MATLAB: Code replacement for “abs” is “mw_arm_abs_f32” instead of “fabs”

Embedded Coder

I am attempting to generate code for the ARM Cortex-M using Embedded Coder. I am using a code replacement library in order to do this but it is not working correctly because the code generation process is replacing the calls to "abs" with "mw_arm_abs_f32" instead of the expected "fabs". How can I get code to be generated using the "fabs" function?

Best Answer

Code replacement during the code generation process is based on a series of constraints. If these constraints are met for a given case, the code is replaced with the specific function. You can view the code replacement table for the ARM Cortex-M using the command below:
 
RTW.viewTfl('ARM Cortex-M')
You will be able to see the constraints which must be met in order for each replacement to happen. As can be seen in the "In1Type" section for the "mw_arm_abs_f32" replacement, the size is a column vector of singles. Therefore, if you want to avoid this replacement being applied, you must ensure the size of the input is a 1x1 variable. If none of the replacement constraints are met, "fabs" will be used.