From f18f6cd0a214ca661dacfacc3f1402c6a7450dc5 Mon Sep 17 00:00:00 2001 From: Sintendo Date: Tue, 2 Nov 2021 00:39:02 +0100 Subject: [PATCH 1/2] Jit64: divwx - Improve comments --- Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index 7cc7723b76..d34b432db9 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -1496,15 +1496,18 @@ void Jit64::divwx(UGeckoInstruction inst) X64Reg tmp = RSCRATCH; if (!Ra.IsSimpleReg()) { + // Load dividend from memory MOV(32, R(tmp), Ra); MOV(32, Rd, R(tmp)); } else if (d == a) { + // Make a copy of the dividend MOV(32, R(tmp), Ra); } else { + // Copy dividend directly into destination MOV(32, Rd, Ra); tmp = Ra.GetSimpleReg(); } @@ -1538,11 +1541,11 @@ void Jit64::divwx(UGeckoInstruction inst) else if (d == a) { // Rd holds the dividend, while RSCRATCH holds the sum - // This is opposite of the other cases + // This is the reverse of the other cases dividend = Rd; sum = RSCRATCH; src = RSCRATCH; - // Negate condition to compensate the swapped values + // Negate condition to compensate for the swapped values cond = CC_S; } else From dfb32040bf2550a6592621544e306fad9c4f1dcb Mon Sep 17 00:00:00 2001 From: Sintendo Date: Tue, 2 Nov 2021 23:52:21 +0100 Subject: [PATCH 2/2] Jit64: divwx - Micro-optimize division by 2 Prefer using eax to isolate the sign bit. This saves a byte when the destination ends up as r8-15, because those require a REX prefix. Before: 41 8B C5 mov eax,r13d 41 C1 ED 1F shr r13d,1Fh 44 03 E8 add r13d,eax 41 D1 FD sar r13d,1 After: 41 8B C5 mov eax,r13d C1 E8 1F shr eax,1Fh 44 03 E8 add r13d,eax 41 D1 FD sar r13d,1 --- Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index d34b432db9..13e654eab5 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -1494,6 +1494,8 @@ void Jit64::divwx(UGeckoInstruction inst) else if (divisor == 2 || divisor == -2) { X64Reg tmp = RSCRATCH; + X64Reg sign = tmp; + if (!Ra.IsSimpleReg()) { // Load dividend from memory @@ -1510,9 +1512,10 @@ void Jit64::divwx(UGeckoInstruction inst) // Copy dividend directly into destination MOV(32, Rd, Ra); tmp = Ra.GetSimpleReg(); + sign = Rd; } - SHR(32, Rd, Imm8(31)); + SHR(32, R(sign), Imm8(31)); ADD(32, Rd, R(tmp)); SAR(32, Rd, Imm8(1));