SPRUIG8J January 2018 – March 2024
A loop iterates some number of times before the loop terminates. The number of iterations is called the iteration count. The variable that counts iterations is the iteration counter. When the iteration counter reaches a limit equal to the iteration count, the loop terminates. The Code Generation Tools use the iteration count to determine whether or not a loop can be pipelined. The structure of a software pipelined loop requires the execution of a minimum number of loop iterations (a minimum iteration count) in order to fill or prime the pipeline.
The minimum iteration count for a software pipelined loop is set by the number of iterations executing in parallel. In Figure 4-1, the minimum iteration count is five. In the following example A, B, and C are instructions in a software pipeline, so the minimum iteration count for this single-cycle software pipelined loop is three.
A | ||||
B | A | |||
C | B | A | ←Three iterations in parallel = minimum iteration count | |
C | B | |||
C |
When the Code Generation Tools cannot determine the iteration count for a loop, then by default two loops and control logic are generated. The first loop is not pipelined, and it executes if the run-time iteration count is less than the loop's minimum safe iteration count. The second loop is the software pipelined loop, and it executes when the run-time iteration count is greater than or equal to the minimum iteration count. At any given time, one of the loops is a redundant loop. For example:
foo(N) /* N is the iteration count */
{
for (I=0; I < N; I++) /* I is the iteration counter */
}
After finding a software pipeline for the loop, the compiler transforms foo() as below, assuming the minimum iteration count for the loop is 3. Two versions of the loop would be generated and the following comparison would be used to determine which version should be executed:
foo(N)
{
if (N < 3)
{
for (I=0; I < N; I++) /* Unpipelined version */
}
else
}
for (I=0; I < N; I++) /* Pipelined version */
}
}
foo(50); /* Execute software pipelined loop */
foo(2); /* Execute loop (unpipelined)*/
You may be able to help the compiler avoid producing redundant loops with the use of --program_level_compile --opt_level=3 (see Section 4.4) or the use of the MUST_ITERATE pragma (see Section 5.8.23).