Interruptible Code Generation
7-8
7.4.4
Getting the Most Performance Out of Interruptible Code
As stated in Chapter 4 and Chapter 7, the .trip directive and the MUST_ITER-
ATE pragma can be used to specify a maximum value for the trip count of a
loop. This information can help to prevent performance loss when your loops
need to be interruptible as in Example 7–3.
For example, if your application has an interrupt threshold of 100 cycles, you
will use the -mi100 option when compiling your application. Assume that there
is a dot product routine in your application as follows:
Example 7–3. Dot Product With MUST_ITERATE Pragma Guaranteeing Minimum Trip
Count
int dot_prod(short *a, short *b, int n)
{
int i, sum = 0;
#pragma MUST_ITERATE (20);
for (i = 0; i < n; i++)
sum += a[i] * b[i];
return sum;
}
With the MUST_ITERATE pragma, the compiler only knows that this loop will
execute at least 20 times. Even with the interrupt threshold set at 100 by the
-mi option, the compiler will still produce a 6-cycle loop for this code (with only
one result computed during those six cycles) because the compiler has to ex-
pect that a value of greater than 100 may be passed into n.
After looking at the application, you discover that n will never be passed a value
greater than 50 in the dot product routine. Example 7–4 adds this information
to the MUST_ITERATE pragma as follows: