Separate ALCdevice from the implementation
[openal-soft.git] / core / fpu_ctrl.cpp
blob7a4f147fa30d329e170202b420e3ea33fae20a89
2 #include "config.h"
3 #include "config_simd.h"
5 #include "fpu_ctrl.h"
7 #ifdef HAVE_INTRIN_H
8 #include <intrin.h>
9 #endif
10 #if HAVE_SSE_INTRINSICS
11 #include <emmintrin.h>
12 #elif HAVE_SSE
13 #include <xmmintrin.h>
14 #endif
16 #if HAVE_SSE && !defined(_MM_DENORMALS_ZERO_MASK)
17 /* Some headers seem to be missing these? */
18 #define _MM_DENORMALS_ZERO_MASK 0x0040u
19 #define _MM_DENORMALS_ZERO_ON 0x0040u
20 #endif
22 #if !HAVE_SSE_INTRINSICS && HAVE_SSE
23 #include "cpu_caps.h"
24 #endif
26 namespace {
28 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
29 [[gnu::target("sse")]]
30 #endif
31 [[maybe_unused]]
32 void disable_denormals(unsigned int *state [[maybe_unused]])
34 #if HAVE_SSE_INTRINSICS
35 *state = _mm_getcsr();
36 unsigned int sseState{*state};
37 sseState &= ~(_MM_FLUSH_ZERO_MASK | _MM_DENORMALS_ZERO_MASK);
38 sseState |= _MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON;
39 _mm_setcsr(sseState);
41 #elif HAVE_SSE
43 *state = _mm_getcsr();
44 unsigned int sseState{*state};
45 sseState &= ~_MM_FLUSH_ZERO_MASK;
46 sseState |= _MM_FLUSH_ZERO_ON;
47 if((CPUCapFlags&CPU_CAP_SSE2))
49 sseState &= ~_MM_DENORMALS_ZERO_MASK;
50 sseState |= _MM_DENORMALS_ZERO_ON;
52 _mm_setcsr(sseState);
53 #endif
56 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
57 [[gnu::target("sse")]]
58 #endif
59 [[maybe_unused]]
60 void reset_fpu(unsigned int state [[maybe_unused]])
62 #if HAVE_SSE_INTRINSICS || HAVE_SSE
63 _mm_setcsr(state);
64 #endif
67 } // namespace
70 unsigned int FPUCtl::Set() noexcept
72 unsigned int state{};
73 #if HAVE_SSE_INTRINSICS
74 disable_denormals(&state);
75 #elif HAVE_SSE
76 if((CPUCapFlags&CPU_CAP_SSE))
77 disable_denormals(&state);
78 #endif
79 return state;
82 void FPUCtl::Reset(unsigned int state [[maybe_unused]]) noexcept
84 #if HAVE_SSE_INTRINSICS
85 reset_fpu(state);
86 #elif HAVE_SSE
87 if((CPUCapFlags&CPU_CAP_SSE))
88 reset_fpu(state);
89 #endif