Hi Hao, Thanks for the suggestion! Yes, - fno-math-errno is definitely more suitable for enabling globally than -ffast-math. While I don't particularly remember using errno for math functions in particularm it's used in non-math functions. So eventhough it seems reasonable to be enabled globally, still a bit tricky to validate that it doesn't cause any unintentional side effects with a large codebase with 3rd parety libs. Another weird side effect I noticed is GCC still doesn't inline the function when the function is within a `pragma GCC optimize ("-fno-math-errno") ` region and -ffast-math is enabled globally eventhough -fno-math-errno is a subset. If you enable both -ffast-math and -fno-math-errno, globally, the function gets inlined. I'm not sure if improving that should be considered as a bug-fix or a feature/enhancement. Best Regards, Hashan Gayasri On Thu, 4 Jan 2024, 8:28 pm LIU Hao, wrote: > 在 2024/1/4 17:01, Hashan Gayasri via Gcc-help 写道: > > I wanted the following to be to be optimized: > > > > (... ...) > > > > So that std::lrint uses the vcvtsd2si instruction on X86 with SSE2. It > > does that but prevents the instruction from being inlined. I complied > with > > - O3 -march=native -DNDEBUG. > > Actually `-ffast-math` is an overkill; `-fno-math-errno` isn't practically > bad, and can be enabled > globally: > (https://gcc.godbolt.org/z/hhfP6cYrr) > > ``` > //#pragma GCC push_options > //#pragma GCC optimize ("-ffast-math") > > inline int64_t __attribute__ ((const)) RoundToNearestLong (double v) > { > // assert(fegetround() == FE_TONEAREST); > return lrint(v); > } > > //#pragma GCC pop_options > > void > xgset(int64_t& r, double s) > { > r = RoundToNearestLong(s); > } > ``` > > results in > ``` > xgset(long&, double): > vcvtsd2si rax, xmm0 > mov QWORD PTR [rdi], rax > ret > ``` > > > > -- > Best regards, > LIU Hao > >