From c4f27aaae123af960cbc6419b867d5f58e5a808a Mon Sep 17 00:00:00 2001 From: hrydgard Date: Fri, 19 Dec 2008 22:46:28 +0000 Subject: [PATCH] Avoid GetCR/SetCR in the cr bitwise ops git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1597 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Interpreter_SystemRegisters.cpp | 49 +++---------------- Source/Core/Core/Src/PowerPC/PowerPC.h | 7 +++ 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp index ae1f41fe23..883cf2d2f0 100644 --- a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp +++ b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp @@ -430,75 +430,42 @@ void mtspr(UGeckoInstruction _inst) void crand(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((a & b) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, GetCRBit(_inst.CRBA) & GetCRBit(_inst.CRBB)); } void crandc(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((a & ~b) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, GetCRBit(_inst.CRBA) & (1 ^ GetCRBit(_inst.CRBB))); } - void creqv(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((~(a ^ b)) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, 1 ^ (GetCRBit(_inst.CRBA) ^ GetCRBit(_inst.CRBB))); } void crnand(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((~(a & b)) & 0x80000000) >>_inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, 1 ^ (GetCRBit(_inst.CRBA) & GetCRBit(_inst.CRBB))); } void crnor(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((~(a | b)) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, 1 ^ (GetCRBit(_inst.CRBA) | GetCRBit(_inst.CRBB))); } void cror(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((a | b) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, (GetCRBit(_inst.CRBA) | GetCRBit(_inst.CRBB))); } void crorc(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((a | ~b) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, (GetCRBit(_inst.CRBA) | (1 ^ GetCRBit(_inst.CRBB)))); } void crxor(UGeckoInstruction _inst) { - u32 cr = GetCR(); - u32 a = cr << _inst.CRBA; - u32 b = cr << _inst.CRBB; - u32 d = ((a ^ b) & 0x80000000) >> _inst.CRBD; - SetCR(d | (cr & ~(0x80000000 >> _inst.CRBD))); + SetCRBit(_inst.CRBD, (GetCRBit(_inst.CRBA) ^ GetCRBit(_inst.CRBB))); } void mcrf(UGeckoInstruction _inst) diff --git a/Source/Core/Core/Src/PowerPC/PowerPC.h b/Source/Core/Core/Src/PowerPC/PowerPC.h index 8b709ed232..8240c2bd83 100644 --- a/Source/Core/Core/Src/PowerPC/PowerPC.h +++ b/Source/Core/Core/Src/PowerPC/PowerPC.h @@ -143,6 +143,13 @@ inline u32 GetCRBit(int bit) { return (PowerPC::ppcState.cr_fast[bit >> 2] >> (3 - (bit & 3))) & 1; } +inline void SetCRBit(int bit, int value) { + if (value & 1) + PowerPC::ppcState.cr_fast[bit >> 2] |= 0x8 >> (bit & 3); + else + PowerPC::ppcState.cr_fast[bit >> 2] &= ~(0x8 >> (bit & 3)); +} + // SetCR and GetCR are fairly slow. Should be avoided if possible. inline void SetCR(u32 new_cr) { PowerPC::ppcState.cr = new_cr;