9/11/95
Page 13
OPTIMIZING THE APPLICATION PROGRAM
Do not try to optimize an application program when it is in the debugging process, because
optimization may move instructions around, and thus make it harder to debug. When the program is
fully functional, optimization may be applied to improve the speed of the program and reduce the size
of the code; these are two important factors in designing an embedded application. Certain
optimization options are turned on by default (/Oc, /Of, /Oo, /Ot, /Ov). This section attempts to
explain briefly other optimizations users might want to try to produce faster and smaller code. Please
review the Microsoft C/C++ Environment and Tools manual for a complete listing.
/G1
Processor specific
instructions
Use this option to produce 80186 instructions
/Gr
Register calling
convention
This option instructs the compiler to pass arguments between functions using
registers as much as possible. Thus it increases the speed. WARNING:
Using this option with inline assembly language may cause conflicts in the
use of registers.
/Gs
Turn stack checking OFF
Use this option to eliminate the stack-probe routine being called at every
function entry point, thus it enables the compiler to produce faster code.
/Gy
eliminate dead-code at
link time
This option eliminates unintended functions at link time, thus it enables the
linker to produce smaller code.
/Ob[0,1,2]
Control inline expansion
Inline expansion produces faster code because the overhead associated with
function calls is eliminated, but it will increase the size of the code.
/Ob0: Disable inline expansion (default with /Od)
/Ob1: Only expand functions marked as inline or __inline
/Ob2: Expand functions marked as inline or __inline and any
other functions the compiler chooses
/Oe
global register allocation
This option allows the compiler to store frequently used variables and
expressions in registers, thus increases the speed and decreases the size of
the code. This option should always be turned ON.
/Og
Global-level common
subexpression
optimization
When the same expression is repeated within a function, and the value has
not changed, the compiler calculates the expression and stores it in a
temporarily variable. Thus this option decreases the size, and increases the
speed. This option should always be turned ON.
/Oi
Generate intrinsic
functions
This option instructs the compiler to replace the common string or memory
functions such as memcpy, strcpy, etc. with their inline code. As with inline
option /Obn, intrinsic functions are faster, but they may be larger due to
additional code generated.
/Ol
Enable loop optimization
This option removes invariant code within a loop. Any expression whose
value is constant inside the loop will be moved outside when this option is
turned ON. Thus it increases the speed of the program execution.
/Os
Minimize executable file
size
This option minimizes the size of the object file. Though it produces smaller
code, it may also slow the code.
/Ox
Maximize optimization
This option is a short way to combine optimizing options to produce the
fastest possible code. It is the combination of the following options:
/Oblcegilnot /Gs.
/Oz
Turn on potential unsafe
loop optimization
This option works like /Ol, only it is much more aggressive. WARNING:
Use of this option may generate unwanted “features”.
BUILDING AN AM186EM STANDALONE PROGRAM