Abstract:
There is disclosed a loop counter reload circuit loads an initial count value into a counter and a shadow register. A count value output from the counter is changed by a predetermined displacement resulting in a changed count value. The count value from the shadow register is loaded into the counter if the changed count value has reached a predetermined reference value, and otherwise the changed count value is loaded into the counter.

Description:
Priority from U.S. Provisional Application Ser. No: 60/067467, filed Dec. 4, 1997 is hereby claimed. 
    
    
     TECHNICAL FIELD 
     This application relates to loop counters for microprocessors and digital signal processors, and in particular to specialized circuitry and method for reloading loop counters. 
     BACKGROUND OF THE INVENTION 
     Many applications performed on microprocessors or digital signal processors require repeating computational steps for a predetermined number of repetitions, or until a predetermined condition is met. Repeating a step or sequence of steps is referred to as a loop. The number of time a loop is executed is tracked by a loop counter that counts the number of time the computation in the loop has been performed. 
     When loops are nested, the inner loop in the case of two nested loops, or the inner loops in the case of more than two nested loops, is/are repeated until the outermost loop has executed a predetermined number of times. Each time an inner loop counts through its associated predetermined number of count times, an outer loop counter is updated, such as being decremented, the inner loop counter is reset to a predetermined value, and the inner loop repeatedly executed the number of times of the predetermined value. 
     Software techniques have typically been used to reload loop counters in microprocessors. While only a few instruction cycles are required for each software counter reload operation, a detrimental impact on the processor performance occurs. Implementation of loop counter reloading in hardware can obviate the detrimental impact on processor performance. 
     SUMMARY OF THE INVENTION 
     In accordance with the present invention, a loop counter reload circuit loads an initial count value into a counter and a shadow register. A count value output from the counter is changed by a predetermined displacement resulting in a changed count value. The count value from the shadow register is loaded into the counter if the changed count value has reached a predetermined reference value, and otherwise the changed count value is loaded into the counter. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a loop counter reset circuit portion of an arithmetic unit, in accordance with illustrative embodiment of the present invention; and 
     FIG. 2 is an integrated circuit employing multiple loop counter reset circuits. 
    
    
     DETAILED DESCRIPTION 
     FIG. 1 illustrates a loop counter circuit 10 as a portion of an arithmetic unit 12 which may be fabricated in an integrated circuit 14. The loop counter reset circuit of the present invention may be used in loop counter control in, for example, microprocessors, microcontrollers, or digital signal processors. 
     Counter 16 is a register that retains the current count value. Counter 16 is configured in FIG. 1 as a count-down counter when the reference value 38 is less than the initial value written into counter 16 and the displacement 40 in conjunction with the arithmetic logic unit (ALU) 42 decreases the current count value output from counter 16. While a count-down counter will be described here, it is understood that with the appropriate setting of reference value 38 being greater than the initial value written into counter 16, and the displacement 40 in conjunction with ALU 42 increasing the current count value output from counter 16 a resettable loop counter 10 configured as an up-counter would result. 
     An initial count value is loaded into counter 16 by way of multiplexer 18 from databus 20. The same count value may be simultaneously loaded into shadow register 22. With the write enable counter shadow register signal, WECS, in a first state such as high, data on bus 20 is written to shadow register 22. When the write enable signal, WEC, is high the data oil bus 20 is written simultaneously to both shadow register 22 and counter 16. Thus, shadow register 22 may be written to independently of writing to counter 16. The write enable of shadow register 22 is enabled when either input to OR gate 26 is high. The write enable of counter 16 is enabled when either input to OR gate 28 is high. 
     The write enable signal, WEC, being high provides a high input to control circuit 30 and OR gate 28 that causes control circuit 30, through select input 32, to provide as the output 34 of multiplexer 18 the data on databus 20. A high input to OR gate 28 also causes output 36 to enable counter 16 such that the output 34 of multiplexer 18 is written to counter 16 overwriting any value then present in counter 16. 
     With loop counter circuit 10 operating as a count-down counter, reference value 38 is typically set to zero and displacement 40 is typically set to minus one, although the invention is not limited thereto. With an initial count value stored in counter 16, at the end of an outer loop, the counter output from counter 16, which is a current counter value, is provided as an input to both ALU 42 and comparator 46. 
     ALU 42 combines, such as by adding, the displacement with input 44 to provide an output that is a changed count value 48. When the displacement is negative, or a positive displacement is subtracted from input 44, the changed count value 48 is the current count value 44 less the magnitude of the displacement. Changed count value is provided as an input to multiplexer 18. An adder may replace ALU 42, as is known in the art, to receive input 44 as well as displacement 40 and produced changed count value 48. 
     Comparator 46 receives the current counter value 44 and reference value 38 as inputs. Comparator 46 compares the current counter value to the reference value and provides an output 50 that takes on a first state, such as a logic zero, when the output current counter value is not the same as the reference value and provides an output that takes on a second state, such as a logic one, when the current counter value 44 and the reference value 38 are the same. When the current counter value 44 and the reference value 38 are the same, the counter has counted down to the reference value and the shadow register count value should be transferred to counter 16. 
     When the current counter value and the reference value are not the same, an inner loop has not been completed. Control circuit 30 through output 32 selects as the output 34 of multiplexer 18 changed count value 48, and output 54 to cause OR gate 28 output 36 to right enable counter 16, thereby overwriting the previous count value with the changed count value. 
     In a count-down configuration, the current counter value repeatedly decrements until the current counter value and the reference values are the same. The condition of the current counter value and the reference values being the same indicates that an inner loop has been completed, and if the outer loop has not been completed as indicated by status signal 52 to control circuit 30, counter 16 should be reset to the count value stored in shadow register 22. Resetting counter 16 to the count value stored in shadow register 22 is achieved by output 50 from comparator 46 taking on a second state, such as a logic one. Control circuit 30 through output 32 selects as the output 34 of multiplexer 18 the count value of shadow register 22 received over bus 56, and output 54 causes OR gate 28 output 36 to right enable counter 16, thereby overwriting the previous or formal count value with the count value of shadow register 22. 
     In accordance with the invention, the reload loop counter circuit provides that a counter be reloaded with the initial count value upon counting to a predetermined reference value, such as zero. In an environment of nested loops, all loops of the outer-most loop could employ the reload loop counter technique. The loop counter reset circuit described above may be used in a manner that does not reset the counter to the initial value by utilizing a disable feature. One such disable feature could be achieved by loading the counter with a count value and subsequently loading the shadow register with a predetermined value, which may be for example either a predetermined numerical value or any negative value. The predetermined value is provided to control circuit 30 overlying 56 and detected by control circuit 30 provides no output to multiplexer 18, thereby maintaining the same counter value in counter 16. 
     While the invention has been described as providing the same count value to the shadow register 22 as to counter 16, the shadow register 22 can be written to independently. With both write enable counter signal, WEC, high and write enable counter shadow signal, WECS, high, the value on databus 20 is written to both counter 16 and shadow register 22. Subsequently, with write enable counter shadow signal WECS high, a different value may be written to shadow register 22. Thus, a second and subsequent setting of counter 16 to a count value can differ from the initial count setting by transferring a count value from shadow register 22 to counter 16 that differs from the initial count value provided to counter 16 from databus 20. 
     Repeatedly changing the value stored in shadow register 22 would provide a different count value for each inner loop execution controlled by circuit 10. However, an advantage of the invention would be overridden. 
     Although a single reloadable loop counter circuit 10 is illustrated in integrated circuit 14 in FIG. 1, circuit 10 may be duplicated for the number of resettable counters required for any application. FIG. 2 illustrates an integrated circuit 14&#39; having an ALU 12&#39; with multiple resettable loop counter circuits 10&#39;.