HP C Programmer's Guide (92434-90009)
Chapter 4 91
Optimizing HP C Programs
Level 2 Optimization Modules
f(int x)
{
int a,b,c:
a=1;
b=2;
c=x*b;
return c;
}
becomes:
f(int x)
{
int a,b,c;
b=2;
c=x*b;
return c;
}
Software Pipelining
Software pipelining is a code transformation that optimizes program loops. It rearranges
the order in which instructions are executed in a loop. It generates code that overlaps
operations from different loop iterations. Software pipelining is useful for loops that
contain arithmetic operations on floats and doubles.
The goal of this optimization is to avoid CPU stalls due to memory or hardware pipeline
latencies. The software pipelining transformation adds code before and after the loop to
achieve a high degree of optimization within the loop.
Example
The following pseudo-code fragment shows a loop before and after the software pipelining
optimization. Four significant things happen:
• A portion of the first iteration of the loop is performed before the loop.
• A portion of the last iteration of the loop is performed after the loop.
• The loop is unrolled twice.
• Operations from different loop iterations are interleaved with each other.
The following is a C for loop:
#define SIZ 10000
float x[SIZ], y[SIZ]; \*Software pipelining works with*\
int i; \*floats and doubles. *\
init();
for (i = 0;i<= SIZ;i++);
{
x[i] =x[i] / y[i] + 4.00
}
When this loop is compiled with software pipelining, the optimization can be expressed in