Lesson 2: Balancing Resources With Dual-Data Paths
2-15
Compiler Optimization Tutorial
Open lesson2_c.c
Example 2–8. lesson2_c.c
void lesson2_c(short * restrict xptr, short * restrict yptr, short *zptr,
short *w_sum, int N)
{
int i, w_vec1, w_vec2;
short w1,w2;
w1 = zptr[0];
w2 = zptr[1];
#pragma MUST_ITERATE(20, , 2);
for (i = 0; i < N; i++)
{
w_vec1 = xptr[i] * w1;
w_vec2 = yptr[i] * w2;
w_sum[i] = (w_vec2) >> 15;
}
}
In lesson2_c.c, no code is altered, only additional information is passed via the
MUST_ITERATE pragma. We simply guarantee to the compiler that the trip
count (in this case the trip count is N) is a multiple of two and that the trip count
is greater than or equal to 20. The first argument for MUST_ITERATE is the
minimum number of times the loop will iterate. The second argument is the
maximum number of times the loop will iterate. The trip count must be evenly
divisible by the third argument. See the
TMS320C6000 Optimizing C/C++
Compiler User’s Guide for more information about the MUST_ITERATE prag-
ma.
For this example, we chose a trip count large enough to tell the compiler that
it is more efficient to unroll. Always specify the largest minimum trip count that
is safe.
Open lesson2_c.asm and examine the feedback