From 4a29e0e4f45bd1d6c8bfa2fbed22a0ae82cb29a1 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:50:08 +0100 Subject: [PATCH] JitArm64_Integer: cmp - Subtract 12-bit constant You can encode a 12-bit immediate in a SUB instruction on ARM64. Constants in this range do not need to be sign extended, so 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: 0x52800416 mov w22, #0x20 ; =32 0x93407f78 sxtw x24, w27 0xcb36c318 sub x24, x24, w22, sxtw After: 0x93407f78 sxtw x24, w27 0xd1008318 sub x24, x24, #0x20 --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 16cf25fdef..370ad619c5 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -652,9 +652,11 @@ void JitArm64::cmp(UGeckoInstruction inst) SXTW(CR, gpr.R(b)); MVN(CR, CR); } - else if (gpr.IsImm(b) && !gpr.GetImm(b)) + else if (gpr.IsImm(b) && (gpr.GetImm(b) & 0xFFF) == gpr.GetImm(b)) { SXTW(CR, gpr.R(a)); + if (const u32 imm = gpr.GetImm(b); imm != 0) + SUB(CR, CR, imm); } else {