Guidelines for Using the Optimizer [ HP C Programmer's Guide ] MPE/iX 5.0 Documentation
HP C Programmer's Guide
Guidelines for Using the Optimizer
The following guidelines help you effectively use the optimizer and write
efficient HP C programs.
1. Use register variables where needed.
2. Hash table sizes should be in powers of 2; field sizes of
variables should also be in powers of 2.
3. Where possible, use local variables to help the optimizer promote
variables to registers.
4. When using short or char variables or bit-fields, it is more
efficient to use unsigned variables rather than signed because a
signed variable causes an extra instruction to be generated.
5. The code generated for a test for a loop termination is more
efficient with a test against zero than for a test against some
other value. Therefore, where possible, construct loops so the
control variable increases or decreases towards zero.
6. Do loops and for loops are more efficient than while loops because
opportunities for removing loop invariant code are greater.
7. Whenever possible, pass and return pointers to large structs
instead of passing and returning large structs by value.
8. Do shift, multiplication, division, or remainder operations using
constants instead of variables whenever possible.
9. Insure all local variables are initialized before they are used.
10. Use type checking tools like lint to help eliminate semantic
errors.
MPE/iX 5.0 Documentation