From a4110ad95894cb43e3d69c8570c6f42e2eeb669f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Aug 2018 17:14:38 -0400 Subject: [PATCH] PowerPC: Deduplicate Helper_Mask() code We can share this across all implementations instead of duplicating it in different ways. --- Source/Core/Core/PowerPC/Gekko.h | 17 +++++++++++++++ .../Core/PowerPC/Interpreter/Interpreter.h | 3 --- .../Interpreter/Interpreter_Integer.cpp | 21 +++---------------- .../Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 16 +++++++------- .../PowerPC/JitArm64/JitArm64_Integer.cpp | 10 ++++----- .../Core/Core/PowerPC/JitCommon/JitBase.cpp | 6 ------ Source/Core/Core/PowerPC/JitCommon/JitBase.h | 3 --- 7 files changed, 33 insertions(+), 43 deletions(-) diff --git a/Source/Core/Core/PowerPC/Gekko.h b/Source/Core/Core/PowerPC/Gekko.h index fda28b1fbc..b11a7565f0 100644 --- a/Source/Core/Core/PowerPC/Gekko.h +++ b/Source/Core/Core/PowerPC/Gekko.h @@ -294,6 +294,23 @@ union UGeckoInstruction }; }; +// Used in implementations of rlwimi, rlwinm, and rlwnm +inline u32 MakeRotationMask(u32 mb, u32 me) +{ + // first make 001111111111111 part + const u32 begin = 0xFFFFFFFF >> mb; + // then make 000000000001111 part, which is used to flip the bits of the first one + const u32 end = 0x7FFFFFFF >> me; + // do the bitflip + const u32 mask = begin ^ end; + + // and invert if backwards + if (me < mb) + return ~mask; + + return mask; +} + // // --- Gekko Special Registers --- // diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h index b1ea851041..8c76b6de6f 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h @@ -299,9 +299,6 @@ private: static void Helper_Dequantize(u32 addr, u32 instI, u32 instRD, u32 instW); static void Helper_Quantize(u32 addr, u32 instI, u32 instRS, u32 instW); - // other helper - static u32 Helper_Mask(int mb, int me); - static void Helper_FloatCompareOrdered(UGeckoInstruction inst, double a, double b); static void Helper_FloatCompareUnordered(UGeckoInstruction inst, double a, double b); diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp index 5b5d4450a6..d851e451fe 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp @@ -23,21 +23,6 @@ u32 Interpreter::Helper_Carry(u32 value1, u32 value2) return value2 > (~value1); } -u32 Interpreter::Helper_Mask(int mb, int me) -{ - // first make 001111111111111 part - u32 begin = 0xFFFFFFFF >> mb; - // then make 000000000001111 part, which is used to flip the bits of the first one - u32 end = 0x7FFFFFFF >> me; - // do the bitflip - u32 mask = begin ^ end; - // and invert if backwards - if (me < mb) - return ~mask; - else - return mask; -} - void Interpreter::addi(UGeckoInstruction inst) { if (inst.RA) @@ -170,7 +155,7 @@ void Interpreter::xoris(UGeckoInstruction inst) void Interpreter::rlwimix(UGeckoInstruction inst) { - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); rGPR[inst.RA] = (rGPR[inst.RA] & ~mask) | (Common::RotateLeft(rGPR[inst.RS], inst.SH) & mask); if (inst.Rc) @@ -179,7 +164,7 @@ void Interpreter::rlwimix(UGeckoInstruction inst) void Interpreter::rlwinmx(UGeckoInstruction inst) { - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); rGPR[inst.RA] = Common::RotateLeft(rGPR[inst.RS], inst.SH) & mask; if (inst.Rc) @@ -188,7 +173,7 @@ void Interpreter::rlwinmx(UGeckoInstruction inst) void Interpreter::rlwnmx(UGeckoInstruction inst) { - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); rGPR[inst.RA] = Common::RotateLeft(rGPR[inst.RS], rGPR[inst.RB] & 0x1F) & mask; if (inst.Rc) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index 4eb13c9344..f91443996b 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -1437,17 +1437,17 @@ void Jit64::rlwinmx(UGeckoInstruction inst) u32 result = gpr.R(s).Imm32(); if (inst.SH != 0) result = Common::RotateLeft(result, inst.SH); - result &= Helper_Mask(inst.MB, inst.ME); + result &= MakeRotationMask(inst.MB, inst.ME); gpr.SetImmediate32(a, result); if (inst.Rc) ComputeRC(gpr.R(a)); } else { - bool left_shift = inst.SH && inst.MB == 0 && inst.ME == 31 - inst.SH; - bool right_shift = inst.SH && inst.ME == 31 && inst.MB == 32 - inst.SH; - u32 mask = Helper_Mask(inst.MB, inst.ME); - bool simple_mask = mask == 0xff || mask == 0xffff; + const bool left_shift = inst.SH && inst.MB == 0 && inst.ME == 31 - inst.SH; + const bool right_shift = inst.SH && inst.ME == 31 && inst.MB == 32 - inst.SH; + const u32 mask = MakeRotationMask(inst.MB, inst.ME); + const bool simple_mask = mask == 0xff || mask == 0xffff; // In case of a merged branch, track whether or not we've set flags. // If not, we need to do a test later to get them. bool needs_test = true; @@ -1520,7 +1520,7 @@ void Jit64::rlwimix(UGeckoInstruction inst) if (gpr.R(a).IsImm() && gpr.R(s).IsImm()) { - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); gpr.SetImmediate32(a, (gpr.R(a).Imm32() & ~mask) | (Common::RotateLeft(gpr.R(s).Imm32(), inst.SH) & mask)); if (inst.Rc) @@ -1529,7 +1529,7 @@ void Jit64::rlwimix(UGeckoInstruction inst) else { gpr.Lock(a, s); - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); bool needs_test = false; if (mask == 0 || (a == s && inst.SH == 0)) { @@ -1619,7 +1619,7 @@ void Jit64::rlwnmx(UGeckoInstruction inst) JITDISABLE(bJITIntegerOff); int a = inst.RA, b = inst.RB, s = inst.RS; - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.R(b).IsImm() && gpr.R(s).IsImm()) { gpr.SetImmediate32(a, Common::RotateLeft(gpr.R(s).Imm32(), gpr.R(b).Imm32() & 0x1F) & mask); diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index c1fa56a4a1..ad14b8148a 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -532,7 +532,7 @@ void JitArm64::rlwinmx(UGeckoInstruction inst) JITDISABLE(bJITIntegerOff); u32 a = inst.RA, s = inst.RS; - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.IsImm(inst.RS)) { gpr.SetImmediate(a, Common::RotateLeft(gpr.GetImm(s), inst.SH) & mask); @@ -579,8 +579,8 @@ void JitArm64::rlwnmx(UGeckoInstruction inst) { INSTRUCTION_START JITDISABLE(bJITIntegerOff); - u32 a = inst.RA, b = inst.RB, s = inst.RS; - u32 mask = Helper_Mask(inst.MB, inst.ME); + const u32 a = inst.RA, b = inst.RB, s = inst.RS; + const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.IsImm(b) && gpr.IsImm(s)) { @@ -1431,8 +1431,8 @@ void JitArm64::rlwimix(UGeckoInstruction inst) INSTRUCTION_START JITDISABLE(bJITIntegerOff); - int a = inst.RA, s = inst.RS; - u32 mask = Helper_Mask(inst.MB, inst.ME); + const int a = inst.RA, s = inst.RS; + const u32 mask = MakeRotationMask(inst.MB, inst.ME); if (gpr.IsImm(a) && gpr.IsImm(s)) { diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp index 606d0d3af0..1639b0313b 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp @@ -22,12 +22,6 @@ void JitTrampoline(JitBase& jit, u32 em_address) jit.Jit(em_address); } -u32 Helper_Mask(u8 mb, u8 me) -{ - u32 mask = ((u32)-1 >> mb) ^ (me >= 31 ? 0 : (u32)-1 >> (me + 1)); - return mb > me ? ~mask : mask; -} - JitBase::JitBase() : m_code_buffer(code_buffer_size) { } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.h b/Source/Core/Core/PowerPC/JitCommon/JitBase.h index 47c98d1f73..db906dd995 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.h @@ -131,6 +131,3 @@ public: }; void JitTrampoline(JitBase& jit, u32 em_address); - -// Merged routines that should be moved somewhere better -u32 Helper_Mask(u8 mb, u8 me);