Skip to content

Commit

Permalink
Merge pull request #6485 from lioncash/flag-unset
Browse files Browse the repository at this point in the history
PowerPC: Properly unset the overflow bit
  • Loading branch information
Helios747 committed Mar 22, 2018
2 parents 23bc507 + e53fffe commit ea82176
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
38 changes: 18 additions & 20 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
Expand Up @@ -492,16 +492,12 @@ void Interpreter::addzex(UGeckoInstruction inst)

void Interpreter::divwx(UGeckoInstruction inst)
{
s32 a = rGPR[inst.RA];
s32 b = rGPR[inst.RB];
const s32 a = rGPR[inst.RA];
const s32 b = rGPR[inst.RB];
const bool overflow = b == 0 || ((u32)a == 0x80000000 && b == -1);

if (b == 0 || ((u32)a == 0x80000000 && b == -1))
if (overflow)
{
if (inst.OE)
{
SetXER_OV(true);
}

if (((u32)a & 0x80000000) && b == 0)
rGPR[inst.RD] = UINT32_MAX;
else
Expand All @@ -512,29 +508,31 @@ void Interpreter::divwx(UGeckoInstruction inst)
rGPR[inst.RD] = (u32)(a / b);
}

if (inst.OE)
SetXER_OV(overflow);

if (inst.Rc)
Helper_UpdateCR0(rGPR[inst.RD]);
}

void Interpreter::divwux(UGeckoInstruction inst)
{
u32 a = rGPR[inst.RA];
u32 b = rGPR[inst.RB];
const u32 a = rGPR[inst.RA];
const u32 b = rGPR[inst.RB];
const bool overflow = b == 0;

if (b == 0)
if (overflow)
{
if (inst.OE)
{
SetXER_OV(true);
}

rGPR[inst.RD] = 0;
}
else
{
rGPR[inst.RD] = a / b;
}

if (inst.OE)
SetXER_OV(overflow);

if (inst.Rc)
Helper_UpdateCR0(rGPR[inst.RD]);
}
Expand Down Expand Up @@ -572,8 +570,8 @@ void Interpreter::mullwx(UGeckoInstruction inst)

rGPR[inst.RD] = static_cast<u32>(result);

if (inst.OE && (result < -0x80000000LL || result > 0x7FFFFFFFLL))
SetXER_OV(true);
if (inst.OE)
SetXER_OV(result < -0x80000000LL || result > 0x7FFFFFFFLL);

if (inst.Rc)
Helper_UpdateCR0(rGPR[inst.RD]);
Expand All @@ -588,8 +586,8 @@ void Interpreter::negx(UGeckoInstruction inst)
if (inst.Rc)
Helper_UpdateCR0(rGPR[inst.RD]);

if (inst.OE && a == 0x80000000)
SetXER_OV(true);
if (inst.OE)
SetXER_OV(a == 0x80000000);
}

void Interpreter::subfx(UGeckoInstruction inst)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/PowerPC.h
Expand Up @@ -434,7 +434,7 @@ inline u32 GetXER_OV()

inline void SetXER_OV(bool value)
{
PowerPC::ppcState.xer_so_ov |= static_cast<u32>(value);
PowerPC::ppcState.xer_so_ov = (PowerPC::ppcState.xer_so_ov & 0xFE) | static_cast<u32>(value);
SetXER_SO(value);
}

Expand Down

0 comments on commit ea82176

Please sign in to comment.