[Mesa-dev] [PATCH 00/13] Avoid double promotion
Matt Turner
mattst88 at gmail.com
Mon Jul 13 16:22:02 PDT 2015
In the process of looking at the assembly generated from the OUT_BATCH
series, I noticed a bunch of float <-> double round trips. Mostly this
arises because unsuffixed floating-point literals are of type double,
and (float op double) is a double operation in which the float is
implicitly converted to double. This leads to some awful code for
simple things like
float x;
...
x += 1.0;
x is converted to double, 1.0 is added, and then x is converted back to
a float. :(
Most of the series is just adding f/F to floating-point literals (I
tried to use the suffix the surrounding code used) but there are also
some changes like s/sin/sinf/.
gcc has a warning flag (-Wdouble-promotion) that identifies places where
floats are implicitly cast to doubles (that I only found after I found
and fixed a bunch of things by looking at assembly) but it's not really
useful in general because float arguments are always cast to double
when passed as arguments to varargs functions like printf (why?), and
it warns about that, generating a lot of noise.
More information about the mesa-dev
mailing list