Skip to content

Commit

Permalink
cmake: also disable FP contraction when disabling fast math
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 16, 2024
1 parent 487cb5f commit 9fc7aa8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ if (MSVC)
# CMake already sets the /O2 flag on Release and RelWithDebInfo build and /O[1-2] already sets the /Oy flag.

if (USE_FAST_MATH)
# By default, the MSVC /fp:fast option enables /fp:contract (introduced in VS 2022).
# See https://learn.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior
# and https://devblogs.microsoft.com/cppblog/the-fpcontract-flag-and-changes-to-fp-modes-in-vs2022/
# By default, MSVC doesn't enable the /fp:fast option.
set_cxx_flag("/fp:fast")
endif()

Expand Down Expand Up @@ -109,7 +113,13 @@ else()
endif()

if (USE_FAST_MATH)
set_cxx_flag("-ffast-math -fno-math-errno")
# By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*.
# See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# By default, GCC doesn't enable the -ffast-math option.
set_cxx_flag("-ffast-math -fno-math-errno -ffp-contract=fast")
else()
# By default, GCC uses -std=gnu* and then enables -ffp-contract=fast even if -ffast-math is not enabled.
set_cxx_flag("-ffp-contract=off")
endif()

# It should be done at the very end because it copies all compiler flags
Expand Down

0 comments on commit 9fc7aa8

Please sign in to comment.