Achieving Optimal Performance from C/C++ Source Code
Smaller Applications: Optimizing for
Code Size
The same ethos for producing fast code also applies to producing small
code. You should present the algorithm in a way that gives the optimizer
excellent visibility of the operations and data, and hence the greatest free-
dom to safely manipulate the code to produce small applications.
Once the program is presented in this way, the optimization strategy will
depend on the code-size constraint that the program must obey. The first
step should be to optimize the application for full performance, using
or
switches. If this obeys the code-size constraints, then no more
-ipa
need be done.
The "optimize for space" switch
conjunction with IPA, will perform every performance-enhancing trans-
formation except those that increase code-size. In addition, the
switch (
-flags-link -e
helpful
(on page
remove unneeded data and code. If the code produced with
does not meet the code-size constraint, some analysis of the source code
will be required to try to reduce the code-size further.
Note that loop transformations such as unrolling and software pipelining
increase code size. But it is these loop transformations that also give the
greatest performance benefit. Therefore, in many cases compiling for min-
imum code size will produce significantly slower code than optimizing for
speed.
The compiler provides a way to balance between the two extremes of
and
. This is the sliding-scale
-Os
optimization slider bar under Project Options in the VisualDSP++
IDDE), described
where the lower value corresponds to minimum code size and the upper to
maximum performance. A value in between will try to optimize the fre-
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
-Os
if used from the compiler command line) may be
1-27). This performs section elimination in the linker to
-Ov num
on page
1-38. The
(on page
1-37). which may be used in
switch (adjustable using the
is a value between 0 and 100,
num
-O
linker
-e
and
-Os
-e
-O
2-29
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers