© National Instruments Corporation 7-1 AutoCode Reference
7
Code OptimizationThis chapter explains the details of generating production quality code for
micro controller-based applications. Generally, micro controller-based
applications have stringent requirements for code size and execution speed.
AutoCode supports various optimizations that could be used effectively
to generate highly optimal code both in terms of speed and code size.
Chapter6, Vectorized Code Generat ion, explains the first step in this
direction, namely generating vectorized code that could significantly
reduce the code size of an application. This chapter explores other
optimizations supported by AutoCode.
Read from Variable Blocks
Variable blocks, both global and local, could be extensively used in any
application in order to store values from computations. AutoCode
sequences variable blocks and uses them in a deterministic fashion. When
a Read from Variable block is used, it is first copied into a temporary local
variable, and this variable is used in all further computations. This is not
strictly required for local variable blocks; and for global variable blocks
that are not shared across subsystems. Hence, instead of using the
temporary variable, the variable block could be used directly in all the
computations. Elimination of the temporary variable would result in
reduced code size, reduced stack size, and improved execution speed.
The code fragment in Example 7-1 shows the code generated by AutoCode
without this optimization; Example 7-2 shows code generated with variable
block optimization.
Example 7-1 Code Generated without Variable Block Optimization
/* Model variable definitions */
RT_FLOAT var;
RT_FLOAT var1;
void subsys_1(U,Y)
struct _Sys_ExtIn *U;
struct _Subsys_1_out *Y;
{