diff options
author | Chris Robinson <[email protected]> | 2020-12-31 16:47:12 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-12-31 16:47:12 -0800 |
commit | 20ef8bf390541339f068676f9d14061fe2f5e115 (patch) | |
tree | 6cca7aa12e11a6b5918fa3748391cb336d8d00bb /core/fpu_ctrl.cpp | |
parent | 002c5062964a598f8cdf53e6b3ed4836629c5048 (diff) |
Move cpu_caps and fpu_ctrl to core
Diffstat (limited to 'core/fpu_ctrl.cpp')
-rw-r--r-- | core/fpu_ctrl.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/core/fpu_ctrl.cpp b/core/fpu_ctrl.cpp new file mode 100644 index 00000000..24021c7d --- /dev/null +++ b/core/fpu_ctrl.cpp @@ -0,0 +1,54 @@ + +#include "config.h" + +#include "fpu_ctrl.h" + +#ifdef HAVE_INTRIN_H +#include <intrin.h> +#endif +#ifdef HAVE_SSE_INTRINSICS +#include <xmmintrin.h> +#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; +} |