@@ -95,6 +95,9 @@ if (MSVC)
95
95
# and https://devblogs.microsoft.com/cppblog/the-fpcontract-flag-and-changes-to-fp-modes-in-vs2022/
96
96
# By default, MSVC doesn't enable the /fp:fast option.
97
97
set_cxx_flag("/fp:fast" )
98
+ else ()
99
+ # Precise model does safe contractions.
100
+ set_cxx_flag("/fp:precise" )
98
101
endif ()
99
102
100
103
if (USE_LTO)
@@ -118,14 +121,28 @@ else()
118
121
set_cxx_flag("-O3" RELWITHDEBINFO)
119
122
endif ()
120
123
124
+ try_cxx_flag(FNO_MATH_ERRNO "-fno-math-errno" )
125
+
121
126
if (USE_FAST_MATH)
122
- # By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*.
123
- # See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
124
- # By default, GCC doesn't enable the -ffast-math option.
125
- set_cxx_flag("-ffast-math -fno-math-errno -ffp-contract=fast" )
127
+ # GCC.
128
+ try_cxx_flag(FFAST_MATH "-ffast-math" )
129
+ try_cxx_flag(FFP_CONTRACT_FAST "-ffp-contract=fast" )
130
+ # Clang.
131
+ try_cxx_flag(FFP_MODEL_FAST "-ffp-model=agressive" )
132
+ # ICC.
133
+ try_cxx_flag(FP_MODEL_FAST_2 "-fp-model=fast=2" )
126
134
else ()
135
+ # By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*.
127
136
# By default, GCC uses -std=gnu* and then enables -ffp-contract=fast even if -ffast-math is not enabled.
128
- set_cxx_flag("-ffp-contract=off" )
137
+ # See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
138
+ # GCC. This still does safe contractions.
139
+ try_cxx_flag(FNO_FAST_MATH "-fno-fast-math" )
140
+ try_cxx_flag(FFP_CONTRACT_FAST "-ffp-contract=fast" )
141
+ # Clang. Precise model does safe contractions.
142
+ try_cxx_flag(FFP_MODEL_PRECISE "-ffp-model=precise" )
143
+ # ICC. Precise model does safe contractions.
144
+ try_cxx_flag(FP_MODEL_PRECISE "-fp-model=precise" )
145
+ try_cxx_flag(QSMID_HONOR_FP_MODEL "-qsimd-honor-fp-model" )
129
146
endif ()
130
147
131
148
# It should be done at the very end because it copies all compiler flags
0 commit comments