From 0e225a5ad19161618bc22df20f7ccbb140da2406 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Wed, 25 May 2011 18:14:29 +0000 Subject: [PATCH] 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 --- Source/Core/Common/Src/MathUtil.cpp | 141 ++++++++++------------ Source/Core/Common/Src/MathUtil.h | 10 +- Source/Core/Core/Src/PowerPC/PowerPC.cpp | 15 +-- Source/Core/VideoCommon/Src/XFStructs.cpp | 4 +- 4 files changed, 74 insertions(+), 96 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; + } + else + { + // Denormalized number. + return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; } } - u64 mantissa = value.i & 0x000FFFFFFFFFFFFFULL; - if (exp == 0 && mantissa) { - // Denormalized number. - if (sign) { - return 0x18; - } else { - return 0x14; - } - } 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 - } - } - 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 - } + 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; } - - return 0x4; + else + { + u32 mantissa = value.i & FLOAT_FRAC; + if (mantissa) + { + if (exp) + { + return PPC_FPCLASS_QNAN; // Quiet NAN + } + else + { + // Denormalized number. + return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; + } + } + else if (exp) + { + // Infinite + return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF; + } + else + { + //Zero + return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ; + } + } } + } // 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 struct Rectangle diff --git a/Source/Core/Core/Src/PowerPC/PowerPC.cpp b/Source/Core/Core/Src/PowerPC/PowerPC.cpp index 3283c3f8e6..567f3ff98e 100644 --- a/Source/Core/Core/Src/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/Src/PowerPC/PowerPC.cpp @@ -85,13 +85,8 @@ void DoState(PointerWrap &p) void ResetRegisters() { - for (int i = 0; i < 32; i++) - { - ppcState.gpr[i] = 0; - riPS0(i) = 0; - riPS1(i) = 0; - } - + memset(ppcState.ps, 0, sizeof(ppcState.ps)); + memset(ppcState.gpr, 0, sizeof(ppcState.gpr)); memset(ppcState.spr, 0, sizeof(ppcState.spr)); /* 0x00080200 = lonestar 2.0 @@ -114,11 +109,7 @@ void ResetRegisters() ppcState.pc = 0; ppcState.npc = 0; ppcState.Exceptions = 0; - - for (int i = 0; i < 8; i++) - { - ppcState.cr_fast[i] = 0; - } + ((u64*)(&ppcState.cr_fast[0]))[0] = 0; TL = 0; TU = 0; diff --git a/Source/Core/VideoCommon/Src/XFStructs.cpp b/Source/Core/VideoCommon/Src/XFStructs.cpp index 4f91c94151..b4afdf3d6b 100644 --- a/Source/Core/VideoCommon/Src/XFStructs.cpp +++ b/Source/Core/VideoCommon/Src/XFStructs.cpp @@ -251,7 +251,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) } // TODO - verify that it is correct. Seems to work, though. -void LoadIndexedXF(u32 val, int array) +void LoadIndexedXF(u32 val, int refarray) { int index = val >> 16; int address = val & 0xFFF; // check mask @@ -261,5 +261,5 @@ void LoadIndexedXF(u32 val, int array) XFMemWritten(size, address); for (int i = 0; i < size; i++) - xfmem[address + i] = Memory::Read_U32(arraybases[array] + arraystrides[array] * index + i * 4); + xfmem[address + i] = Memory::Read_U32(arraybases[refarray] + arraystrides[refarray] * index + i * 4); }