Chapter 7 Code Optimization
AutoCode Reference 7-16 ni.com
input of the gain block and the expression 2.0 * const_2 is evaluated to
4 as the value of const_2_1 is 2. Hence, the subsystem output gets the
value 4.
The command-line option for invoking this optimization is -Opc.
Optimizing with Matrix BlocksOutputs labeled as matrices are generated as vectors, so most matrix blocks
can be optimized by following the rules you would follow for any other
vectorized block:
• Try to group all the outputs into a single vector (or matrix) so the
output variable will be an array
• Try to connect all the inputs from the same output array of a single
block, in a smooth stride
In general, this leads to looped code rather than unrolled code being
generated for a block—which reduces the code footprint—or at least to the
fewest number of loops per block. This applies to the MatrixTranspose,
MatrixMultiply, LeftMultiply, RightMultiply, and ScalarGain blocks.
Optimizing with Constant Blocks
Constant blocks are highly optimized by design. When you create a
constant block and label the output as a single matrix, you will not see any
code generated for the block—the constant values defined in the block will
be part of the declaration of the block output variable at the top of the
containing subsystem or procedure.
By default, such output variables are declared as type “static” in C or
“constant” in Ada and thus should not require separate assembly
instructions to load values into position. For C, you can make them stack
variables (automatics) by modifying the definition of RT_CONSTANT in the
sa_types.h file. If you declare the output variable to be a stack variable,
assembly instructions are generated to load its values into place each time
the containing subsystem or procedure is executed.
The previous information applies provided you have not used a %Variable
in the block. If a %Variable is present, a different optimization takes over.
Instead of putting values into the declaration—which you cannot do in the
case of a %Variable—you perform forward propagation on the constant
block, replacing references to the constant block with direct references to
the associated %Variable. If all use points can be so optimized, the entire