From c5984d7f02ccb746b869f327c49775471aac8f44 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Wed, 10 Jan 2024 11:12:23 -0800 Subject: [PATCH] Add `-ffp-contract=off` compile flag. GCC per default enables one optimization for x86_64 that can change the result of floating-point operations: -ffp-contract=fast. This allows the compiler to do floating-point expression contraction such as combining multiplication and addition instructions with an FMA instruction. However, the FMA instruction omits the rounding done in the multiplication instruction, making the calculations produce different results for some input values. Disabling floating-point contraction with -ffp-contract=off makes GCC generate code that produces a consistent result for x86_64. See https://kristerw.github.io/2021/11/09/fp-contract/ The `fft_test` checks that this is working correctly. Signed-off-by: Tim 'mithro' Ansell --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9692bdb407..62e4903aa2 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -192,6 +192,9 @@ add_compile_options( -Wno-sign-compare -Wp,-D_GLIBCXX_ASSERTIONS $<$:-Wno-gnu-zero-variadic-macro-arguments> + # Needed for floating point stability in FFT (fft_test will check this). + # See also https://kristerw.github.io/2021/11/09/fp-contract/ + -ffp-contract=off # Apple clang 14.0.0 deprecates sprintf, which generates 900 warnings. $<$:-Wno-deprecated-declarations> $<$:-fsanitize=address>