File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,10 @@ if (MSVC)
8080 # CMake already sets the /O2 flag on Release and RelWithDebInfo build and /O[1-2] already sets the /Oy flag.
8181
8282 if (USE_FAST_MATH)
83+ # By default, the MSVC /fp:fast option enables /fp:contract (introduced in VS 2022).
84+ # See https://learn.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior
85+ # and https://devblogs.microsoft.com/cppblog/the-fpcontract-flag-and-changes-to-fp-modes-in-vs2022/
86+ # By default, MSVC doesn't enable the /fp:fast option.
8387 set_cxx_flag("/fp:fast" )
8488 endif ()
8589
@@ -109,7 +113,13 @@ else()
109113 endif ()
110114
111115 if (USE_FAST_MATH)
112- set_cxx_flag("-ffast-math -fno-math-errno" )
116+ # By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*.
117+ # See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
118+ # By default, GCC doesn't enable the -ffast-math option.
119+ set_cxx_flag("-ffast-math -fno-math-errno -ffp-contract=fast" )
120+ else ()
121+ # By default, GCC uses -std=gnu* and then enables -ffp-contract=fast even if -ffast-math is not enabled.
122+ set_cxx_flag("-ffp-contract=off" )
113123 endif ()
114124
115125 # It should be done at the very end because it copies all compiler flags
You can’t perform that action at this time.
0 commit comments