Avoiding Conditional Code In Loops - Analog Devices VISUALDSP++ 3.5 Manual

C/c++ compiler and library for adsp-219x processors
Hide thumbs Also See for VISUALDSP++ 3.5:
Table of Contents

Advertisement

Loop Guidelines
time in the inner loop; otherwise it may actually be made to run slower by
optimization. If you have nested loops where the outer loop runs many
times and the inner loop a small number of times, it may be possible to
rewrite the loops so that the outer loop has the fewer iterations.

Avoiding Conditional Code in Loops

If a loop contains conditional code, control-flow latencies may incur large
penalties if the compiler has to generate conditional jumps within the
loop. In some cases, the compiler will be able to convert
constructs into conditional instructions. In other cases, it will be able
?:
to relocate the expression evaluation outside of the loop entirely. How-
ever, for important loops, linear code should be written where possible.
The compiler will not perform the loop transformation that interchanges
conditional code and loop structures. Instead of writing
for (i=0; i<100; i++) {
if (mult_by_b)
sum1 += a[i] * b[i];
else
sum1 += a[i] * c[i];
}
Bad: loop contains conditional code.
it is better to write
if (mult_by_b) {
for (i=0; i<100; i++)
sum1 += a[i] * b[i];
} else {
for (i=0; i<100; i++)
sum1 += a[i] * c[i];
}
Good: two simple loops can be optimized well.
if this is an important loop.
2-20
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
and
IF-THEN-ELSE
for ADSP-219x DSPs

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Related Products for Analog Devices VISUALDSP++ 3.5

Table of Contents