Refining C/C++ Code
3-35
Optimizing C/C++ Code
You need some way to convey to the compiler that this loop will also execute
an even number of times. The MUST_ITERATE pragma conveys loop count
information to the compiler. For example, #pragma MUST_ITERATE (40, 40),
tells the compiler the loop immediately following this pragma will execute a
minimum of 40 times (the first argument), and a maximum of 40 times (the sec-
ond argument). An optional third argument tells the compiler what the trip
count is a multiple of. See the
TMS320C6000 C/C++ Compiler User’s Guide
for more information about the MUST_ITERATE pragma.
Example 3–19 and Example 3–20 show how to use the _nassert() intrinsic
and MUST_ITERATE pragma to get word accesses on the vector sum and the
FIR filter.
Example 3–19. Using the _nassert() Intrinsic to Generate Word Accesses for Vector Sum
void vecsum(short *restrict sum, const short *restrict in1,
const short *restrict in2, unsigned int N)
{
int i;
_nassert(((int)sum & 0x3) == 0);
_nassert(((int)in1 & 0x3) == 0);
_nassert(((int)in2 & 0x3) == 0);
#pragma MUST_ITERATE (40, 40);
for (i = 0; i < N; i++)
sum[i] = in1[i] + in2[i];
}