Chapter 5 Generated Code Architecture
AutoCode Reference 5-32 ni.com
FOR Loop—Can generate either a rolled or unrolled loop depending
upon the range of the loop subscript and whether or not scalar code is
generated.
Examples of Rolled and Unrolled Loops
Example 5-12 Unrolled Loop from Example5-9
/***** Output Update. *****/
/* ---------------------------- BlockScript Block */
/* {bsb..2} */
bsb_1 = indata_1 * 2;
bsb_2 = indata_2 * 4;
bsb_3 = indata_3 * 6;
bsb_4 = indata_4 * 8;
bsb_5 = indata_5 * 10;
Example 5-13 Rolled Loop from Example5-10, Using Vectorized Code
/***** Output Update. *****/
/* ---------------------------- BlockScript Block */
/* {bsb..4} */
for(j=1; j <= indata[0]; j++) {
bsb[-1+j] = indata[-1+j] + j;
Table 5-4. Scalar Code Semantics for the Loop Types
Loop Type Soft-Subscript Rolled Loop
WHILE Not for inputs,
outputs, or
states
Always
FOR Not for inputs,
outputs, or
states
No, unless the bounds of the loop are
known and only local variables are
used in the loop body
Table 5-5. Vectorized Code Semantics for the Loop Types
Loop Type Soft-Subscript Rolled Loop
WHILE Not for inputs,
outputs, or states
Always
FOR Yes Yes