I am working on code for a arm Cortex-M4F with a fpv4-sp-d16 and ABI=hard.
As i was looking with Ozone into my elf file I found that my code uses some double precision functions: eg. __aeabi_dmul
If I don't use sqrtf
or use the -ffast-math option, the double support function are no longer linked.
Since I do not know what other implications the -ffast-math option introduces, I would like to not use that option.
Are there any other option to get a float sqrt function?
Using ARM-GCC 10 2021.10 with -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Os -fsingle-precision-constant -Wfloat-equal -Wdouble-promotion
I found in the Disassembly that inside of sqrtf
the __aeabi_ddiv
is called.
The suggested solution:
float sqrtf_wrap(float x) __attribute__((optimize("fast-math")));
float sqrtf_wrap(float x)
{
if(x >= 0.0f)
return __builtin_sqrtf(x);
else
return NAN;
}
does not change the build result: __aeabi_ddiv
is still used.
Update/Solution
I found a question where one had the same problem: Double division in sqrtf? [UPDATE]
His solution: Directly calling __ieee754_sqrtf
works(there is directly the VSQRT.F32 instruction) for me as well.
Further more I found that sqrtf
with -fno-math-errno also works .
Unfortunately a wrapper with local optimization options does Not work - seems that the optimization is not applied to the called math function.
Therefore I will use
__ieee754_sqrtf
instead of sqrtf