Don't assert for unexpected FX slot IDs
[openal-soft.git] / core / fpu_ctrl.cpp
blob28e60c04281eb64b9421315f2180be7b3e9e3d90
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 <emmintrin.h>
11 #elif defined(HAVE_SSE)
12 #include <xmmintrin.h>
13 #endif
15 #if defined(HAVE_SSE) && !defined(_MM_DENORMALS_ZERO_MASK)
16 /* Some headers seem to be missing these? */
17 #define _MM_DENORMALS_ZERO_MASK 0x0040u
18 #define _MM_DENORMALS_ZERO_ON 0x0040u
19 #endif
21 #include "cpu_caps.h"
23 namespace {
25 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
26 [[gnu::target("sse")]]
27 #endif
28 [[maybe_unused]]
29 void disable_denormals(unsigned int *state [[maybe_unused]])
31 #if defined(HAVE_SSE_INTRINSICS)
32 *state = _mm_getcsr();
33 unsigned int sseState{*state};
34 sseState &= ~(_MM_FLUSH_ZERO_MASK | _MM_DENORMALS_ZERO_MASK);
35 sseState |= _MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON;
36 _mm_setcsr(sseState);
38 #elif defined(HAVE_SSE)
40 *state = _mm_getcsr();
41 unsigned int sseState{*state};
42 sseState &= ~_MM_FLUSH_ZERO_MASK;
43 sseState |= _MM_FLUSH_ZERO_ON;
44 if((CPUCapFlags&CPU_CAP_SSE2))
46 sseState &= ~_MM_DENORMALS_ZERO_MASK;
47 sseState |= _MM_DENORMALS_ZERO_ON;
49 _mm_setcsr(sseState);
50 #endif
53 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
54 [[gnu::target("sse")]]
55 #endif
56 [[maybe_unused]]
57 void reset_fpu(unsigned int state [[maybe_unused]])
59 #if defined(HAVE_SSE_INTRINSICS) || defined(HAVE_SSE)
60 _mm_setcsr(state);
61 #endif
64 } // namespace
67 unsigned int FPUCtl::Set() noexcept
69 unsigned int state{};
70 #if defined(HAVE_SSE_INTRINSICS)
71 disable_denormals(&state);
72 #elif defined(HAVE_SSE)
73 if((CPUCapFlags&CPU_CAP_SSE))
74 disable_denormals(&state);
75 #endif
76 return state;
79 void FPUCtl::Reset(unsigned int state [[maybe_unused]]) noexcept
81 #if defined(HAVE_SSE_INTRINSICS)
82 reset_fpu(state);
83 #elif defined(HAVE_SSE)
84 if((CPUCapFlags&CPU_CAP_SSE))
85 reset_fpu(state);
86 #endif