Friday, December 04, 2009

Some rough points of optimization in embedded system

The first step in optimization is to determine which problems you have. Size issues or speed issues? Let the compiler do the optimization first. In GNU C, O3 turns on all available gcc optimizations.

To increase code efficiency, you may try:

  1. inline function.
  2. assembly. Usually compiler will do this, but sometimes hand-coded assembly is better.
  3. register variables.
  4. global variables. Sometimes it is better than passing parameters to functions.
  5. fix-point arithmetic. Try to avoid float.
  6. check you loop. Use loop unrolling.

To decrease code size:

  1. avoid standard library routines, the function like ‘strupr…’ may cost your code.
  2. use ‘goto’ statement if it is necessary.

No comments:

Post a Comment