4 ms·
For the change to reorder the additions to add int-to-int and float-to-float to remove one conversion, I wonder if the compiler would do that itself if allowed
by JoshTriplett 11y ago
For the change to reorder the additions to add int-to-int and float-to-float to remove one conversion, I wonder if the compiler would do that itself if allowed to by -ffast-math (included in -Ofast)? Normally, the compiler cannot (even with -O3) perform changes that might change exact floating-point results.
EDIT: No, looks like gcc can't do this even with -ffast-math or -Ofast. Given the following C code:
double test1(int lbits, double lsym, int dbits, double dsym)
{
return lsym + lbits + dsym + dbits;
}
double test2(int lbits, double lsym, int dbits, double dsym)
{
return lbits + dbits + lsym + dsym;
}
GCC, with either -O3 or -Ofast, with or without -ffast-math, always produces two cvtsi2sd instructions for test1 and one cvtsi2sd instruction for test2.
Filed as a GCC feature request: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70731 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70731
- jtlim 11y agoHi, author of article here. I tested -ffast-math on clang and it won't reorder the additions to omit the conversion here. I'm actually VERY wary of -ffast-math due to a bad experience some years ago where it just totally messed up my calculations and I couldn't avoid it messing up my calculations. Even a 1ulp change (not accounting for the round down) in the final floating point comparison changed my compression results; so I'm not entirely confident about using -ffast-math without a huge test corpus -- but turning it on does improve the run time.