The conditions when convert from double to float is permitted?
Marc Glisse
marc.glisse@inria.fr
Thu Dec 10 10:21:23 GMT 2020
On Thu, 10 Dec 2020, Xionghu Luo via Gcc wrote:
> I have a maybe silly question about whether there is any *standard*
> or *options* (like -ffast-math) for GCC that allow double to float
> demotion optimization? For example,
>
> 1) from PR22326:
>
> #include <math.h>
>
> float foo(float f, float x, float y) {
> return (fabs(f)*x+y);
> }
>
> The fabs will return double result but it could be demoted to float
> actually since the function returns float finally.
With fp-contract, this is (float)fma((double)f,(double)x,(double)y). This
could almost be transformed into fmaf(f,x,y), except that the double
rounding may not be strictly equivalent. Still, that seems like it would
be no problem with -funsafe-math-optimizations, just like turning
(float)((double)x*(double)y) into x*y, as long as it is a single operation
with casts on all inputs and output. Whether there are cases that can be
optimized without -funsafe-math-optimizations is harder to tell.
--
Marc Glisse
More information about the Gcc
mailing list