From 1206528e457740d757f1287742759b575da1c1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Sep 2026 11:23:09 -0600 Subject: [PATCH] Build: Turn off floating-point contraction for C++ Clang and GCC fuse a * b + c into one rounding on CPUs that have fused multiply-add, which on ARM64 made the interpreter's dot products, vavg, vdet and vqmul round differently from x86-64. Fused operations now only happen where the code asks for them. MSVC doesn't contract by default. Co-Authored-By: Claude Opus 5.5 (1M context) --- CMakeLists.txt | 3 +++ android/jni/Locals.mk | 2 +- libretro/Makefile | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff03e675da..98448dbc62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,6 +496,9 @@ if(NOT MSVC) add_compile_options(-fno-math-errno) + # No fused multiply-adds unless written explicitly, so float results are the same on every CPU. + add_compile_options("$<$:-ffp-contract=off>") + if(X86) # enable sse2 code generation (enabled by default on X86_64) if(NOT MACOSX) diff --git a/android/jni/Locals.mk b/android/jni/Locals.mk index c4033435c5..bcaac1e061 100644 --- a/android/jni/Locals.mk +++ b/android/jni/Locals.mk @@ -4,7 +4,7 @@ LOCAL_CFLAGS := -DUSE_FFMPEG -DWITH_UPNP -DUSING_GLES2 -DZ7_CRC_NUM_TABLES=1 -DMOBILE_DEVICE -O3 -fsigned-char -Wall -Wno-multichar -Wno-unused-variable -fno-strict-aliasing -D__STDC_CONSTANT_MACROS -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS # yes, it's really CPPFLAGS for C++ # deprecated-register is generated by Android default code and causes noise. -LOCAL_CPPFLAGS := -fexceptions -std=c++17 -frtti -Wno-reorder -Wno-deprecated-register -Wno-nullability-completeness +LOCAL_CPPFLAGS := -fexceptions -std=c++17 -ffp-contract=off -frtti -Wno-reorder -Wno-deprecated-register -Wno-nullability-completeness LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../../Common \ $(LOCAL_PATH)/../.. \ diff --git a/libretro/Makefile b/libretro/Makefile index f3a60535cc..35c739f73b 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -448,7 +448,8 @@ else endif ifeq (,$(findstring msvc,$(platform))) - CXXFLAGS += -std=c++17 + # No fused multiply-adds unless written explicitly, so float results are the same on every CPU. + CXXFLAGS += -std=c++17 -ffp-contract=off else CXXFLAGS += -std:c++17 endif