commit
a1374dd4ba
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <cfenv>
|
||||||
|
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "Common/CPUDetect.h"
|
#include "Common/CPUDetect.h"
|
||||||
#include "Common/FPURoundMode.h"
|
#include "Common/FPURoundMode.h"
|
||||||
|
@ -20,41 +22,18 @@ namespace FPURoundMode
|
||||||
|
|
||||||
void SetRoundMode(int mode)
|
void SetRoundMode(int mode)
|
||||||
{
|
{
|
||||||
// Set FPU rounding mode to mimic the PowerPC's
|
// Convert PowerPC to native rounding mode.
|
||||||
#ifdef _M_X86_32
|
const int rounding_mode_lut[] = {
|
||||||
// This shouldn't really be needed anymore since we use SSE
|
FE_TONEAREST,
|
||||||
#ifdef _WIN32
|
FE_TOWARDZERO,
|
||||||
const int table[4] =
|
FE_UPWARD,
|
||||||
{
|
FE_DOWNWARD
|
||||||
_RC_NEAR,
|
};
|
||||||
_RC_CHOP,
|
fesetround(rounding_mode_lut[mode]);
|
||||||
_RC_UP,
|
|
||||||
_RC_DOWN
|
|
||||||
};
|
|
||||||
_set_controlfp(_MCW_RC, table[mode]);
|
|
||||||
#else
|
|
||||||
const unsigned short X87_ROUND_MASK = 3 << 10;
|
|
||||||
const unsigned short x87_rounding_table[] =
|
|
||||||
{
|
|
||||||
0 << 10, // nearest
|
|
||||||
3 << 10, // zero
|
|
||||||
2 << 10, // +inf
|
|
||||||
1 << 10, // -inf
|
|
||||||
};
|
|
||||||
unsigned short _mode;
|
|
||||||
asm ("fstcw %0" : "=m" (_mode));
|
|
||||||
_mode = (_mode & ~X87_ROUND_MASK) | x87_rounding_table[mode];
|
|
||||||
asm ("fldcw %0" : : "m" (_mode));
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPrecisionMode(PrecisionMode mode)
|
void SetPrecisionMode(PrecisionMode mode)
|
||||||
{
|
{
|
||||||
#ifdef _M_X86_32
|
|
||||||
// sets the floating-point lib to 53-bit
|
|
||||||
// PowerPC has a 53bit floating pipeline only
|
|
||||||
// eg: sscanf is very sensitive
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_control87(_PC_53, MCW_PC);
|
_control87(_PC_53, MCW_PC);
|
||||||
#else
|
#else
|
||||||
|
@ -64,14 +43,10 @@ namespace FPURoundMode
|
||||||
2 << 8, // 53 bits
|
2 << 8, // 53 bits
|
||||||
3 << 8, // 64 bits
|
3 << 8, // 64 bits
|
||||||
};
|
};
|
||||||
unsigned short _mode;
|
unsigned short cw;
|
||||||
asm ("fstcw %0" : "=m" (_mode));
|
asm ("fnstcw %0" : "=m" (cw));
|
||||||
_mode = (_mode & ~PRECISION_MASK) | precision_table[mode];
|
cw = (cw & ~PRECISION_MASK) | precision_table[mode];
|
||||||
asm ("fldcw %0" : : "m" (_mode));
|
asm ("fldcw %0" : : "m" (cw));
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
//x64 doesn't need this - fpu is done with SSE
|
|
||||||
//but still - set any useful sse options here
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue