Skip to content

Commit

Permalink
Fix aarch64-apple-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Mar 2, 2023
1 parent 0078a10 commit 1e04de1
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions physx/source/foundation/unix/FdUnixFPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
PX_COMPILE_TIME_ASSERT(8 * sizeof(uint32_t) >= sizeof(fenv_t));
#endif

#if PX_OSX && !PX_A64
#if PX_OSX && PX_X64
// osx defines SIMD as standard for floating point operations.
#include <xmmintrin.h>
#endif
Expand All @@ -42,9 +42,13 @@ physx::PxFPUGuard::PxFPUGuard()
#if defined(__CYGWIN__)
#pragma message "FPUGuard::FPUGuard() is not implemented"
#elif PX_OSX
mControlWords[0] = _mm_getcsr();
// set default (disable exceptions: _MM_MASK_MASK) and FTZ (_MM_FLUSH_ZERO_ON), DAZ (_MM_DENORMALS_ZERO_ON: (1<<6))
_mm_setcsr(_MM_MASK_MASK | _MM_FLUSH_ZERO_ON | (1 << 6));
#if PX_X64
mControlWords[0] = _mm_getcsr();
// set default (disable exceptions: _MM_MASK_MASK) and FTZ (_MM_FLUSH_ZERO_ON), DAZ (_MM_DENORMALS_ZERO_ON: (1<<6))
_mm_setcsr(_MM_MASK_MASK | _MM_FLUSH_ZERO_ON | (1 << 6));
#else
// Not supported
#endif
#elif defined(__EMSCRIPTEN__)
// not supported
#else
Expand All @@ -67,9 +71,13 @@ physx::PxFPUGuard::~PxFPUGuard()
#if defined(__CYGWIN__)
#pragma message "PxFPUGuard::~PxFPUGuard() is not implemented"
#elif PX_OSX
// restore control word and clear exception flags
// (setting exception state flags cause exceptions on the first following fp operation)
_mm_setcsr(mControlWords[0] & ~_MM_EXCEPT_MASK);
#if PX_X64
// restore control word and clear exception flags
// (setting exception state flags cause exceptions on the first following fp operation)
_mm_setcsr(mControlWords[0] & ~_MM_EXCEPT_MASK);
#else
// not supported
#endif
#elif defined(__EMSCRIPTEN__)
// not supported
#else
Expand All @@ -82,23 +90,22 @@ PX_FOUNDATION_API void physx::PxEnableFPExceptions()
#if PX_LINUX && !defined(__EMSCRIPTEN__)
feclearexcept(FE_ALL_EXCEPT);
feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
#elif PX_OSX
#elif PX_OSX && PX_X64
// clear any pending exceptions
// (setting exception state flags cause exceptions on the first following fp operation)
uint32_t control = _mm_getcsr() & ~_MM_EXCEPT_MASK;

// enable all fp exceptions except inexact and underflow (common, benign)
// note: denorm has to be disabled as well because underflow can create denorms
_mm_setcsr((control & ~_MM_MASK_MASK) | _MM_MASK_INEXACT | _MM_MASK_UNDERFLOW | _MM_MASK_DENORM);

#endif
}

PX_FOUNDATION_API void physx::PxDisableFPExceptions()
{
#if PX_LINUX && !defined(__EMSCRIPTEN__)
fedisableexcept(FE_ALL_EXCEPT);
#elif PX_OSX
#elif PX_OSX && PX_X64
// clear any pending exceptions
// (setting exception state flags cause exceptions on the first following fp operation)
uint32_t control = _mm_getcsr() & ~_MM_EXCEPT_MASK;
Expand Down

0 comments on commit 1e04de1

Please sign in to comment.