From 645353cbdc8c0745c9d13b377c28624a61eca15c Mon Sep 17 00:00:00 2001 From: nabijaczleweli Date: Tue, 24 Mar 2020 13:04:06 +0100 Subject: [PATCH] Force SSE2 floats for i686 targets Both GCC and Clang use x87 instructions by default on 32-bit x86 targets, but the loss of precision resulting from that has yielded crashing tests (see referenced issue), and it can be safely assumed there are very few CPUs that both don't support SSE2 and are expected to run SolveSpace This commit also removes a now-redundant check for 32-bit Windows against TARGET, which doesn't seem to be actually set by CMake at all Ref: #565 --- CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc15578b..3e98325d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,11 +80,20 @@ endif() if(MINGW) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") +endif() - if(TRIPLE STREQUAL "i686-w64-mingw32") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") +# Ensure that all platforms use 64-bit IEEE floating point operations for consistency; +# this is most important for the testsuite, which compares savefiles directly +# and depends on consistent rounding of intermediate results. +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X86") + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(FLOAT_FLAGS "-mfpmath=sse -msse2") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(FLOAT_FLAGS "-msse2") endif() + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLOAT_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLOAT_FLAGS}") endif() if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")