From b7c3f91643535b760a71de5b1faaae2b91ac7af2 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:11:23 +0100 Subject: [PATCH] JitArm64_Integer: cmpl - Subtract 12-bit constant You can encode a 12-bit immediate in a SUB instruction on ARM64. We can exploit this to avoid materializing the immediate. This approach saves an instruction if it does not need to be materialized in a register afterwards. Otherwise, we just materialize it later and the total number of instructions stays the same. Before: 0x5280003a mov w26, #0x1 ; =1 0xcb1a033b sub x27, x25, x26 After: 0xd100073b sub x27, x25, #0x1 --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 518922343d..ef44a72efd 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -728,9 +728,13 @@ void JitArm64::cmpl(UGeckoInstruction inst) { NEG(CR, EncodeRegTo64(gpr.R(b))); } - else if (gpr.IsImm(b) && !gpr.GetImm(b)) + else if (gpr.IsImm(b) && (gpr.GetImm(b) & 0xFFF) == gpr.GetImm(b)) { - MOV(EncodeRegTo32(CR), gpr.R(a)); + const u32 imm = gpr.GetImm(b); + if (imm == 0) + MOV(EncodeRegTo32(CR), gpr.R(a)); + else + SUB(CR, EncodeRegTo64(gpr.R(a)), imm); } else {