Why does the compiler not use any FPU instructions?
The Clang compiler complies with the ANSI standard. This means that, by default, the number "1.0" is regarded as a double, not a float.
If a 32-bit floating point unit is available and the float strategy is to generate fpu instructions(-mfloat-abi=hh32
), then no FPU instructions are generated by the compiler.
There are two ways to address this issue:
-
Explicitly declare float as "1.0f" instead of "1.0"
Since doubles have a higher resolution than floats, the result is less accurate, but the behaviour is predictable and complies with the ANSI standard. -
Use the same size for double as for float
If the compiler option-mfloat-abi=hh32
is used, the compiler will assume identical sizes for float and double and will generate 32-bit FPU instructions. For more details, please refer to the Multilib variants chapter in [1]. The advantage is the improved efficiency of the FPU. On the other hand, this option does not comply with the ANSI standard because the single precision is imposed on the expression, and the result is less precise despite the use of a double type.