性能 -凯发k8网页登录
减少内存使用量并提高生成的代码的执行速度
当开发您打算从中生成代码的 simulink® 模型时,请使用模型配置参数来减少 ram 和 rom 的消耗并加快代码执行速度。如果您愿意为提高代码的安全性而牺牲一定的效率,则可以禁用其中一个或多个参数。
您可以配置对代码的执行进行探查,以确定生成的代码是否符合需要改进内存使用量或执行速度的代码节和目标硬件的实时要求。您还可以使用代码生成顾问检查模型的当前配置是否已针对调试或代码执行进行了优化。
模型设置
主题
代码优化基础知识
alter a model to increase the speed at which the code generator generates code.
apply design tools and techniques to optimize a model for code generation.
control compiler optimizations for your makefile at the simulink ui level.
防御式编程
minimize the possibility of execution slowdowns or overruns due to subnormal number calculation latency.
if the input values in your application are in the range of the output type, remove code for out-of-range floating-point to integer conversions.
if input values ofnan
do not exist in your application, specify that the code generator remove code that mapsnan
to integer zero.
use code replacement library (crl) customization entries to selectively disable nonfinite checks for math functions and inlining of math functions.
减少数据副本
the code generator folds block computations into a single expression, instead of generating separate code statements and storage declarations for each block in a model.
expression fold code to minimize the computation of intermediate results at block outputs and the storage of such results in temporary buffers or variables.
where possible, the code generator declares block outputs as local variables, so that it can potentially reuse these variables.
model buses to maximize efficiency of the generated code.
use the numerical values of invariant signals instead of their symbolic names in the generated code.
the code generator optimizes the generated code for vector assignments by replacingfor
loops withmemcpy
function calls.
model buses to maximize efficiency of the generated code.
内存使用量
the code generator reduces stack memory by replacing temporary local arrays with local variables.
reduce the amount of memory that stores state configuration variables andboolean
variables.
thememset
function clears internal storage, regardless of type, to the integer bit pattern 0 (that is, all bits are off).
control the maximum allowable stack size to provide some control over whether data is defined locally or globally in the generated code.
starting at a default value of 5, the code generator begins to use afor
loop instead of separate statements to assign values to the elements of a signal or parameter array.
generate code whose floating-point data types are only single precision, for example, for targeting a single-precision processor.
to generate more efficient code, match parameter data types with signal data types or store parameters in smaller data types.
the code generator optimizes the generated code by storing logical signals asboolean
data types.
优化代码生成器为经过时间或绝对时间分配的内存。
执行速度
the code generator uses data dependency analysis to combinefor
constructs to reduce static code size and runtime branching.
starting at a default value of 5, the code generator begins to use afor
loop instead of separate statements to assign values to the elements of a signal or parameter array.
the code generator eliminates dead (that is, unused) code paths from the generated code.
for processors that support efficient multiplication, improve code efficiency by using floating-point multiplication to handle a net slope correction.
the code generator increases execution speed and reduces rom consumption by removing code that does not impact computational results.
reduce global ram usage by inlining the literal numeric values of block parameters.
generate fixed-point code in simulink, stateflow®, and matlab®.
customize generated algorithm code with target-specific optimizations.
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 performs various optimizations on the structures that represent signals in the generated code.
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.
禁用动态内存分配或为 matlab function 模块指定动态内存分配阈值。
improve the execution speed of the generated code using intel® sse and intel avx technology.
generate optimized code for reduction operations using simd instruction sets.
代码执行探查
使用代码执行探查来观察代码执行速度。