aboutsummaryrefslogtreecommitdiffstats
path: root/alc/fpu_ctrl.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-03-20 15:01:45 -0700
committerChris Robinson <[email protected]>2020-03-20 15:01:45 -0700
commitf56ef433d8bbf8709b559276bea79c6acb8167ef (patch)
tree9c826bbe5b187ce0c8374fb37db3bf13960297cd /alc/fpu_ctrl.cpp
parentad988958767f222625f2560cd628642c948cd736 (diff)
Move the FPUCtl methods to its own source
Diffstat (limited to 'alc/fpu_ctrl.cpp')
-rw-r--r--alc/fpu_ctrl.cpp54
1 files changed, 54 insertions, 0 deletions
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 <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;
+}