Removal of Redundant Code

Article 2 of 3: Model Optimization with emmtrix”
February 11, 2025

To further reduce the size of the C code generated from Simulink models (as seen in Part 1), the next step is to remove redundant parts in the C code. Due to the complexity of the models, some parts may exist multiple times in the generated C code:

  • Functions with identical functionality can be generated with different names and used by different modules.
  • Data types such as structs and arrays, along with defines, can exist with identical structures but different names.
  • Code blocks can perform identical operations on data in different parts of the program.

Here an example of two redundant structs and functions:

 

The emmtrix tools can be used to identify these redundancies in the source code and help estimate the memory savings that can be achieved by optimizing the model. A detailed report combines the findings with information from the Simulink model to provide suggestions on how to modify the models to improve the size of the generated C code by reusing blocks, signals, and functions.

When applied to actual production code, potential code size savings of up to 30% were observed. However, it should be noted that the potential is not always realizable in the model, as it may be prevented by the structures or requirements of the model.

A more integrated approach to making changes easier to apply is currently under development, with more news to follow later in the year.

For more details, visit the emmtrix Performance Estimator or contact Rainer Heim: 📞 +49 170 447 2986, 📧 rainer.heim@emmtrix.com

Cookie Consent with Real Cookie Banner