Jit64: divwx - Special case dividend == 0

Zero divided by any number is still zero. For whatever reason, this case
shows up frequently too.

Before:
B8 00 00 00 00       mov         eax,0
85 F6                test        esi,esi
74 0C                je          overflow
3D 00 00 00 80       cmp         eax,80000000h
75 0C                jne         normal_path
83 FE FF             cmp         esi,0FFFFFFFFh
75 07                jne         normal_path
overflow:
C1 F8 1F             sar         eax,1Fh
8B F8                mov         edi,eax
EB 05                jmp         done
normal_path:
99                   cdq
F7 FE                idiv        eax,esi
8B F8                mov         edi,eax
done:

After:
Nothing!
This commit is contained in:
Sintendo 2021-02-27 20:51:38 +01:00
parent c081e3f2b3
commit c9adc60d73
1 changed files with 62 additions and 45 deletions

View File

@ -1345,6 +1345,22 @@ void Jit64::divwx(UGeckoInstruction inst)
// Constant dividend
const u32 dividend = gpr.Imm32(a);
if (dividend == 0)
{
if (inst.OE)
{
RCOpArg Rb = gpr.Use(b, RCMode::Read);
RegCache::Realize(Rb);
CMP_or_TEST(32, Rb, Imm32(0));
GenerateOverflow(CC_NZ);
}
// Zero divided by anything is always zero
gpr.SetImmediate32(d, 0);
}
else
{
RCX64Reg Rb = gpr.Bind(b, RCMode::Read);
RCX64Reg Rd = gpr.Bind(d, RCMode::Write);
// no register choice
@ -1397,6 +1413,7 @@ void Jit64::divwx(UGeckoInstruction inst)
SetJumpTarget(done);
}
}
else
{
RCOpArg Ra = gpr.Use(a, RCMode::Read);