The code generator increases the execution speed of the generated code where possible by
replacing global variables with local variables, removing data copies, using the
memcpy functions, and
reducing the amount of memory for storing data. You can increase the execution
speed of the generated code by implementing compiler and processor specific
optimizations, specifying buffer reuse, and removing code you might not
Processor Specific Optimizations
Increase code efficiency on your hardware by inserting pragmas in the generated code. Pragmas specify locations in memory to store data and functions.
Improve the execution speed of the generated code by replacing the
boolean built-in data type with a specific integer data type.
Minimize the possibility of execution slowdowns or overruns due to subnormal number calculation latency.
For processors that support efficient multiplication, improve code efficiency by using floating-point multiplication to handle a net slope correction.
Generate fixed-point code in Simulink®, Stateflow®, and MATLAB®.
Customize generated algorithm code with target-specific optimizations.
Specify target hardware device characteristics that can be critical in
embedded systems development (such as word sizes for
long data types, or desired rounding behaviors in
For processors that support FMA instructions, improve execution efficiency by performing fused multiply-add operations.
Compiler Specific Optimizations
Control compiler optimizations for your makefile at the Simulink UI level.
Optimizations that Improve Execution Efficiency
Choose a global variable reference optimization to satisfy your memory usage and execution speed requirements.
The code generator can change the block execution order to improve execution efficiency.
The code generator uses data dependency analysis to combine
for constructs to reduce static
code size and runtime branching.
The code generator performs various optimizations on the structures that represent signals in the generated code.
Starting at a default value of 5, the code generator begins to
for loop instead of separate
statements to assign values to the elements of a signal or
The code generator reduces the number of times a multiply operation executes in an array index by replacing the multiply operation with a temporary variable.
memset function clears internal
storage, regardless of type, to the integer bit pattern 0
bits are off).
The code generator optimizes the generated code for vector
assignments by replacing
for loops with
memcpy function calls.
For Switch and Multiport Switch blocks, Simulink executes only blocks that compute the control input and the data input that the control input selects.
The code generator optimizes fixed-point operations by replacing expensive division operations with highly efficient product operations.
Disable dynamic memory allocation or specify a dynamic memory allocation threshold for MATLAB Function blocks.
Generate LAPACK calls for certain linear algebra functions in a MATLAB function block. Specify LAPACK library to use.
Generate BLAS calls for certain low-level matrix operations. Specify BLAS library to use.
Generate FFTW library calls for fast Fourier transforms in a MATLAB Function block. Specify the FFTW library.
Implement FFT library callback class methods and provide supporting C code to prevent concurrent access to FFTW planning.
Implement parallel for-loops in the generated code for MATLAB Function and MATLAB System block using parfor.
parfor-loops that have small number of iterations.
Improve the execution speed of the generated code using Intel SSE and Intel AVX technology.
Model a fixed-point acoustic noise canceller.