SPRUI30H November 2015 – May 2024 DRA745 , DRA746 , DRA750 , DRA756
The loop setup process for each level of nesting consists of the following (in the specified order):
A loop becomes active as soon as a value greater than 1 is programmed in LCNTn. The LSAn and LEAn registers are written when the corresponding MVC/SLA instruction is executed but the values are not used by the processor (for detecting loop rewind condition) until the corresponding loop becomes active.
When a loop becomes active (LCNTn > 1), the PC of the instruction at DEC phase is checked with the LEAn register. If they match, the CPU takes a zero-cycle overhead branch to the top of the loop provided by the LSAn registers. The program fetch request to LSAn is placed when the last instruction of a loop is at DEC. Thus there is no delay slot for the loop rewind branch, neither any stall or null cycle.
For LCNTn = x, the loop rewinds x - 1 times, effectively the loop body executes total x times (x - 1 rewinds and the last fall through pass). For LCNTn = 1, the loop body executes once (zero rewind). For LCNTn = 0, the loop is not considered active – the CPU just linearly executes – however, as a result, the loop body executes once (linear fall through). Note that LCNTn = 0 does not mean loop body would not be executed.
During operation, the LCNTn registers are directly updated (decremented) with the remaining iteration count. The loop counters are updated along with the corresponding rewind-branch. At any time LCNTn is read to determine how many iterations of the corresponding loop are still to be executed. When each level completes, the corresponding LCNTn registers become zero, the LSAn/LEAn registers are left unchanged. Note that for LCNTn = 1, the loop body executes once and the loop counter is decremented when the last instruction of the corresponding loop is executed.
The LCNT0RLD register is updated automatically by the CPU whenever a value is written to LCNT0 (for example, during loop setup). For a two-level nested loop, once the inner most level iteration completes and the CPU rewinds to the top of the outer loop, the LCNT0 is reloaded with the content of LCNT0RLD. Note that even if LCNT0RLD is a programmer visible control register, it acts as a shadow register of LCNT0 (updated on any write to LCNT0) and must not be explicitly written during a loop setup.
There are no restrictions in embedding an HLA construct or instruction sequence, consisting of one or two levels of nested loops, into a larger level of nested loop implemented by normal software techniques.