diff options
| author | Rodolfo Osvaldo Bogado <rodolfoosvaldobogado@gmail.com> | 2011-05-25 18:14:29 +0000 |
|---|---|---|
| committer | Rodolfo Osvaldo Bogado <rodolfoosvaldobogado@gmail.com> | 2011-05-25 18:14:29 +0000 |
| commit | 0e225a5ad19161618bc22df20f7ccbb140da2406 (patch) | |
| tree | 38d66ed61b3aecb5128ab398755550cddf2a66b5 /Source/Core/Common | |
| parent | a9f7a0c284677611efd2c535f15b5c95f57048c7 (diff) | |
some code cleanup i have left in my folder :)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7560 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Src/MathUtil.cpp | 137 | ||||
| -rw-r--r-- | Source/Core/Common/Src/MathUtil.h | 10 |
2 files changed, 67 insertions, 80 deletions
diff --git a/Source/Core/Common/Src/MathUtil.cpp b/Source/Core/Common/Src/MathUtil.cpp index 4de649a805..e078db2e9d 100644 --- a/Source/Core/Common/Src/MathUtil.cpp +++ b/Source/Core/Common/Src/MathUtil.cpp @@ -31,100 +31,87 @@ static const u32 default_sse_state = _mm_getcsr(); namespace MathUtil { -int ClassifyDouble(double dvalue) +u32 ClassifyDouble(double dvalue) { // TODO: Optimize the below to be as fast as possible. IntDouble value; value.d = dvalue; - // 5 bits (C, <, >, =, ?) - // easy cases first - if (value.i == 0) { - // positive zero - return 0x2; - } else if (value.i == 0x8000000000000000ULL) { - // negative zero - return 0x12; - } else if (value.i == 0x7FF0000000000000ULL) { - // positive inf - return 0x5; - } else if (value.i == 0xFFF0000000000000ULL) { - // negative inf - return 0x9; - } else { - // OK let's dissect this thing. - int sign = value.i >> 63; - int exp = (int)((value.i >> 52) & 0x7FF); - if (exp >= 1 && exp <= 2046) { - // Nice normalized number. - if (sign) { - return 0x8; // negative - } else { - return 0x4; // positive + u64 sign = value.i & DOUBLE_SIGN; + u64 exp = value.i & DOUBLE_EXP; + if (exp > DOUBLE_ZERO && exp < DOUBLE_EXP) + { + // Nice normalized number. + return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN; + } + else + { + u64 mantissa = value.i & DOUBLE_FRAC; + if (mantissa) + { + if (exp) + { + return PPC_FPCLASS_QNAN; } - } - u64 mantissa = value.i & 0x000FFFFFFFFFFFFFULL; - if (exp == 0 && mantissa) { - // Denormalized number. - if (sign) { - return 0x18; - } else { - return 0x14; + else + { + // Denormalized number. + return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; } - } else if (exp == 0x7FF && mantissa /* && mantissa_top*/) { - return 0x11; // Quiet NAN + } + else if (exp) + { + //Infinite + return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF; + } + else + { + //Zero + return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ; } } - - return 0x4; } -int ClassifyFloat(float fvalue) +u32 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 + u32 sign = value.i & FLOAT_SIGN; + u32 exp = value.i & FLOAT_EXP; + if (exp > FLOAT_ZERO && exp < FLOAT_EXP) + { + // Nice normalized number. + return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN; + } + else + { + u32 mantissa = value.i & FLOAT_FRAC; + if (mantissa) + { + if (exp) + { + return PPC_FPCLASS_QNAN; // Quiet NAN } - } - u64 mantissa = value.i & 0x007FFFFF; - if (exp == 0 && mantissa) { - // Denormalized number. - if (sign) { - return 0x18; - } else { - return 0x14; + else + { + // Denormalized number. + return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; } - } else if (exp == 0xFF && mantissa /* && mantissa_top*/) { - return 0x11; // Quiet NAN + } + else if (exp) + { + // Infinite + return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF; + } + else + { + //Zero + return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ; } - } - - return 0x4; + } } + } // namespace void LoadDefaultSSEState() diff --git a/Source/Core/Common/Src/MathUtil.h b/Source/Core/Common/Src/MathUtil.h index d10540d45f..ecace1fb4a 100644 --- a/Source/Core/Common/Src/MathUtil.h +++ b/Source/Core/Common/Src/MathUtil.h @@ -29,12 +29,12 @@ namespace MathUtil static const u64 DOUBLE_SIGN = 0x8000000000000000ULL, DOUBLE_EXP = 0x7FF0000000000000ULL, DOUBLE_FRAC = 0x000FFFFFFFFFFFFFULL, - DOUBLE_ZERO = 0x0000000000000000ULL, + DOUBLE_ZERO = 0x0000000000000000ULL; - FLOAT_SIGN = 0x80000000, +static const u32 FLOAT_SIGN = 0x80000000, FLOAT_EXP = 0x7F800000, FLOAT_FRAC = 0x007FFFFF, - FLOAT_ZERO = 0x00000000ULL; + FLOAT_ZERO = 0x00000000; union IntDouble { double d; @@ -99,9 +99,9 @@ enum PPCFpClass // Uses PowerPC conventions for the return value, so it can be easily // used directly in CPU emulation. -int ClassifyDouble(double dvalue); +u32 ClassifyDouble(double dvalue); // More efficient float version. -int ClassifyFloat(float fvalue); +u32 ClassifyFloat(float fvalue); template<class T> struct Rectangle |
