Skip to content

Commit cd7cdf4

Browse files
committed
test: Avoid -ffinite-math-only on floating point comparisons
With `-ffinite-math-only` (implied by `-ffast-math` and -Ofast), GCC considers all comparisons against infinities to be false and can optimize them away. This breaks several tests that rely on infinities to be compared correctly. To avoid this, we add GCC-specific optimize attribute that disables `-ffinite-math-only` optimization for floating point comarisions used in assertions. Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
1 parent 3113494 commit cd7cdf4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/test.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ simde_test_debug_printf_(const char* format, ...) {
126126
HEDLEY_DIAGNOSTIC_PUSH
127127
SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL_
128128

129+
#if defined(SIMDE_FAST_MATH) && defined(HEDLEY_GCC_VERSION) && HEDLEY_GCC_VERSION_CHECK(4,4,0)
130+
__attribute__((optimize("-fno-finite-math-only")))
131+
__attribute__((noinline))
132+
#endif
129133
static int
130134
simde_test_equal_f32(simde_float32 a, simde_float32 b, simde_float32 slop) {
131135
if (simde_math_isnan(a)) {
@@ -156,6 +160,10 @@ simde_test_equal_f16(simde_float16 a, simde_float16 b, simde_float16 slop) {
156160
return simde_test_equal_f32(af, bf, slopf);
157161
}
158162

163+
#if defined(SIMDE_FAST_MATH) && defined(HEDLEY_GCC_VERSION) && HEDLEY_GCC_VERSION_CHECK(4,4,0)
164+
__attribute__((optimize("-fno-finite-math-only")))
165+
__attribute__((noinline))
166+
#endif
159167
static int
160168
simde_test_equal_f64(simde_float64 a, simde_float64 b, simde_float64 slop) {
161169
if (simde_math_isnan(a)) {

0 commit comments

Comments
 (0)