Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9675 from JosJuice/jit64-div-80000000
Jit64: Fix UB/infinite loop when compiling division by 0x80000000
  • Loading branch information
leoetlino committed Apr 26, 2021
2 parents ac679eb + 7d4b87e commit 51bf2dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/JitCommon/DivUtils.h
Expand Up @@ -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

0 comments on commit 51bf2dc

Please sign in to comment.