$OPTIMIZE | $O - Define optimization modes

$OPTIMIZE | $O - Define optimization modes

Language reference ›› Directives ››
Parent Previous Next

optimize-directive = ( $OPTIMIZE | $O ) optimize-item { "," optimize-item } .
optimize-item = optimize-generation-mode | optimize-ram-mode | optimize-params-mode | optimize-calls-mode | optimize-enums-mode | optimize-eewrite-mode .
optimize-generation-mode = speed-mode | memory-mode | off-mode .
speed-mode = SPEED | "S" .
memory-mode = MEMORY | "M" .
off-mode = directive-switch-off .
optimize-params-mode = PARAMS directive-toggle .
optimize-ram-mode = RAM directive-toggle .
optimize-calls-mode = CALLS directive-toggle .
optimize-enums-mode = CALLS directive-toggle .
optimize-eewrite-mode = EEWRITE directive-toggle .


Define one or several compiler's optimizer behaviors.


This directive overrides the default options defined in the Project's Options.


NEW! (V2.1): All optimization setups have been grouped in this directive, and several items may be separated by commas. $OPTIMIZE_RAM and $OPTIMIZE_PARAMS are now obsolete but kept for compatibility.


speed-mode:


Optimize for speed; some internal function calls are replaced by inline code (call instructions to these functions are suppressed: less use of processor hardware stack) and code optimization is more accurate.

It invalidates the memory optimization.

{$OPTIMIZE SPEED}


memory-mode:


Optimize for memory size and calls (default); internal functions are mostly implemented as subroutines; processor hardware stack is used for calls. It invalidates the speed optimization.

{$OPTIMIZE MEMORY}


off-mode:


Disables the optimization for speed or memory size or some code tuning techniques (not recommended; should be used only to workaround optimization bugs). Does not affect the other optimizations below.

{$OPTIMIZE OFF}


optimize-params-mode:


Define procedure and function parameters passing mode.

By default parameters passing may be optimized (passed in registers).

In some cases it may be necessary to turn off this optimization, for pure assembler routines or procedures assigned to output channel.

Defaults to ON.

{$OPTIMIZE PARAMS OFF}


optimize-ram-mode:


Define RAM memory optimization behavior.

By default the RAM allocation for variables is managed so that some variables may occupy the same RAM location, if there's no conflict, e.g.: parameters and local variables in procedures and functions.

In case of trouble it may be necessary to turn off this optimization.

Defaults to ON.

{$OPTIMIZE RAM OFF}


optimize-calls-mode:


Define behavior when the construct "CALL XXX" followed by "RETURN" pair is encountered, if ON the pair is replaced by a direct "GOTO XXX", so that less HW stack is used.

As this optimization may be inconvenient during step by step debugging, it may be disabled.

Defaults to ON.

{$OPTIMIZE CALLS OFF}


optimize-enums-mode:


Define variable / constant ENUMERATED allocation and code generation behavior, when this enumeration is only of two possible values which ordinal positions are 0 and 1, the compiler will use a single bit instead of a BYTE, so that the related code may be optimized.

Defaults to ON.


{$OPTIMIZE ENUMS OFF}
TYPE
  tLedState = (lsON, lsOFF);
VAR
  LED: tLedState @ PORTA.0; // LED output with anode to Vdd
...
 LED := lsON;  // more readable than a boolean output that would need to be assigned with false to light the LED


optimize-eewrite-mode:


Define EE memory write mode. If ON, any EE write is preceded by a read and if the value is already set, the write is skipped. This behaviour optimizes overall execution time and EE memory lifetime. Also if ON, no user program mechanism is needed to write back a variable to EE memory only if it has changed.

Defaults to ON.

{$OPTIMIZE EEWRITE ON}