From fa13457abbf4bf194b4c5b8b0d5ff86fc2862ae7 Mon Sep 17 00:00:00 2001 From: Sintendo <3380580+Sintendo@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:18:09 +0100 Subject: [PATCH] JitArm64_Integer: subfex - Optimize InHostCarry case for -1 The result is either -1 or 0 depending on the state of the carry flag. This can be done with a csetm instruction. Before: 0x1280001a mov w26, #-0x1 ; =-1 0x1a1f035a adc w26, w26, wzr After: 0x5a9f23fa csetm w26, lo --- .../Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 3b6aef8788..ed59599cff 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -1244,8 +1244,18 @@ void JitArm64::subfex(UGeckoInstruction inst) { gpr.BindToRegister(d, false); ARM64Reg RD = gpr.R(d); - MOVI2R(RD, imm); - ADC(RD, RD, ARM64Reg::WZR); + if (is_all_ones) + { + // RD = -1 + carry = carry ? 0 : -1 + // CSETM sets the destination to -1 if the condition is true, 0 + // otherwise. Hence, the condition must be carry clear. + CSETM(RD, CC_CC); + } + else + { + MOVI2R(RD, imm); + ADC(RD, RD, ARM64Reg::WZR); + } break; } case CarryFlag::ConstantTrue: