-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Description
According to the documentation, x87 math should have the precision limited to the nominal precision of the type:
https://clang.llvm.org/docs/UsersManual.html
For example, even on pre-SSE X86 targets where
float
anddouble
computations must be performed in the 80-bit X87 format, Clang rounds all intermediate results correctly for their type.
Despite this, for a test function like this, the full x87 precision is retained even if both intermediates are assigned to float types (the same also holds if using explicit casts).
int math(float a, float b, float c) {
float prod = a * b;
float sum = prod + c;
return (int)sum;
}
$ clang --target=i686-linux-gnu -mno-sse -O2 -fexcess-precision=standard math.c -S -o -
This differs from GCC, where -fexcess-precision=standard
does limit the precision to the nominal precision of type type - see https://godbolt.org/z/arMsje11T. Here, GCC produces
fstp DWORD PTR [esp]
fld DWORD PTR [esp]
after both the multiplication and the addition, while Clang does nothing to limit the intermediate precision.