From 45760841b21f96fcedc325c6121b4446a55f5cb7 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 1 Sep 2024 10:13:57 +0200 Subject: [PATCH] Jit: Move divwx to ConstantPropagation --- .../Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 19 +-------------- .../PowerPC/JitArm64/JitArm64_Integer.cpp | 23 +------------------ .../PowerPC/JitCommon/ConstantPropagation.cpp | 9 ++++++++ 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index d73b20bc9e8..458ecdc2e55 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -1433,24 +1433,7 @@ void Jit64::divwx(UGeckoInstruction inst) JITDISABLE(bJITIntegerOff); int a = inst.RA, b = inst.RB, d = inst.RD; - if (gpr.IsImm(a, b)) - { - s32 i = gpr.SImm32(a), j = gpr.SImm32(b); - if (j == 0 || (i == (s32)0x80000000 && j == -1)) - { - const u32 result = i < 0 ? 0xFFFFFFFF : 0x00000000; - gpr.SetImmediate32(d, result); - if (inst.OE) - GenerateConstantOverflow(true); - } - else - { - gpr.SetImmediate32(d, i / j); - if (inst.OE) - GenerateConstantOverflow(false); - } - } - else if (gpr.IsImm(a)) + if (gpr.IsImm(a)) { // Constant dividend const u32 dividend = gpr.Imm32(a); diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 129445fff94..a2b4297738b 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -1625,28 +1625,7 @@ void JitArm64::divwx(UGeckoInstruction inst) int a = inst.RA, b = inst.RB, d = inst.RD; - if (gpr.IsImm(a) && gpr.IsImm(b)) - { - s32 imm_a = gpr.GetImm(a); - s32 imm_b = gpr.GetImm(b); - u32 imm_d; - if (imm_b == 0 || (static_cast(imm_a) == 0x80000000 && imm_b == -1)) - { - if (imm_a < 0) - imm_d = 0xFFFFFFFF; - else - imm_d = 0; - } - else - { - imm_d = static_cast(imm_a / imm_b); - } - gpr.SetImmediate(d, imm_d); - - if (inst.Rc) - ComputeRC0(imm_d); - } - else if (gpr.IsImm(a, 0)) + if (gpr.IsImm(a, 0)) { // Zero divided by anything is always zero gpr.SetImmediate(d, 0); diff --git a/Source/Core/Core/PowerPC/JitCommon/ConstantPropagation.cpp b/Source/Core/Core/PowerPC/JitCommon/ConstantPropagation.cpp index e67e247b43c..4484fd8c329 100644 --- a/Source/Core/Core/PowerPC/JitCommon/ConstantPropagation.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/ConstantPropagation.cpp @@ -269,6 +269,12 @@ ConstantPropagationResult ConstantPropagation::EvaluateTable31AB(UGeckoInstructi case 971: // divwuox d = d_overflow = b == 0 ? 0x1'0000'0000 : u64(a / b); break; + case 491: // divwx + case 1003: // divwox + d = d_overflow = b == 0 || (a == 0x80000000 && b == 0xFFFFFFFF) ? + (s32(a) < 0 ? 0xFFFFFFFF : 0x1'0000'0000) : + s32(a) / s32(b); + break; default: return {}; } @@ -308,6 +314,9 @@ ConstantPropagation::EvaluateTable31ABOneRegisterKnown(UGeckoInstruction inst, u result.overflow = true; return result; } + [[fallthrough]]; + case 491: // divwx + case 1003: // divwox if (!known_reg_is_b && value == 0 && !(flags & FL_SET_OE)) { return ConstantPropagationResult(inst.RD, 0, inst.Rc);