Browse Source

Added USE_WASM_SIMD cmake option

This will enable SIMD on the emscripten WASM build
Jorrit Rouwe 1 year ago
parent
commit
256a61aeea
2 changed files with 10 additions and 1 deletions
  1. 4 0
      Build/CMakeLists.txt
  2. 6 1
      Jolt/Jolt.cmake

+ 4 - 0
Build/CMakeLists.txt

@@ -47,6 +47,10 @@ option(USE_TZCNT "Enable TZCNT" ON)
 option(USE_F16C "Enable F16C" ON)
 option(USE_F16C "Enable F16C" ON)
 option(USE_FMADD "Enable FMADD" ON)
 option(USE_FMADD "Enable FMADD" ON)
 
 
+# Enable SIMD for the WASM build. Note that this is currently off by default since not all browsers support this.
+# See: https://caniuse.com/?search=WebAssembly%20SIMD (Safari got support in March 2023 and was the last major browser to get support).
+option(USE_WASM_SIMD "Enable SIMD for WASM" OFF)
+
 # Enable all warnings
 # Enable all warnings
 option(ENABLE_ALL_WARNINGS "Enable all warnings and warnings as errors" ON)
 option(ENABLE_ALL_WARNINGS "Enable all warnings and warnings as errors" ON)
 
 

+ 6 - 1
Jolt/Jolt.cmake

@@ -620,7 +620,12 @@ else()
 	elseif (CROSS_COMPILE_ARM OR CMAKE_OSX_ARCHITECTURES MATCHES "arm64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
 	elseif (CROSS_COMPILE_ARM OR CMAKE_OSX_ARCHITECTURES MATCHES "arm64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
 		# ARM64 uses no special commandline flags
 		# ARM64 uses no special commandline flags
 	elseif (EMSCRIPTEN)
 	elseif (EMSCRIPTEN)
-		# Emscripten uses no special flags, if you want to turn on SIMD you should use -msimd128 -msse4.2
+		if (USE_WASM_SIMD)
+			# Jolt currently doesn't implement the WASM specific SIMD intrinsics so uses the SSE 4.2 intrinsics
+			# See: https://emscripten.org/docs/porting/simd.html#webassembly-simd-intrinsics
+			# Note that this does not require the browser to actually support SSE 4.2 it merely means that it can translate those instructions to WASM SIMD instructions
+			target_compile_options(Jolt PUBLIC -msimd128 -msse4.2)
+		endif()
 	elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386")
 	elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386")
 		# x86 and x86_64
 		# x86 and x86_64
 		# On 32-bit builds we need to default to using SSE instructions, the x87 FPU instructions have higher intermediate precision
 		# On 32-bit builds we need to default to using SSE instructions, the x87 FPU instructions have higher intermediate precision