From 8304ae33613c197ae377ed246d705f0b2a398e38 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:13:30 +0200 Subject: [PATCH 1/3] JitArm64_RegCache: Add IsImm helper Because checking if a register is a specific immediate is a rather common operation. --- Source/Core/Core/PowerPC/JitArm64/JitArm64_RegCache.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_RegCache.h b/Source/Core/Core/PowerPC/JitArm64/JitArm64_RegCache.h index 9ea4e0e3b6..bfc9f32a54 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_RegCache.h +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_RegCache.h @@ -286,6 +286,8 @@ public: // Gets the immediate that a register is set to. Only valid for guest GPRs. u32 GetImm(size_t preg) const { return GetGuestGPROpArg(preg).GetImm(); } + bool IsImm(size_t preg, u32 imm) { return IsImm(preg) && GetImm(preg) == imm; } + // Binds a guest GPR to a host register, optionally loading its value. // // preg: The guest register index. From 0d9984b299ece57b5fec22d5d45d55d8f3f6554e Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:16:25 +0200 Subject: [PATCH 2/3] JitArm64_SystemRegisters: Optimize mtspr No need to materialize the immediate if it is zero, we can just use WZR. Before: mov w27, #0x0 ; =0 str w27, [x29, #0x1178] After: str wzr, [x29, #0x1178] --- Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp index 87f652d6d4..8ffa1b84aa 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp @@ -477,7 +477,7 @@ void JitArm64::mtspr(UGeckoInstruction inst) } // OK, this is easy. - ARM64Reg RD = gpr.R(inst.RD); + ARM64Reg RD = gpr.IsImm(inst.RD, 0) ? ARM64Reg::WZR : gpr.R(inst.RD); STR(IndexType::Unsigned, RD, PPC_REG, PPCSTATE_OFF_SPR(iIndex)); } From a9a779a6b9a9843c456d208575c7749e89a33429 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:21:31 +0200 Subject: [PATCH 3/3] JitArm64_Integer: Use IsImm helper more --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index f3d263379c..63ccff4c47 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -649,7 +649,7 @@ void JitArm64::cmp(UGeckoInstruction inst) SXTW(CR, gpr.R(b)); NEG(CR, CR); } - else if (gpr.IsImm(a) && gpr.GetImm(a) == 0xFFFFFFFF) + else if (gpr.IsImm(a, 0xFFFFFFFF)) { SXTW(CR, gpr.R(b)); MVN(CR, CR); @@ -1640,7 +1640,7 @@ void JitArm64::divwx(UGeckoInstruction inst) if (inst.Rc) ComputeRC0(imm_d); } - else if (gpr.IsImm(a) && gpr.GetImm(a) == 0) + else if (gpr.IsImm(a, 0)) { // Zero divided by anything is always zero gpr.SetImmediate(d, 0); @@ -1829,7 +1829,7 @@ void JitArm64::slwx(UGeckoInstruction inst) if (inst.Rc) ComputeRC0(gpr.GetImm(a)); } - else if (gpr.IsImm(s) && gpr.GetImm(s) == 0) + else if (gpr.IsImm(s, 0)) { gpr.SetImmediate(a, 0); if (inst.Rc) @@ -1934,7 +1934,7 @@ void JitArm64::srawx(UGeckoInstruction inst) ComputeRC0(gpr.GetImm(a)); return; } - else if (gpr.IsImm(s) && gpr.GetImm(s) == 0) + else if (gpr.IsImm(s, 0)) { gpr.SetImmediate(a, 0); ComputeCarry(false);