![](http://datasheet.mmic.net.cn/370000/ST20-SWC-PC_datasheet_16733502/ST20-SWC-PC_5.png)
ST20–SWC
5/21
2.2
ANSI C compilation system
2.2.1
The compiler operates from a host command line interface. The preprocessor is integrated into the
compiler for fast execution. The compile time diagnostics provided by the compiler are comprehen-
sive and include type checking in expressions and type checking of function arguments.
Compiler operation
2.2.2
The ST20 ANSI C Toolset supports the full standard language as defined in X3.159-1989. The
compiler passes all the tests in the validation suites from Plum Hall and Perennial.
ANSI conformance
2.2.3
The compiler implements a wide range of local code optimization techniques.
Constant folding.
The compiler evaluates all integer and real constant expressions at compile
time.
Workspace allocation.
Frequently used variables are placed at small offsets in workspace, thus
reducing the size of the instructions needed to access them, and hence increasing the speed
of execution.
Dead-code elimination.
Code that cannot be reached during the execution of the program is
removed.
Peephole optimization.
Code sequences are selected that are the fastest for the operation.
Constant caching.
Some constants have their load time reduced by placing them in a constant
table.
Unnecessary jumps
are eliminated.
Switch statements
can generate a number of different code sequences to cover the dense
ranges within the total range.
Special idioms
that are better on ST20s are chosen for some code sequences.
Local optimized code generation
2.2.4
The ANSI C globally optimizing compiler extends the types of optimizations it performs to global
techniques. These have typically given a 15–25 percent improvement in speed over the local opti-
mizations as measured by a suite of internal benchmarks.
Common sub-expression elimination
removes the evaluation of an expression where it is
known that the value has already been computed; the value is stored in temporary local work-
space. This improves the speed of a program and reduces code size.
Loop-invariant code motion
can move the position where an expression is evaluated from within
a loop to outside it. If the expression contains no variables that are changed during the execution
of a loop, then the expression can be evaluated just once before the loop is entered. By keeping
the result in a temporary, the speed of execution of the whole loop is increased.
Tail-call optimization
reduces the number of calls and returns executed by a program. If the last
thing a function does is to invoke another function and immediately return the value there from,
then the compiler attempts to re-use the same workspace area by just jumping to (rather than
calling) the lower level function. The called function then returns directly to where the upper level
function was called from. In the case where the call is a recursive call to the same function, then
the workspace is exactly the right size, and a saving is also made because the stack adjustment
instructions are no longer needed either. This optimization saves speed and total stack space.
Globally optimized code generation