Browse Source

Supporting SIMD for WASM build (#963)

Use -msimd128 -msse4.2 options with emscripten to enable this.

Fixes #957
Jorrit Rouwe 1 year ago
parent
commit
3824d58d09
4 changed files with 24 additions and 19 deletions
  1. 5 0
      Jolt/Core/Core.h
  2. 5 5
      Jolt/Core/FPControlWord.h
  3. 8 8
      Jolt/Core/FPException.h
  4. 6 6
      Jolt/Core/FPFlushDenormals.h

+ 5 - 0
Jolt/Core/Core.h

@@ -181,6 +181,11 @@
 	#define JPH_CPU_ADDRESS_BITS 32
 	#define JPH_VECTOR_ALIGNMENT 16
 	#define JPH_DVECTOR_ALIGNMENT 32
+	#ifdef __wasm_simd128__
+		#define JPH_USE_SSE
+		#define JPH_USE_SSE4_1
+		#define JPH_USE_SSE4_2
+	#endif
 #elif defined(__e2k__)
 	// Elbrus e2k architecture
 	#define JPH_CPU_E2K

+ 5 - 5
Jolt/Core/FPControlWord.h

@@ -8,7 +8,11 @@
 
 JPH_NAMESPACE_BEGIN
 
-#ifdef JPH_USE_SSE
+#if defined(JPH_CPU_WASM)
+
+// Not supported
+
+#elif defined(JPH_USE_SSE)
 
 /// Helper class that needs to be put on the stack to update the state of the floating point control word.
 /// This state is kept per thread.
@@ -122,10 +126,6 @@ private:
 	uint32		mPrevState;
 };
 
-#elif defined(JPH_CPU_WASM)
-
-// Not supported
-
 #else
 
 #error Unsupported CPU architecture

+ 8 - 8
Jolt/Core/FPException.h

@@ -10,7 +10,14 @@ JPH_NAMESPACE_BEGIN
 
 #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
 
-#if defined(JPH_USE_SSE)
+#if defined(JPH_CPU_WASM)
+
+// Not supported
+class FPExceptionsEnable { };
+class FPExceptionDisableInvalid { };
+class FPExceptionDisableDivByZero { };
+
+#elif defined(JPH_USE_SSE)
 
 /// Enable floating point divide by zero exception and exceptions on invalid numbers
 class FPExceptionsEnable : public FPControlWord<0, _MM_MASK_DIV_ZERO | _MM_MASK_INVALID> { };
@@ -49,13 +56,6 @@ class FPExceptionDisableInvalid : public FPControlWord<0, FP_IOE> { };
 /// Disable division by zero floating point exceptions
 class FPExceptionDisableDivByZero : public FPControlWord<0, FP_DZE> { };
 
-#elif defined(JPH_CPU_WASM)
-
-// Not supported
-class FPExceptionsEnable { };
-class FPExceptionDisableInvalid { };
-class FPExceptionDisableDivByZero { };
-
 #else
 
 #error Unsupported CPU architecture

+ 6 - 6
Jolt/Core/FPFlushDenormals.h

@@ -8,7 +8,12 @@
 
 JPH_NAMESPACE_BEGIN
 
-#if defined(JPH_USE_SSE)
+#if defined(JPH_CPU_WASM)
+
+// Not supported
+class FPFlushDenormals { };
+
+#elif defined(JPH_USE_SSE)
 
 /// Helper class that needs to be put on the stack to enable flushing denormals to zero
 /// This can make floating point operations much faster when working with very small numbers
@@ -27,11 +32,6 @@ static constexpr uint64 FP_FZ = 1 << 24;
 /// This can make floating point operations much faster when working with very small numbers
 class FPFlushDenormals : public FPControlWord<FP_FZ, FP_FZ> { };
 
-#elif defined(JPH_CPU_WASM)
-
-// Not supported
-class FPFlushDenormals { };
-
 #else
 
 #error Unsupported CPU architecture