Achieving Optimal Performance from C/C++ Source Code
return sum;
}
Bad: rotated by hand—hard for the compiler to optimize.
By rotating the loop, the scalar variables
ducing loop-carried dependencies.
Avoiding Array Writes in Loops
Other dependencies can be caused by writes to array elements. In the fol-
lowing loop, the optimizer cannot determine whether the load from a
reads a value defined on a previous iteration or one that will be overwrit-
ten in a subsequent iteration.
for (i = 0; i < n; ++i)
a[i] = b[i] * a[c[i]];
Bad: has array dependency.
The optimizer can resolve access patterns where the addresses are expres-
sions that vary by a fixed amount on each iteration. These are known as
"induction variables".
for (i = 0; i < n; ++i)
a[i+4] = b[i] * a[i];
Good: uses induction variables.
Inner Loops vs. Outer Loops
Tip: Inner loops should iterate more than outer loops.
The optimizer focuses on improving the performance of inner loops
because this is where most programs spend the majority of their time. It is
considered a good trade-off for an optimization to slow down the code
before and after a loop if it is going to make the loop body run faster.
Therefore, try to make sure that your algorithm also spends most of its
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
and
have been added, intro-
ta
tb
2-19
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers