You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to use Clang for a microcontroller project (Cortex-M4 with FPU), I am seeing fabs(-0) returning -0. But the correct result is 0. Note, this is for calculation with doubles not floats.
Attached is a simple test case that can be compiled to assembly, and the resulting assembly, produced with the command below.
I cannot read ARM assembly well but I suspect the inlined implementation of fabs really is incorrect with respect to -0. I have also attached the result of compiling with GCC (same command line), which seems to be a much more optimized implementation.
Also note, trying to workaround this with "-fno-builtin-fabs" does not work. Even for the simple case when no C headers are included and instead a declaration of fabs is given with "extern double fabs(double);" (so the headers could not be replacing it with __builtin_fabs). On the other hand, "-fno-builtin" does work (but is not really a workaround considering it affects other builtins).
Extended Description
While trying to use Clang for a microcontroller project (Cortex-M4 with FPU), I am seeing fabs(-0) returning -0. But the correct result is 0. Note, this is for calculation with doubles not floats.
Attached is a simple test case that can be compiled to assembly, and the resulting assembly, produced with the command below.
I cannot read ARM assembly well but I suspect the inlined implementation of fabs really is incorrect with respect to -0. I have also attached the result of compiling with GCC (same command line), which seems to be a much more optimized implementation.
arm-none-eabi-clang -mcpu=cortex-m4 -mthumb -O2 -fno-math-errno -fno-trapping-math -fshort-enums -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-rtti -fno-exceptions abs.c -S -o abs.S
Clang was configured as follows:
../configure --enable-targets=arm --target=arm-none-eabi --enable-cxx11 --disable-docs
--with-gcc-toolchain=${gcc-arm-embedded}/lib/gcc/arm-none-eabi/$gccVersion
--with-c-include-dirs=${gcc-arm-embedded}/arm-none-eabi/include
The text was updated successfully, but these errors were encountered: