Browse Source

Moving -mfpmath option to Jolt.cmake (#848)

This makes it possible to make a 32 bit build on Linux using only -DCMAKE_CXX_FLAGS=-m32. Unfortunately the cmake code is a bit convoluted as clang-cl doesn't like the -mfpmath option.

See: godot-jolt/godot-jolt#739
Jorrit Rouwe 1 year ago
parent
commit
36d1418f5c
2 changed files with 9 additions and 1 deletions
  1. 1 1
      .github/workflows/build.yml
  2. 8 0
      Jolt/Jolt.cmake

+ 1 - 1
.github/workflows/build.yml

@@ -69,7 +69,7 @@ jobs:
     - name: Install G++-Multilib
       run: sudo apt -y install g++-multilib
     - name: Configure CMake
-      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} -DCMAKE_CXX_FLAGS="-m32 -msse2 -mfpmath=sse" -DUSE_SSE4_1=OFF -DUSE_SSE4_2=OFF -DUSE_AVX=OFF -DUSE_AVX2=OFF -DUSE_AVX512=OFF -DUSE_LZCNT=OFF -DUSE_TZCNT=OFF -DUSE_F16C=OFF -DUSE_FMADD=OFF Build
+      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} -DCMAKE_CXX_FLAGS=-m32 -DUSE_SSE4_1=OFF -DUSE_SSE4_2=OFF -DUSE_AVX=OFF -DUSE_AVX2=OFF -DUSE_AVX512=OFF -DUSE_LZCNT=OFF -DUSE_TZCNT=OFF -DUSE_F16C=OFF -DUSE_FMADD=OFF Build
     - name: Build
       run: cmake --build ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -j 2
     - name: Test

+ 8 - 0
Jolt/Jolt.cmake

@@ -596,6 +596,14 @@ else()
 		if (USE_FMADD AND NOT CROSS_PLATFORM_DETERMINISTIC)
 			target_compile_options(Jolt PUBLIC -mfma)
 		endif()
+
+		# On 32-bit builds we need to default to using SSE instructions, the x87 FPU instructions have higher intermediate precision
+		# which will cause problems in the collision detection code (the effect is similar to leaving FMA on, search for
+		# JPH_PRECISE_MATH_ON for the locations where this is a problem).
+		if (NOT MSVC)
+			target_compile_options(Jolt PUBLIC -mfpmath=sse)
+		endif()
+
 		EMIT_X86_INSTRUCTION_SET_DEFINITIONS()
 	endif()
 endif()