Prepare for Code Generation

Prepare for Code Generation Overview

Identify settings that might lead to nonoptimal results in code generation.

Limitations

All tasks in this folder require a Real-Time Workshop license.

See Also

Disable signal logging

Disables unnecessary signal logging.

Description

Disabling unnecessary signal logging avoids declaring extra signal memory in generated code.

Analysis Results and Recommended Actions

ConditionsRecommended Action
Signals are logged.Disable signal logging on all signals.

Action Results

Clicking Modify All disables signal logging on all logged signals.

Limitations

This task requires a Real-Time Workshop license.

Identify blocks that generate expensive saturation and rounding code

Check for blocks that generate expensive saturation or rounding code.

Description

Analysis Results and Recommended Actions

ConditionsRecommended Action
Blocks generate expensive saturation code.Check each block to ensure that your application requires setting Function Block Parameters > Signal Attributes > Saturate on integer overflow. Otherwise, clear the Saturate on integer overflow parameter to ensure the most efficient implementation of the block in the generated code.
Generated code is inefficient.Set the Function Block Parameters > Round integer calculations toward parameter to the recommended value.

Limitations

This task requires a Real-Time Workshop license.

Identify questionable fixed-point operations

Identify fixed-point operations that can lead to nonoptimal results.

Description

The following operations can lead to nonoptimal results:

Analysis Results and Recommended Actions

ConditionsRecommended Action
Integer division generated code is large.Set the Configuration Parameters > Hardware Implementation > Signed integer division rounds to parameter to the recommended value.
Protection code generated as part of the division operation is redundant.Verify that your model cannot cause exceptions in division operations and then remove redundant protection code by setting the Configuration Parameters > Optimization > Remove code that protects against division arithmetic exceptions parameter.
Generated code is inefficient.Set the Function Block Parameters > Round integer calculations toward parameter to the recommended value.
Lookup table input data is not evenly spaced.If the data is nontunable, adjust the table to be evenly spaced. See fixpt_look1_func_approx.
Lookup table input data is not evenly spaced when quantized, but it is very close to being evenly spaced.If the data is nontunable, adjust the table to be evenly spaced. See fixpt_evenspace_cleanup.
Lookup table input data is evenly spaced, but the spacing is not a power of 2.If the data is nontunable, reimplement the table with even power-of-2 spacing. See fixpt_look1_func_approx.
Index search method is set to Evenly-spaced points.Specify a different Function Block Parameters > Index search method to avoid the division operation.
Blocks require cumbersome multiplication. Restrict multiplication operations:
  • So the product integer size is no larger than the target integer size.

  • To the recommended size.

Blocks multiply signals with nonzero bias.Insert a Data Type Conversion block before and after the block containing the multiplication operation.
Product blocks are multiplying signals with mismatched slope adjustment factors.Change the scaling of the output so that its slope adjustment factor is the product of the input slope adjustment factors.
Product blocks are configured to do multiple division operations.Multiply all the denominator terms together, and then do a single division using cascading Product blocks.
Product blocks are configured to do many multiplication or division operations.Split the operations across several blocks, with each block performing one multiplication or one division operation.
Product blocks are configured with a divide operation for the first input and a multiply operation for the second input. Reverse the inputs so the multiply operation occurs first and the division operation occurs second.
An input with an invariant constant value is used as the denominator in an online division operation. Change the operation to multiplication, and replace the invariant input by its reciprocal.
The data type range of the inputs of Sum blocks exceeds the data type range of the output, which can cause overflow or saturation.

Change the output and accumulator data types so the range equals or exceeds all input ranges.

For example, if the model has two inputs

  • int8 (–128 to 127)

  • uint8 (0 to 255)

The data type range of the output and accumulator must equal or exceed –128 to 255. A int16 (–32768 to 32767) data type meets this condition.

A Sum block has an input with a slope adjustment factor that does not equal the slope adjustment factor of the output.Change the data types so the inputs, outputs, and accumulator have the same slope adjustment factor.
The net sum of the Sum block input biases does not equal the bias of the output. Change the bias of the output scaling, making the net bias adjustment zero.
The inputs of the Relational Operator block have different data types.
  • Change the data type and scaling of the invariant input to match other inputs.

  • Insert Data Type Conversion blocks before the Relational Operator block to convert both inputs to a common data type.

The inputs of the Relational Operator block have different slope adjustment factors.Change the scaling of either input.
The input and output of the MinMax block have different data types.Change the data type of the input or output.
The input of the MinMax block has a different slope adjustment factor than the output. Change the scaling of the input or the output.
The initial condition of the Discrete-Time Integrator block is used to initialize both the state and the output. Set the Function Block Parameters > Use initial condition as initial and reset value for parameter to State only (most efficient).

Limitations

This task requires Real-Time Workshop and Simulink Fixed Point licenses.

See Also

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS