Target Language Compiler    

Advantages of Inlining S-Functions

Motivations

The goals of generated code usually include compactness and speed. On the other hand, S-functions are run-time-loadable extension modules for adding block-level functionality to Simulink. As such, the S-function interface is optimized for flexibility in configuring and using blocks in a simulation environment with capability to allow run-time changes to a block's operation via parameters. These changes typically take the form of algorithm selection and numerical constants for the block algorithms.

While switching algorithms is a desirable feature in the design phase of a system, when the time comes to generate code, this type of flexibility is often dropped in favor of optimal calculation speed and code size. TLC was designed to allow the generation of code that is compact and fast by selectively generating only the code you need for one instance of a block's parameter set.

When Inlining Is Not Appropriate

You may decide that inlining is not appropriate for certain C MEX S-functions. This may be the case if an S-function has

Whenever you encounter this situation, the effort of inlining the block may not improve execution speed and could actually increase the size of the generated code. The trade-off is in the size of the block's body code generated for each instance vs. the size of the child SimStruct created for each instance of a noninlined S-function in the generated code.

Alternatively, you can use a hybrid inlining method known as a C MEX wrappered S-function, where the block target file is used to simply generate a call to a custom code function that the S-function itself also calls. This approach may be the optimal solution for code generation in the case of a large piece of existing code. An adaptation of this hybrid technique is used for calling the rt_*.c library functions located in directory rtw/c/libsrc/. See Inlining S-Functions for the procedure and an example of a wrappered S-function.


  A Look at Inlined and Noninlined S-Function Code Inlining Process