From e713d3567c95dae09b38b1327a4c51cf9f2ad47c Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Wed, 13 Sep 2023 00:54:04 -0400 Subject: [PATCH] use SSE registers for FP operations on i386 for moder gcc platform arches * only use if related are given, by example 32bit using gcc compilers/stdlibs becouse of the long time bugs around those errors by desing, its not about to crash the engine.. its about to permits to hacked clients (either players or the client program per se) making predictable results, so predictable results permits to catch securit issues! * floating point problems are only on modern gcc and modern platform arches, raising problems like bad calculations positions.. a long time bug reported at https://git.minetest.land/Mineclonia/Mineclonia/issues/201 and addressed at https://github.com/minetest/minetest/issues/11742#issuecomment-994444462 with enought explanations but not accepted byt stupid developers.. now years later.. the problems were solved and reconiced as big bug! A workaround were proposed at https://github.com/minetest/minetest/pull/12389/files but never accepted (included in this repository), cos was superset by https://github.com/minetest/minetest/commit/8ff3fadba033dbc686c4f834811f0744099fedfb * related https://codeberg.org/minenux/minetest-engine-multicraft2/issues/57 --- src/CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63f46a202..3b6cf158d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -830,6 +830,21 @@ else() set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions") endif() + # only related to moder x86 32bit platforms using gcc compilers + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.7) + # Enable SSE for floating point math on 32-bit x86 by default + # reasoning see minetest issue #11810 and https://gcc.gnu.org/wiki/FloatingPointMath + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + check_c_source_compiles("#ifndef __i686__\n#error\n#endif\nint main(){}" IS_I686) + if(IS_I686) + message(STATUS "Detected Intel x86: using SSE instead of x87 FPU") + set(OTHER_FLAGS "${OTHER_FLAGS} -mfpmath=sse -msse") + endif() + endif() + endif() + endif() + set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops") if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS} -Os")