Real-Time Workshop | ![]() ![]() |
Supporting Expression Folding in S-Functions
This section describes how you can take advantage of expression folding to increase the efficiency of code generated by your own inlined S-function blocks by calling macros provided in the S-Function API.
This section assumes that you are familiar with:
The S-Function API lets you specify whether a given S-Function block should nominally accept expressions at a given input port. A block should not always accept expressions. For example, if the address of the signal at the input is used, expressions should not be accepted at that input, because it is not possible to take the address of an expression.
The S-Function API also lets you specify whether an expression can represent the computations associated with a given output port. When you request an expression at a block's input or output port, Simulink determines whether or not it can honor that request, given the block's context. For example, Simulink may deny a block's request to output an expression if the destination block does not accept expressions at its input; if the destination block has an update function; or if there are multiple output destinations.
The decision to honor or deny a request to output an expression can also depend on the category of output expression the block uses (see Categories of Output Expressions).
In the sections that follow, we explain:
To take advantage of expression folding in your S-functions, you need to understand when it is appropriate to request acceptance and generation of expressions for specific blocks. It is not necessary for you to understand the algorithm by which Simulink chooses to accept or deny these requests. However, if you want to trace between the model and the generated code, it will be helpful to understand some of the more common situations which lead to denial of a request.
![]() | Using and Configuring Expression Folding | Categories of Output Expressions | ![]() |