2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2014-03-28 12:06:12 -06:00
|
|
|
#include <cfenv>
|
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/CPUDetect.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-23 06:57:31 -07:00
|
|
|
#include "Common/FPURoundMode.h"
|
2015-02-23 12:40:05 -07:00
|
|
|
#include "Common/Intrinsics.h"
|
2013-02-26 12:49:00 -07:00
|
|
|
|
|
|
|
namespace FPURoundMode
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
// Get the default SSE states here.
|
|
|
|
static u32 saved_sse_state = _mm_getcsr();
|
|
|
|
static const u32 default_sse_state = _mm_getcsr();
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SetRoundMode(int mode)
|
|
|
|
{
|
|
|
|
// Convert PowerPC to native rounding mode.
|
|
|
|
static const int rounding_mode_lut[] = {FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD};
|
|
|
|
fesetround(rounding_mode_lut[mode]);
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SetPrecisionMode(PrecisionMode /* mode */)
|
|
|
|
{
|
|
|
|
// x64 doesn't need this - fpu is done with SSE
|
|
|
|
}
|
2013-10-24 05:52:22 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SetSIMDMode(int rounding_mode, bool non_ieee_mode)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
(3 << 13) | EXCEPTION_MASK, // zero
|
|
|
|
(2 << 13) | EXCEPTION_MASK, // +inf
|
|
|
|
(1 << 13) | EXCEPTION_MASK, // -inf
|
|
|
|
};
|
|
|
|
u32 csr = simd_rounding_table[rounding_mode];
|
2013-10-24 05:52:22 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
if (non_ieee_mode)
|
|
|
|
{
|
|
|
|
csr |= FTZ;
|
|
|
|
}
|
|
|
|
_mm_setcsr(csr);
|
|
|
|
}
|
2013-03-19 19:51:12 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SaveSIMDState()
|
|
|
|
{
|
|
|
|
saved_sse_state = _mm_getcsr();
|
|
|
|
}
|
|
|
|
void LoadSIMDState()
|
|
|
|
{
|
|
|
|
_mm_setcsr(saved_sse_state);
|
|
|
|
}
|
|
|
|
void LoadDefaultSIMDState()
|
|
|
|
{
|
|
|
|
_mm_setcsr(default_sse_state);
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|