diff options
| author | hrydgard <hrydgard@gmail.com> | 2009-06-15 21:10:11 +0000 |
|---|---|---|
| committer | hrydgard <hrydgard@gmail.com> | 2009-06-15 21:10:11 +0000 |
| commit | 4dba26777572dcb2992a94f770e65adb6e960fbb (patch) | |
| tree | 739f6e1540b6627755861e3994adbb36106a627a /Source/Core/Common/Src/MathUtil.cpp | |
| parent | dcae21f692b77edf8ffdedc8b2c71535ee5c0117 (diff) | |
Improve accuracy of FPU emulation slightly - still no F-Zero improvements :(
Generic code cleanup.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3458 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common/Src/MathUtil.cpp')
| -rw-r--r-- | Source/Core/Common/Src/MathUtil.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/Source/Core/Common/Src/MathUtil.cpp b/Source/Core/Common/Src/MathUtil.cpp index afd1e3e2cb..8e15cef701 100644 --- a/Source/Core/Common/Src/MathUtil.cpp +++ b/Source/Core/Common/Src/MathUtil.cpp @@ -32,7 +32,7 @@ static const u32 default_sse_state = _mm_getcsr(); namespace MathUtil { -int ClassifyFP(double dvalue) +int ClassifyDouble(double dvalue) { // TODO: Optimize the below to be as fast as possible. IntDouble value; @@ -79,6 +79,53 @@ int ClassifyFP(double dvalue) return 0x4; } +int ClassifyFloat(float fvalue) +{ + // TODO: Optimize the below to be as fast as possible. + IntFloat value; + value.f = fvalue; + // 5 bits (C, <, >, =, ?) + // easy cases first + if (value.i == 0) { + // positive zero + return 0x2; + } else if (value.i == 0x80000000) { + // negative zero + return 0x12; + } else if (value.i == 0x7F800000) { + // positive inf + return 0x5; + } else if (value.i == 0xFF800000) { + // negative inf + return 0x9; + } else { + // OK let's dissect this thing. + int sign = value.i >> 31; + int exp = (int)((value.i >> 23) & 0xFF); + if (exp >= 1 && exp <= 254) { + // Nice normalized number. + if (sign) { + return 0x8; // negative + } else { + return 0x4; // positive + } + } + u64 mantissa = value.i & 0x007FFFFF; + if (exp == 0 && mantissa) { + // Denormalized number. + if (sign) { + return 0x18; + } else { + return 0x14; + } + } else if (exp == 0xFF && mantissa /* && mantissa_top*/) { + return 0x11; // Quiet NAN + } + } + + return 0x4; +} + } // namespace void LoadDefaultSSEState() |
