world leader in high performance signal processing
Trace: » lsetup

LSETUP, LOOP

General Form

There are two forms of this instruction. The first is:

LOOP loop_name loop_counter
LOOP_BEGIN loop_name
LOOP_END loop_name

The second form is:

LSETUP (Begin_Loop, End_Loop)Loop_Counter

Syntax

Use any one of the LOOP syntax versions with a LOOP_BEGIN and a LOOP_END instruction. The name of the loop (loop_name in the syntax) relates the three instructions together.

For Loop0:

LOOP loop_name LC0 ;                                /* (b) */
LOOP loop_name LC0 = Preg ;                         /* autoinitialize LC0 (b) */
LOOP loop_name LC0 = Preg >> 1 ;                    /* autoinit LC0(b) */
LOOP_BEGIN loop_name ;                              /* define the 1st instruction of loop (b)*/
LOOP_END loop_name ;                                /* define the last instruction of the loop (b) */
                                                
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 ;             /* (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 = Preg ;      /* autoinitialize LC0 (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 = Preg >> 1 ; /* autoinitialize LC0 (b) */

For Loop1:

LOOP loop_name LC1 ;                                /* (b) */
LOOP loop_name LC1 = Preg ;                         /* autoinitialize LC1 (b) */
LOOP loop_name LC1 = Preg >> 1 ;                    /* autoinitialize LC1 (b) */
LOOP_BEGIN loop_name ;                              /* define the first instruction of the loop (b) */
LOOP_END loop_name ;                                /* define the last instruction of the loop (b) */

LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 ;             /* (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 = Preg ;      /* autoinitialize LC1 (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 = Preg >> 1 ; /* autoinitialize LC1 (b) */

Syntax Terminology

Preg
P5–0 (SP and FP are not allowed as the source register for this instruction.)
pcrel5m2
5-bit unsigned, even, PC-relative offset; can be replaced by a symbolic label. The range is 4 to 30, or 25–2.
lppcrel11m2
11-bit unsigned, even, PC-relative offset for a loop; can be replaced by a symbolic label. The range is 4 to 2046 (0x0004 to 0x07FE), or 211–2.
loop_name
a symbolic identifier

Instruction Length

In the syntax, comment (b) identifies 32-bit instruction length.

Functional Description

The Zero-Overhead Loop Setup instruction provides a flexible, counter-based, hardware loop mechanism that provides efficient, zero-overhead software loops. In this context, zero-overhead means that the software in the loops does not incur a performance or code size penalty by decrementing a counter, evaluating a loop condition, then calculating and branching to a new target address.

When the Begin_Loop address is the next sequential address after the LSETUP instruction, the loop has zero overhead. If the Begin_Loop address is not the next sequential address after the LSETUP instruction, there is some overhead that is incurred on loop entry only.

The architecture includes two sets of three registers each to support two independent, nestable loops. The registers are Loop_Top (LTn), Loop_Bottom (LBn) and Loop_Count (LCn). Consequently, LT0, LB0, and LC0 describe Loop0, and LT1, LB1, and LC1 describe Loop1.

The LOOP and LSETUP instructions are a convenient way to initialize all three registers in a single instruction. The size of the LOOP and LSETUP instructions only supports a finite number of bits, so the loop range is limited. However, LT0 and LT1, LB0 and LB1 and LC0 and LC1 can be initialized manually using Move instructions if loop length and repetition count need to be beyond the limits supported by the LOOP and LSETUP syntax. Thus, a single loop can span the entire 4 GB of memory space.

When initializing LT0 and LT1, LB0 and LB1, and LC0 and LC1 manually, make sure that Loop_Top (LTn) and Loop_Bottom (LBn) are configured before setting Loop_Count (LCn) to the desired loop count value.

The instruction syntax supports an optional initialization value from a P-register or P-register divided by 2.

The LOOP, LOOP_BEGIN, LOOP_END syntax is generally more readable and user friendly. The LSETUP syntax contains the same information, but in a more compact form.

