Refining C/C++ Code
3-40
3.4.3
Software Pipelining
Software pipelining is a technique used to schedule instructions from a loop
so that multiple iterations of the loop execute in parallel. When you use the –o2
and –o3 compiler options, the compiler attempts to software pipeline your
code with information that it gathers from your program.
Figure 3–2 illustrates a software-pipelined loop. The stages of the loop are
represented by A, B, C, D, and E. In this figure, a maximum of five iterations
of the loop can execute at one time. The shaded area represents the loop ker-
nel. In the loop kernel, all five stages execute in parallel. The area immediately
before the kernel is known as the pipelined-loop prolog, and the area immedi-
ately following the kernel is known as the pipelined-loop epilog.
Figure 3–2. Software-Pipelined Loop
A1
B1
A2
C1
B2
A3
Pipelined-loop prolog
D1
C2
B3
A4
E1
D2
C3
B4
A5
Kernel
E2
D3
C4
B5
E3
D4
C5
Pipelined-loop epilog
E4
D5
E5
Because loops present critical performance areas in your code, consider the
following areas to improve the performance of your C code:
-
Trip count
-
Redundant loops
-
Loop unrolling
-
Speculative execution