From 7ce7da629e8059a7c819ea26436f4426648d22b5 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Sat, 1 Feb 2025 22:02:43 +0100 Subject: [PATCH] JitArm64_Integer: cmpl - Subtract shifted 12-bit constant You can encode a shifted 12-bit immediate in a SUB instruction on ARM64. We 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: 0x52a00218 mov w24, #0x100000 ; =1048576 0xcb180379 sub x25, x27, x24 After: 0xd1440379 sub x25, x27, #0x100, lsl #12 ; =0x100000 --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index ef44a72efd..58fab5cfea 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -736,6 +736,10 @@ void JitArm64::cmpl(UGeckoInstruction inst) else SUB(CR, EncodeRegTo64(gpr.R(a)), imm); } + else if (gpr.IsImm(b) && (gpr.GetImm(b) & 0xFFF000) == gpr.GetImm(b)) + { + SUB(CR, EncodeRegTo64(gpr.R(a)), gpr.GetImm(b) >> 12, true); + } else { SUB(CR, EncodeRegTo64(gpr.R(a)), EncodeRegTo64(gpr.R(b)));