Refining C/C++ Code
3-43
Optimizing C/C++ Code
3.4.3.3
Communicating Trip-Count Information to the Compiler
When invoking the compiler, use the following options to communicate trip-
count information to the compiler:
-
Use the –o3 and –pm compiler options to allow the optimizer to access the
whole program or large parts of it and to characterize the behavior of loop
trip counts.
-
Use the MUST_ITERATE pragma to help reduce code size by preventing
the generation of a redundant loop or by allowing the compiler (with or
without the –ms option) to software pipeline innermost loops.
You can use the MUST_ITERATE and PROB_ITERATE pragma to convey
many different types of information about the trip count to the compiler.
-
The MUST_ITERATE pragma can convey that the trip count will always
equal some value.
/* This loop will always execute exactly 30 times */
#pragma MUST_ITERATE (30, 30);
for (j = 0; j < x; j++)
-
The MUST_ITERATE pragma can convey that the trip count will be great-
er than some minimum value or smaller than some maximum value. The
latter is useful when interrupts need to occur inside of loops and you are
using the -mi<n> option. Refer to section 7.4,
Interruptible Loops.
/* This loop will always execute at least 30 times */
#pragma MUST_ITERATE (30);
for (j = 0; j < x; j++)
-
The MUST_ITERATE pragma can convey that the trip count is always di-
visible by a value.
/* The trip count will execute some multiple of 4 times */
#pragma MUST_ITERATE (,, 4);
for (j = 0; j < x; j++)
This information call all be combined as well into a single C statement:
#pragma MUST_ITERATE (8, 48, 8);
for (j = 0; j < x; j++)
The compiler knows that this loop will execute some multiple of 8 (between 8
and 48) times. This information is useful in providing more information about
unrolling a loop or the ability to perform word accesses on a loop.