Keil Logo

C251: OPTIMIZE DIRECTIVE


Information in this article applies to:

  • C251 Version 1.24
  • C251 Version 2.14

QUESTION

How do I change optimization levels ?

ANSWER

The OPTIMIZE directive set the optimization level and emphasis.

Abbreviation: OT

Arguments: A decimal number between 0 and 7 enclosed in parentheses. In addition, OPTIMIZE (SIZE) or OPTIMIZE (SPEED) may be used to select whether the optimization emphasis should be placed on code size or on execution speed.

Each higher optimization level contains all of the characteristics of the preceding lower optimization level.

Level O

Constant Folding: The compiler performs calculations that reduce expressions to numeric constants, where possible. This includes calculations of run-time addresses.

Simple Access Optimizing: The compiler optimizes access of internal data and bit addresses in the 251 system.

Jump Optimizing: The compiler always extends jumps to the final target. jumps to jumps are deleted.

Level 1

Dead Code Elimination: Unused code fragments and artifacts are eliminated.

Jump Negation: Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.

Level 2

Data Overlaying: Data and bit segments suitable for static overlay are indentifed and internally marked. The L251 linker/locator has the capability, through global data flow analysis, of selecting the segments which can then be overlaid.

Peephole Optimizing: Redundant MOV instructions are removed. This include unnecessary loading of objects from the memory as well as load operations with constants. Complex operations are replaced by simple operations when memory space or execution time can be saved.

Level 3

Register Variables: Automatic variables and functions are calculated only once when possible. Reservation of data memory for these variables is omitted.

Level 4

Extended Access Optimizing: Variables from the IDATA, XDATA, PDATA, and CODE areas are directly included in operations. The use of intermediate registers is not necessary most of the time.

Local and Global Common Subexpression Elimination: Identical sub expressions within a a function are calculated only one when possible. The intermediate result is stored in a register and used instead of a new calculation.

Case/Switch Optimizing: Code involving switch and case statements is optimized as jump tables or jump strings.

Level 5

Life Variable Analysis: Removes redundant and dead store operations to automatic variables.

Level 6

Constant Propagation: The values of expressions are tracked and when possible constant values are inserted instead of variable accesses.

Peephole Optimizing: Redundant MOV instructions are removed. This includes unnecessary loading of objects from the memory as well as load operations with constants. Complex operations are replaced by simple operations when memory space or execustion time can be saved.

Level 7

Common Tail Merging and Instruction Simplification: The compiler analyzes the generated code function by function and tries to find common heads and tails. If the compiler detects common code sequences, it will replace one code sequence by a jump instruction to the other equivalent code sequence. This situation arises many times with switch/case statements, for example. While analyzing the code, the compiler also tries to replace instruction sequences with cheaper instructions.

Example:

C251 SAMPLE.C OPTIMIZE (size)
C251 SAMPLE.C OPTIMIZE (6, speed)
#pragma ot(4)
#pragma ot(size)

MORE INFORMATION

  • Refer to OPTIMIZE in the Cx51 User's Guide.

Last Reviewed: Monday, July 18, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.