|
@@ -378,13 +378,22 @@ static_assert(sizeof(void *) == (JPH_CPU_ADDRESS_BITS == 64? 8 : 4), "Invalid si
|
|
|
#define JPH_UNUSED(x) (void)x
|
|
|
|
|
|
// Macro to enable floating point precise mode and to disable fused multiply add instructions
|
|
|
-#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
|
|
|
- // In clang it appears you cannot turn off -ffast-math and -ffp-contract=fast for a code block
|
|
|
- // There is #pragma clang fp contract (off) but that doesn't seem to work under clang 9 & 10 when -ffast-math is specified on the commandline (you override it to turn it on, but not off)
|
|
|
- // There is #pragma float_control(precise, on) but that doesn't work under clang 9.
|
|
|
- // So for now we compile clang without -ffast-math so the macros are empty
|
|
|
+#if defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
|
|
|
+ // We compile without -ffast-math and -ffp-contract=fast, so we don't need to disable anything
|
|
|
#define JPH_PRECISE_MATH_ON
|
|
|
#define JPH_PRECISE_MATH_OFF
|
|
|
+#elif defined(JPH_COMPILER_CLANG)
|
|
|
+ // We compile without -ffast-math because it cannot be turned off for a single compilation unit
|
|
|
+ // On clang 14 and later we can turn off float contraction through a pragma, so if FMA is on we can disable it through this macro
|
|
|
+ #if __clang_major__ >= 14 && defined(JPH_USE_FMADD)
|
|
|
+ #define JPH_PRECISE_MATH_ON \
|
|
|
+ _Pragma("clang fp contract(off)")
|
|
|
+ #define JPH_PRECISE_MATH_OFF \
|
|
|
+ _Pragma("clang fp contract(on)")
|
|
|
+ #else
|
|
|
+ #define JPH_PRECISE_MATH_ON
|
|
|
+ #define JPH_PRECISE_MATH_OFF
|
|
|
+ #endif
|
|
|
#elif defined(JPH_COMPILER_MSVC)
|
|
|
// Unfortunately there is no way to push the state of fp_contract, so we have to assume it was turned on before JPH_PRECISE_MATH_ON
|
|
|
#define JPH_PRECISE_MATH_ON \
|