dolphin/Source/Core/Common/x64FPURoundMode.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
C++
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2013-02-26 12:49:00 -07:00
2021-12-09 19:22:16 -07:00
#include "Common/FPURoundMode.h"
#include <cfenv>
#include "Common/CPUDetect.h"
#include "Common/CommonTypes.h"
2015-02-23 12:40:05 -07:00
#include "Common/Intrinsics.h"
2013-02-26 12:49:00 -07:00
namespace FPURoundMode
{
// Get the default SSE states here.
static u32 saved_sse_state = _mm_getcsr();
static const u32 default_sse_state = _mm_getcsr();
2021-07-17 19:55:06 -06:00
void SetSIMDMode(RoundMode rounding_mode, bool non_ieee_mode)
2013-02-26 12:49:00 -07:00
{
// OR-mask for disabling FPU exceptions (bits 7-12 in the MXCSR register)
const u32 EXCEPTION_MASK = 0x1F80;
// Flush-To-Zero (non-IEEE mode: denormal outputs are set to +/- 0)
const u32 FTZ = 0x8000;
// lookup table for FPSCR.RN-to-MXCSR.RC translation
static const u32 simd_rounding_table[] = {
(0 << 13) | EXCEPTION_MASK, // nearest
2015-06-22 18:17:36 -06:00
(3 << 13) | EXCEPTION_MASK, // zero
(2 << 13) | EXCEPTION_MASK, // +inf
2015-06-22 18:17:36 -06:00
(1 << 13) | EXCEPTION_MASK, // -inf
2013-02-26 12:49:00 -07:00
};
u32 csr = simd_rounding_table[rounding_mode];
if (non_ieee_mode)
{
csr |= FTZ;
}
2013-02-26 12:49:00 -07:00
_mm_setcsr(csr);
}
2013-02-26 12:49:00 -07:00
void SaveSIMDState()
{
saved_sse_state = _mm_getcsr();
}
void LoadSIMDState()
{
_mm_setcsr(saved_sse_state);
}
void LoadDefaultSIMDState()
{
_mm_setcsr(default_sse_state);
}
} // namespace FPURoundMode