rtIsNaN implementation does not work on ARM7 target without FPU
Show older comments
Hello there,
I generate code using Matlab Coder for an ARM7TDMI target (Device: ARM compatible, Type: ARM 7, Standard math library: C89/C90) that uses the C89/90 math.h (GNUARM) to do floating point operations.
The code that Coder emits for the function that is used to test for NaN looks like this (in rt_nonfinite.c):
boolean_T rtIsNaN(real_T value)
{
return (value!=value)? 1U:0U;
}
Unfortunately, that test fails on target. It is not true for rtNaN. rtNaN is properly initialized to the pattern required for an LE machine. I assume that the math library just does not support it.
I have worked around that by replacing the statement with:
return ((value!=value) || (value==rtNaN))? 1U:0U;
This works, but I would rather not patch in the generated code.
Is there anything I can do to change/fix what the Coder emits here? Or do I need to disable support for non-finite numbers altogether?
Thanks
5 Comments
Nathan S
on 22 Feb 2021
What compiler are you using? In general, the emitted code should be working no matter the target, but this pattern is somtimes not handled correctly by C compilers making optimizations. Depending on your compiler, there might be a flag that can be used to stop these optimizations.
I don't think there is a good way to change the code that Coder is emitting.
Julian
on 22 Feb 2021
Nathan S
on 23 Feb 2021
-O3 should be safe, so I am not too surprised that -O0 didn't work either. I am not sure what the best workaround is for this situation, but I am looking into it and will hopefully have a more helpful answer soon.
Turning off nonfinites is definitely not what you should do. For the most part, doing so will cause Coder to assume that none of your values are ever Inf or Nan, so this check would be removed altogether and is likely to cause unexpected behavior.
Julian
on 23 Feb 2021
Answers (1)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!