From 01eed0a7585fbd3031e850ee8f14778e9e46a0e4 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:02:10 +0100 Subject: [PATCH] JitArm64_Integer: cmp - Add 12-bit constant You can encode a 12-bit immediate in an ADD instruction on ARM64. If the negated constant fits in this range, 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: 0x12800019 mov w25, #-0x1 ; =-1 0x93407f5b sxtw x27, w26 0xcb39c37b sub x27, x27, w25, sxtw After: 0x93407f5b sxtw x27, w26 0x9100077b add x27, x27, #0x1 --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 3a56e58b84..2175f9a219 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -663,6 +663,11 @@ void JitArm64::cmp(UGeckoInstruction inst) SXTW(CR, gpr.R(a)); SUB(CR, CR, gpr.GetImm(b) >> 12, true); } + else if (gpr.IsImm(b) && (((~gpr.GetImm(b) + 1) & 0xFFF) == (~gpr.GetImm(b) + 1))) + { + SXTW(CR, gpr.R(a)); + ADD(CR, CR, ~gpr.GetImm(b) + 1); + } else { ARM64Reg RA = gpr.R(a);