Avoid a stateful unique_ptr deleter
[openal-soft.git] / core / fpu_ctrl.cpp
blobb12f2c967faa7f3384cf0dc915d31ddf502a2267
2 #include "config.h"
4 #include "fpu_ctrl.h"
6 #ifdef HAVE_INTRIN_H
7 #include <intrin.h>
8 #endif
9 #ifdef HAVE_SSE_INTRINSICS
10 #include <xmmintrin.h>
11 #endif
13 #include "cpu_caps.h"
16 void FPUCtl::enter() noexcept
18 if(this->in_mode) return;
20 #if defined(HAVE_SSE_INTRINSICS)
21 this->sse_state = _mm_getcsr();
22 unsigned int sseState{this->sse_state};
23 sseState |= 0x8000; /* set flush-to-zero */
24 sseState |= 0x0040; /* set denormals-are-zero */
25 _mm_setcsr(sseState);
27 #elif defined(__GNUC__) && defined(HAVE_SSE)
29 if((CPUCapFlags&CPU_CAP_SSE))
31 __asm__ __volatile__("stmxcsr %0" : "=m" (*&this->sse_state));
32 unsigned int sseState{this->sse_state};
33 sseState |= 0x8000; /* set flush-to-zero */
34 if((CPUCapFlags&CPU_CAP_SSE2))
35 sseState |= 0x0040; /* set denormals-are-zero */
36 __asm__ __volatile__("ldmxcsr %0" : : "m" (*&sseState));
38 #endif
40 this->in_mode = true;
43 void FPUCtl::leave() noexcept
45 if(!this->in_mode) return;
47 #if defined(HAVE_SSE_INTRINSICS)
48 _mm_setcsr(this->sse_state);
50 #elif defined(__GNUC__) && defined(HAVE_SSE)
52 if((CPUCapFlags&CPU_CAP_SSE))
53 __asm__ __volatile__("ldmxcsr %0" : : "m" (*&this->sse_state));
54 #endif
55 this->in_mode = false;