Jit64: Fix UB/infinite loop when compiling division by 0x80000000

This commit is contained in:
JosJuice 2021-04-26 23:33:52 +02:00
parent 5da85f3a25
commit 7d4b87e7ae
2 changed files with 3 additions and 3 deletions

View File

@ -1480,9 +1480,9 @@ void Jit64::divwx(UGeckoInstruction inst)
if (inst.OE)
GenerateConstantOverflow(false);
}
else if (MathUtil::IsPow2(divisor) || MathUtil::IsPow2(-divisor))
else if (MathUtil::IsPow2(divisor) || MathUtil::IsPow2(-static_cast<s64>(divisor)))
{
u32 abs_val = std::abs(divisor);
const u32 abs_val = static_cast<u32>(std::abs(static_cast<s64>(divisor)));
X64Reg tmp = RSCRATCH;
if (Ra.IsSimpleReg() && Ra.GetSimpleReg() != Rd)

View File

@ -16,7 +16,7 @@ struct Magic
// Calculate the constants required to optimize a signed 32-bit integer division.
// Taken from The PowerPC Compiler Writer's Guide and LLVM.
// Divisor must not be -1, 0, and 1.
// Divisor must not be -1, 0, 1 or INT_MIN.
Magic SignedDivisionConstants(s32 divisor);
} // namespace JitCommon