Achieving Optimal Performance from C/C++ Source Code
Avoiding Placing Function Calls in Loops
The compiler will not usually be able to generate a hardware loop if the
loop contains a function call due to the expense of saving and restoring the
context of a hardware loop. In addition to obvious function calls, such as
, hardware loop generation can also be prevented by operations
printf()
such as division, modulus, and some type coercions. These operations may
require implicit calls to library functions. For more details, see
Types" on page
Avoiding Non-Unit Strides
If you write a loop such as:
for (i=0; i<n; i+=3) {
// some code
}
Bad: non-unit stride means division may be required.
then in order for the compiler to turn this into a hardware loop, it will
need to work out the loop trip count. To do so, it must divide
compiler will decide that this is worthwhile as it will speed up the loop,
but as discussed above, division is an expensive operation. Try to avoid
creating loop control variables with strides of non-unit magnitude.
Loop Control
Tip: Use
Tip: Use automatic variables for loop control and loop exit test.
For loop control variables and array indices, it is always better to use
signed
rather than any other integral type. The C standard requires
ints
various type promotions and standard conversions that complicate the
code for the compiler optimizer. Frequently, the compiler is still able to
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
2-7.
types for loop control variables and array indices.
int
"Data
by 3. The
n
2-21
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers