General Guidelines
Avoiding Emulated Arithmetic
Arithmetic operations for some types are implemented by library func-
tions because the DSP hardware does not directly support these types.
Consequently, operations for these types are far slower than native opera-
tions-sometimes by a factor of a hundred-and also produce larger code.
These types are marked as "Emulated Arithmetic" in
page
2-7.
The hardware does not provide direct support for division, so division and
modulus operations are almost always multi-cycle operations, even on
integral type inputs. If the compiler has to issue a full division operation,
it will usually need to generate a call to a library function. One notable sit-
uation in which a library call is avoided is for integer division when the
divisor is a compile-time constant and is a power of two. In that case the
compiler generates a shift instruction. Even then, a few fix-up instructions
are needed after the shift if the types are signed. If you have a signed divi-
sion by a power of two, consider whether you can change it to unsigned in
order to obtain a single-instruction operation.
When the compiler has to generate a call to a library function for one of
these arithmetic operators that are not supported by the hardware, perfor-
mance will suffer not only because the operation will take multiple cycles,
but also because the effectiveness of the compiler optimizer will be
reduced.
For example, such an operation in a loop can prevent the compiler from
making use of efficient zero-overhead hardware loop instructions. Also,
calling the library to perform the required operation can change values
held in scratch registers before the call, so the compiler will have to gener-
ate more stores and loads from the data stack to keep values required after
the call returns. Emulated arithmetic operators should therefore be
avoided where possible, especially in loops.
2-8
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
"Data Types" on
for ADSP-219x DSPs
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers