From 67d2fa11f122dfd15f157d59356bcfb69d3acc47 Mon Sep 17 00:00:00 2001 From: Sintendo Date: Sun, 13 Dec 2020 12:36:07 +0100 Subject: [PATCH] Jit64: srawx - Handle constant zero input Shifting zero by any amount always gives zero. Before: 41 B9 00 00 00 00 mov r9d,0 41 8B CF mov ecx,r15d 49 C1 E1 20 shl r9,20h 49 D3 F9 sar r9,cl 49 C1 E9 20 shr r9,20h After: Nothing, register is set to constant zero. Before: 41 B8 00 00 00 00 mov r8d,0 41 8B CF mov ecx,r15d 49 C1 E0 20 shl r8,20h 49 D3 F8 sar r8,cl 41 8B C0 mov eax,r8d 49 C1 E8 20 shr r8,20h 44 85 C0 test eax,r8d 0F 95 45 58 setne byte ptr [rbp+58h] After: C6 45 58 00 mov byte ptr [rbp+58h],0 Occurs a bunch of times in Super Mario Sunshine. Since this is an arithmetic shift a similar optimization can be done for constant -1 (0xFFFFFFFF), but I couldn't find any game where this happens. --- Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index d32d75bb88..1bc4ef5c35 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -1983,6 +1983,11 @@ void Jit64::srawx(UGeckoInstruction inst) FinalizeCarry(CC_NZ); } } + else if (gpr.IsImm(s) && gpr.Imm32(s) == 0) + { + gpr.SetImmediate32(a, 0); + FinalizeCarry(false); + } else { RCX64Reg ecx = gpr.Scratch(ECX); // no register choice