5-30
SC100 C Compiler
Optimization Techniques and Hints
5.3.4.2 Prefix grouping
Instruction grouping is applied by the optimizer wherever possible, in order to make best use of the
available multiple execution units. In addition to "natural" grouping of instructions, which increases
efficiency and does not increase code size, the optimizer can implement prefix grouping. Prefix grouping is
a mechanism whereby an additional word is introduced into the code in order to force more than one
instruction to execute in the same cycle.
Prefix grouping improves performance in terms of speed, but increases the size of the code. According to
the optimization option selected, the optimizer activates prefix grouping as follows:
Option
-Ot2
: on the entire code
Option
-Ot1
: on all loops
Options
-Ot
and
-O2
: on small loops only (the default)
5.3.5 Space Optimizations
When you select the
-Os
option, the optimizer aims to produce code that occupies as little memory space
as possible. In certain cases, this may be at the expense of program speed, resulting in a program that is
small, but which executes relatively slower than a program optimized with the default option
-O2
.
The compiler executes both high-level and low-level optimization phases when compiling with the
-Os
option. In order to minimize the size of the code, the optimizer does not apply the high-level
optimization, function inlining, since this always increases code size.
All the low-level optimizations are applied, except for conditional execution, which is not used if the basic
block involved contains more than five instructions.
In this mode, the optimizer uses only serial grouping when encoding assembly instructions, since code size
is increased when prefixes are added, as described in
Section 5.3.4.2,
“
Prefix grouping.
”
The optimizer
applies conditional execution and predication to small structures only, because this optimization adds to
the size of the code. See
Section 5.3.3.3,
“
Conditional execution and predication,
”
for further details.
5.3.6 Global Optimizations
Global optimization mode produces the most effective form of optimization, since optimizations are
applied across all the files in the application. The option
-Og
can be specified in the command line together
with any of the optimization options except the
-O0
option, and is most effective when used with the
default level
-O2
.
In addition to implementing the selected level of optimization across all the files, global optimization also
applies two specific optimizations:
Function inlining across multiple files, which applies the optimization described in
Section 5.3.2.2,
“
Function inlining,
”
to the whole program. As with function inlining for individual files, this
increases the size of the code, but can considerably increase execution speed.
Optimization of access to global and static variables.