Achieving Optimal Performance from C/C++ Source Code
Loop Guidelines
Loops are where an application will ordinarily spend the majority of its
time. It is therefore useful to look in detail at how to help the compiler to
produce the most efficient code possible for them.
Keeping Loops Short
For best code efficiency, loops should be as small as possible. Large loop
bodies are usually more complex and difficult to optimize. Additionally,
they may require register data to be stored in memory. This will cause a
decrease in code density and execution performance.
Avoiding Unrolling Loops
Tip: Do not unroll loops yourself.
Not only does loop unrolling make the program harder to read but it also
prevents optimization by complicating the code for the compiler.
void va1(const short a[], const short b[], short c[], int n)
{
int i;
for (i = 0; i < n; ++i) {
c[i] = b[i] + a[i];
}
}
Good: the compiler will unroll if it helps.
void va2(const short a[], const short b[], short c[], int n)
{
short xa, xb, xc, ya, yb, yc;
int i;
for (i = 0; i < n; i+=2) {
xb = b[i]; yb = b[i+1];
xa = a[i]; ya = a[i+1];
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
2-17
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers