From f56ef433d8bbf8709b559276bea79c6acb8167ef Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 20 Mar 2020 15:01:45 -0700 Subject: Move the FPUCtl methods to its own source --- alc/alc.cpp | 2 +- alc/alu.cpp | 2 +- alc/converter.cpp | 2 +- alc/fpu_ctrl.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ alc/fpu_ctrl.h | 25 +++++++++++++++++++++++++ alc/fpu_modes.h | 25 ------------------------- alc/helpers.cpp | 45 --------------------------------------------- 7 files changed, 82 insertions(+), 73 deletions(-) create mode 100644 alc/fpu_ctrl.cpp create mode 100644 alc/fpu_ctrl.h delete mode 100644 alc/fpu_modes.h (limited to 'alc') diff --git a/alc/alc.cpp b/alc/alc.cpp index 0962276d..9ce1fa65 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -79,7 +79,7 @@ #include "effects/base.h" #include "filters/nfc.h" #include "filters/splitter.h" -#include "fpu_modes.h" +#include "fpu_ctrl.h" #include "hrtf.h" #include "inprogext.h" #include "intrusive_ptr.h" diff --git a/alc/alu.cpp b/alc/alu.cpp index ae65fbcb..d3a0a858 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -65,7 +65,7 @@ #include "filters/biquad.h" #include "filters/nfc.h" #include "filters/splitter.h" -#include "fpu_modes.h" +#include "fpu_ctrl.h" #include "hrtf.h" #include "inprogext.h" #include "mastering.h" diff --git a/alc/converter.cpp b/alc/converter.cpp index 553bad58..38b8bedb 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -11,7 +11,7 @@ #include "albyte.h" #include "alu.h" -#include "fpu_modes.h" +#include "fpu_ctrl.h" #include "mixer/defs.h" diff --git a/alc/fpu_ctrl.cpp b/alc/fpu_ctrl.cpp new file mode 100644 index 00000000..24021c7d --- /dev/null +++ b/alc/fpu_ctrl.cpp @@ -0,0 +1,54 @@ + +#include "config.h" + +#include "fpu_ctrl.h" + +#ifdef HAVE_INTRIN_H +#include +#endif +#ifdef HAVE_SSE_INTRINSICS +#include +#endif + +#include "cpu_caps.h" + + +FPUCtl::FPUCtl() +{ +#if defined(HAVE_SSE_INTRINSICS) + this->sse_state = _mm_getcsr(); + unsigned int sseState = this->sse_state; + sseState |= 0x8000; /* set flush-to-zero */ + sseState |= 0x0040; /* set denormals-are-zero */ + _mm_setcsr(sseState); + +#elif defined(__GNUC__) && defined(HAVE_SSE) + + if((CPUCapFlags&CPU_CAP_SSE)) + { + __asm__ __volatile__("stmxcsr %0" : "=m" (*&this->sse_state)); + unsigned int sseState = this->sse_state; + sseState |= 0x8000; /* set flush-to-zero */ + if((CPUCapFlags&CPU_CAP_SSE2)) + sseState |= 0x0040; /* set denormals-are-zero */ + __asm__ __volatile__("ldmxcsr %0" : : "m" (*&sseState)); + } +#endif + + this->in_mode = true; +} + +void FPUCtl::leave() +{ + if(!this->in_mode) return; + +#if defined(HAVE_SSE_INTRINSICS) + _mm_setcsr(this->sse_state); + +#elif defined(__GNUC__) && defined(HAVE_SSE) + + if((CPUCapFlags&CPU_CAP_SSE)) + __asm__ __volatile__("ldmxcsr %0" : : "m" (*&this->sse_state)); +#endif + this->in_mode = false; +} diff --git a/alc/fpu_ctrl.h b/alc/fpu_ctrl.h new file mode 100644 index 00000000..e89bdc29 --- /dev/null +++ b/alc/fpu_ctrl.h @@ -0,0 +1,25 @@ +#ifndef FPU_CTRL_H +#define FPU_CTRL_H + +class FPUCtl { +#if defined(HAVE_SSE_INTRINSICS) || (defined(__GNUC__) && defined(HAVE_SSE)) + unsigned int sse_state{}; +#endif + bool in_mode{}; + +public: + FPUCtl(); + /* HACK: 32-bit targets for GCC seem to have a problem here with certain + * noexcept methods (which destructors are) causing an internal compiler + * error. No idea why it's these methods specifically, but this is needed + * to get it to compile. + */ + ~FPUCtl() noexcept(false) { leave(); } + + FPUCtl(const FPUCtl&) = delete; + FPUCtl& operator=(const FPUCtl&) = delete; + + void leave(); +}; + +#endif /* FPU_CTRL_H */ diff --git a/alc/fpu_modes.h b/alc/fpu_modes.h deleted file mode 100644 index 5465e9cf..00000000 --- a/alc/fpu_modes.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef FPU_MODES_H -#define FPU_MODES_H - -class FPUCtl { -#if defined(HAVE_SSE_INTRINSICS) || (defined(__GNUC__) && defined(HAVE_SSE)) - unsigned int sse_state{}; -#endif - bool in_mode{}; - -public: - FPUCtl(); - /* HACK: 32-bit targets for GCC seem to have a problem here with certain - * noexcept methods (which destructors are) causing an internal compiler - * error. No idea why it's these methods specifically, but this is needed - * to get it to compile. - */ - ~FPUCtl() noexcept(false) { leave(); } - - FPUCtl(const FPUCtl&) = delete; - FPUCtl& operator=(const FPUCtl&) = delete; - - void leave(); -}; - -#endif /* FPU_MODES_H */ diff --git a/alc/helpers.cpp b/alc/helpers.cpp index 4ea94c7d..5006bc51 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -46,9 +46,6 @@ #ifdef HAVE_CPUID_H #include #endif -#ifdef HAVE_SSE_INTRINSICS -#include -#endif #ifdef HAVE_SYS_SYSCONF_H #include #endif @@ -75,7 +72,6 @@ #include "alstring.h" #include "compat.h" #include "cpu_caps.h" -#include "fpu_modes.h" #include "logging.h" #include "strutils.h" #include "vector.h" @@ -207,47 +203,6 @@ void FillCPUCaps(int capfilter) } -FPUCtl::FPUCtl() -{ -#if defined(HAVE_SSE_INTRINSICS) - this->sse_state = _mm_getcsr(); - unsigned int sseState = this->sse_state; - sseState |= 0x8000; /* set flush-to-zero */ - sseState |= 0x0040; /* set denormals-are-zero */ - _mm_setcsr(sseState); - -#elif defined(__GNUC__) && defined(HAVE_SSE) - - if((CPUCapFlags&CPU_CAP_SSE)) - { - __asm__ __volatile__("stmxcsr %0" : "=m" (*&this->sse_state)); - unsigned int sseState = this->sse_state; - sseState |= 0x8000; /* set flush-to-zero */ - if((CPUCapFlags&CPU_CAP_SSE2)) - sseState |= 0x0040; /* set denormals-are-zero */ - __asm__ __volatile__("ldmxcsr %0" : : "m" (*&sseState)); - } -#endif - - this->in_mode = true; -} - -void FPUCtl::leave() -{ - if(!this->in_mode) return; - -#if defined(HAVE_SSE_INTRINSICS) - _mm_setcsr(this->sse_state); - -#elif defined(__GNUC__) && defined(HAVE_SSE) - - if((CPUCapFlags&CPU_CAP_SSE)) - __asm__ __volatile__("ldmxcsr %0" : : "m" (*&this->sse_state)); -#endif - this->in_mode = false; -} - - #ifdef _WIN32 const PathNamePair &GetProcBinary() -- cgit v1.2.3