If LCn is nonzero when the fetch address equals LBn, the processor decrements LCn and places the address in LTn into the PC. The loop always executes once through because Loop_Count is evaluated at the end of the loop.

There are two special cases for small loop count values. A value of 0 in Loop_Count causes the hardware loop mechanism to neither decrement or loopback, causing the instructions enclosed by the loop pointers to be executed as straight-line code. A value of 1 in Loop_Count causes the hardware loop mechanism to decrement only (not loopback), also causing the instructions enclosed by the loop pointers to be executed as straight-line code.

In the instruction syntax, the designation of the loop counter–LC0 or LC1– determines which loop level is initialized. Consequently, to initialize Loop0, code LC0; to initialize Loop1, code LC1.

In the case of nested loops that end on the same instruction, the processor requires Loop0 to describe the outer loop and Loop1 to describe the inner loop. The user is responsible for meeting this requirement. For example, if LB0=LB1, then the processor assumes loop 1 is the inner loop and loop 0 the outer loop.

Just like entries in any other register, loop register entries can be saved and restored. If nesting beyond two loop levels is required, the user can explicitly save the outermost loop register values, re-use the registers for an inner loop, and then restore the outermost loop values before terminating the inner loop. In such a case, remember that loop 0 must always be outside of loop 1. Alternately, the user can implement the outermost loop in software with the Conditional Jump structure.

Begin_Loop, the value loaded into LTn, is a 5-bit, PC-relative, even offset from the current instruction to the first instruction in the loop. The user is required to preserve half-word alignment by maintaining even values in this register. The offset is interpreted as a one’s-complement, unsigned number, eliminating backwards loops. End_Loop, the value loaded into LBn, is an 11-bit, unsigned, even, PC-relative offset from the current instruction to the last instruction of the loop. When using the LSETUP instruction, Begin_Loop and End_Loop are typically address labels. The linker replaces the labels with offset values. A loop counter register (LC0 or LC1) counts the trips through the loop. The register contains a 32-bit unsigned value, supporting as many as 4,294,967,294 trips through the loop. The loop is disabled (subsequent executions of the loop code pass through without reiterating) when the loop counter equals 0.

ADSP-BF535 Execution: The following information about instructions that are permissible as the last instruction on a loop applies only to the ADSP-BF535 processor, not to all ADSP-BF53x/BF56x processors.

The last instruction of the loop must not be any of the following instructions.

  • Jump
  • Conditional Branch
  • Call
  • CSYNC
  • SSYNC
  • Return (RTS, RTN, etc.)

As long as the hardware loop is active (Loop_Count is nonzero), any of these forbidden instructions at the End_Loop address produces undefined execution, and no exception is generated. Forbidden End_Loop instructions that appear anywhere else in the defined loop execute normally. Branch instructions that are located anywhere else in the defined loop execute normally.

Also, the last instruction in the loop must not modify the registers that define the currently active loop (LCn, LTn, or LBn). User modifications to those registers while the hardware accesses them produces undefined execution. Software can legally modify the loop counter at any other location in the loop.

Flags Affected

None

Required Mode

User & Supervisor

Parallel Issue

This instruction cannot be issued in parallel with other instructions.

Example

lsetup ( 4, 4 ) lc0 ;
lsetup ( poll_bit, end_poll_bit ) lc0 ;
lsetup ( 4, 6 ) lc1 ;
lsetup ( FIR_filter, bottom_of_FIR_filter ) lc1 ;
lsetup ( 4, 8 ) lc0 = p1 ;
lsetup ( 4, 8 ) lc0 = p1>>1 ;
loop DoItSome LC0 ;   /* define loop ‘DoItSome’ with Loop Counter 0 */
loop_begin DoItSome ; /* place before the first instruction in the loop */
loop_end DoItSome ;   /* place after the last instruction in the loop */
loop MyLoop LC1 ;     /* define loop ‘MyLoop’ with Loop Counter 1 */
loop_begin MyLoop ;   /* place before the first instruction in the loop */
loop_end MyLoop ;     /* place after the last instruction in the loop */

Also See

Special Applications

None