Coding for Performance and Optimization

The MPE/iX Optimizer modi￿es code to use mac hine resources e￿cien tly, using less space and running faster. It impro ves code, but does not alter the algorithm used in code. Coding for good performance requires recognition of the following facts:

Coding practices alter performance.

Mismatches exist between programming languages and most arc hitectures.

Coding techniques can enhance or inhibit optimization opportunities.

Coding for optimization pro vides the follo wing methods of optimizing a program at the source code level:

Reduces or avoids aliasing

Uses optimal data t ypes

Identi￿es common subexpressions

Reduces procedure calls Avoids non-nativ e alignment

Reduce Aliasing

The compiler must generate explicit loads and stores when programs use aliasing with pointers. If you specify that the poin ter does not change (for example, b y using WITH in HP Pascal/iX), you can eliminate some loads and stores. Th us, more optimization (suc h as using registers) can occur. Figure 5-1 sho ws an example of reducing aliasing.

Figure 5-1. Reducing Aliasing

Use Optimal Data Types

Examples of optimal data t ypes are 8-bit character and 32-bit in teger. For detailed information refer to the appropriate man ual in the Language Series.

5-4 Optimizing a Program