aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-21 09:07:02 -0800
committerChris Robinson <[email protected]>2018-11-21 09:07:02 -0800
commit9f2a77f78801da760df582900ec862fff6438a09 (patch)
tree5a8bdbbf8519aaca1bb92c836b165fad64b60b39 /Alc/helpers.cpp
parent8f43f737ba5f0ed32a37498f6787c34257a3f796 (diff)
Use RAII when handling the mixer's FPU state
Diffstat (limited to 'Alc/helpers.cpp')
-rw-r--r--Alc/helpers.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp
index a78e3d83..658c7d09 100644
--- a/Alc/helpers.cpp
+++ b/Alc/helpers.cpp
@@ -260,13 +260,13 @@ void FillCPUCaps(int capfilter)
}
-void SetMixerFPUMode(FPUCtl *ctl)
+FPUCtl::FPUCtl() noexcept
{
#if defined(__GNUC__) && defined(HAVE_SSE)
if((CPUCapFlags&CPU_CAP_SSE))
{
- __asm__ __volatile__("stmxcsr %0" : "=m" (*&ctl->sse_state));
- unsigned int sseState = ctl->sse_state;
+ __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 */
@@ -275,32 +275,37 @@ void SetMixerFPUMode(FPUCtl *ctl)
#elif defined(HAVE___CONTROL87_2)
- __control87_2(0, 0, &ctl->state, &ctl->sse_state);
+ __control87_2(0, 0, &this->state, &this->sse_state);
_control87(_DN_FLUSH, _MCW_DN);
#elif defined(HAVE__CONTROLFP)
- ctl->state = _controlfp(0, 0);
+ this->state = _controlfp(0, 0);
_controlfp(_DN_FLUSH, _MCW_DN);
#endif
+
+ this->in_mode = true;
}
-void RestoreFPUMode(const FPUCtl *ctl)
+void FPUCtl::leave() noexcept
{
+ if(!this->in_mode) return;
+
#if defined(__GNUC__) && defined(HAVE_SSE)
if((CPUCapFlags&CPU_CAP_SSE))
- __asm__ __volatile__("ldmxcsr %0" : : "m" (*&ctl->sse_state));
+ __asm__ __volatile__("ldmxcsr %0" : : "m" (*&this->sse_state));
#elif defined(HAVE___CONTROL87_2)
unsigned int mode;
- __control87_2(ctl->state, _MCW_DN, &mode, nullptr);
- __control87_2(ctl->sse_state, _MCW_DN, nullptr, &mode);
+ __control87_2(this->state, _MCW_DN, &mode, nullptr);
+ __control87_2(this->sse_state, _MCW_DN, nullptr, &mode);
#elif defined(HAVE__CONTROLFP)
- _controlfp(ctl->state, _MCW_DN);
+ _controlfp(this->state, _MCW_DN);
#endif
+ this->in_mode = false;
}