Merge pull request #455 from jpcima/ftz-asm

Update FTZ assembly to support ARM64
This commit is contained in:
JP Cimalando 2020-09-27 23:40:36 +02:00 committed by GitHub
commit 13a3c9fd61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -18,19 +18,25 @@ ScopedFTZ::ScopedFTZ()
#if SFIZZ_HAVE_SSE #if SFIZZ_HAVE_SSE
unsigned mask = _MM_DENORMALS_ZERO_MASK | _MM_FLUSH_ZERO_MASK; unsigned mask = _MM_DENORMALS_ZERO_MASK | _MM_FLUSH_ZERO_MASK;
registerState = _mm_getcsr(); registerState = _mm_getcsr();
_mm_setcsr((registerState & (~mask)) | mask); _mm_setcsr((static_cast<unsigned>(registerState) & (~mask)) | mask);
#elif SFIZZ_HAVE_NEON #elif SFIZZ_HAVE_NEON && SFIZZ_CPU_FAMILY_ARM
intptr_t mask = (1 << 24); uintptr_t mask = 1u << 24;
asm volatile("vmrs %0, fpscr" : "=r"(registerState)); asm volatile("vmrs %0, fpscr" : "=r"(registerState));
asm volatile("vmsr fpscr, %0" : : "ri"((registerState & (~mask)) | mask)); asm volatile("vmsr fpscr, %0" : : "r"((registerState & (~mask)) | mask));
#elif SFIZZ_HAVE_NEON && SFIZZ_CPU_FAMILY_AARCH64
uintptr_t mask = 1u << 24;
asm volatile("mrs %0, fpcr" : "=r"(registerState));
asm volatile("msr fpcr, %0" : : "r"((registerState & (~mask)) | mask));
#endif #endif
} }
ScopedFTZ::~ScopedFTZ() ScopedFTZ::~ScopedFTZ()
{ {
#if SFIZZ_HAVE_SSE #if SFIZZ_HAVE_SSE
_mm_setcsr(registerState); _mm_setcsr(static_cast<unsigned>(registerState));
#elif SFIZZ_HAVE_NEON #elif SFIZZ_HAVE_NEON && SFIZZ_CPU_FAMILY_ARM
asm volatile("vmrs %0, fpscr" : : "ri"(registerState)); asm volatile("vmrs %0, fpscr" : : "r"(registerState));
#elif SFIZZ_HAVE_NEON && SFIZZ_CPU_FAMILY_AARCH64
asm volatile("mrs %0, fpcr" : : "r"(registerState));
#endif #endif
} }

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once #pragma once
#include <cstdint>
/** /**
* @brief Flush floating points to zero and disable denormals as an RAII helper. * @brief Flush floating points to zero and disable denormals as an RAII helper.
@ -16,5 +17,5 @@ public:
ScopedFTZ(); ScopedFTZ();
~ScopedFTZ(); ~ScopedFTZ();
private: private:
unsigned registerState; uintptr_t registerState;
}; };