summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorMarkus Wick <degasus@users.noreply.github.com>2018-03-22 14:15:58 +0100
committerGitHub <noreply@github.com>2018-03-22 14:15:58 +0100
commit59c5bc964f29a297af129fbefcb2b73df04adda4 (patch)
tree8769ba57e03cd0d6c394a1a592b0da19025a5b7b /Source
parent2e92d95888f90c14f5f91b1b12525ae019e85edb (diff)
parent9d214254493c2525579c81952aa50dffa33be81a (diff)
Merge pull request #6486 from lioncash/add-oe
Interpreter_Integer: Handle overflow flag when OE bit is set in add, addc, adde, addme, and addze
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp68
1 files changed, 44 insertions, 24 deletions
diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
index 7367e85fdc..09db4c35da 100644
--- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
+++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
@@ -422,72 +422,92 @@ void Interpreter::xorx(UGeckoInstruction inst)
Helper_UpdateCR0(rGPR[inst.RA]);
}
+static bool HasAddOverflowed(u32 x, u32 y, u32 result)
+{
+ // If x and y have the same sign, but the result is different
+ // then an overflow has occurred.
+ return (((x ^ result) & (y ^ result)) >> 31) != 0;
+}
+
void Interpreter::addx(UGeckoInstruction inst)
{
- rGPR[inst.RD] = rGPR[inst.RA] + rGPR[inst.RB];
+ const u32 a = rGPR[inst.RA];
+ const u32 b = rGPR[inst.RB];
+ const u32 result = a + b;
+
+ rGPR[inst.RD] = result;
if (inst.OE)
- PanicAlert("OE: addx");
+ SetXER_OV(HasAddOverflowed(a, b, result));
if (inst.Rc)
- Helper_UpdateCR0(rGPR[inst.RD]);
+ Helper_UpdateCR0(result);
}
void Interpreter::addcx(UGeckoInstruction inst)
{
- u32 a = rGPR[inst.RA];
- u32 b = rGPR[inst.RB];
- rGPR[inst.RD] = a + b;
+ const u32 a = rGPR[inst.RA];
+ const u32 b = rGPR[inst.RB];
+ const u32 result = a + b;
+
+ rGPR[inst.RD] = result;
SetCarry(Helper_Carry(a, b));
if (inst.OE)
- PanicAlert("OE: addcx");
+ SetXER_OV(HasAddOverflowed(a, b, result));
if (inst.Rc)
- Helper_UpdateCR0(rGPR[inst.RD]);
+ Helper_UpdateCR0(result);
}
void Interpreter::addex(UGeckoInstruction inst)
{
- int carry = GetCarry();
- int a = rGPR[inst.RA];
- int b = rGPR[inst.RB];
- rGPR[inst.RD] = a + b + carry;
+ const u32 carry = GetCarry();
+ const u32 a = rGPR[inst.RA];
+ const u32 b = rGPR[inst.RB];
+ const u32 result = a + b + carry;
+
+ rGPR[inst.RD] = result;
SetCarry(Helper_Carry(a, b) || (carry != 0 && Helper_Carry(a + b, carry)));
if (inst.OE)
- PanicAlert("OE: addex");
+ SetXER_OV(HasAddOverflowed(a, b, result));
if (inst.Rc)
- Helper_UpdateCR0(rGPR[inst.RD]);
+ Helper_UpdateCR0(result);
}
void Interpreter::addmex(UGeckoInstruction inst)
{
- int carry = GetCarry();
- int a = rGPR[inst.RA];
- rGPR[inst.RD] = a + carry - 1;
+ const u32 carry = GetCarry();
+ const u32 a = rGPR[inst.RA];
+ const u32 b = 0xFFFFFFFF;
+ const u32 result = a + b + carry;
+
+ rGPR[inst.RD] = result;
SetCarry(Helper_Carry(a, carry - 1));
if (inst.OE)
- PanicAlert("OE: addmex");
+ SetXER_OV(HasAddOverflowed(a, b, result));
if (inst.Rc)
- Helper_UpdateCR0(rGPR[inst.RD]);
+ Helper_UpdateCR0(result);
}
void Interpreter::addzex(UGeckoInstruction inst)
{
- int carry = GetCarry();
- int a = rGPR[inst.RA];
- rGPR[inst.RD] = a + carry;
+ const u32 carry = GetCarry();
+ const u32 a = rGPR[inst.RA];
+ const u32 result = a + carry;
+
+ rGPR[inst.RD] = result;
SetCarry(Helper_Carry(a, carry));
if (inst.OE)
- PanicAlert("OE: addzex");
+ SetXER_OV(HasAddOverflowed(a, 0, result));
if (inst.Rc)
- Helper_UpdateCR0(rGPR[inst.RD]);
+ Helper_UpdateCR0(result);
}
void Interpreter::divwx(UGeckoInstruction inst)