summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-05-22 10:25:45 -0400
committerLioncash <mathew1800@gmail.com>2018-05-22 10:39:08 -0400
commit2ca1ac337040a6dd9f0f1a18a7dbdc2aa027d21f (patch)
tree8dde35097def2340f48096c037aae531412fddd9 /Source
parent5ac05725c88a146ff517dc145c07a9f475186256 (diff)
Interpreter_Integer: Correct negative overflow handling for divw
Previously, given cases such as 0x80000000 / 0xFFFFFFFF we'd incorrectly set the destination register value to zero. If the dividend is negative, then the destination should be set to -1 (0xFFFFFFFF), however if the dividend is positive, then the destination should be set to 0. Note that the 750CL documents state that: "If an attempt is made to perform either of the divisions -- 0x80000000 / -1 or <anything> / 0, then the contents of rD are undefined, as are the contents of the LT, GT, and EQ bits of the CR0 field (if Rc = 1). In this case, if OE = 1 then OV is set." So this is a particular behavior of the hardware itself.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
index 5801b527c1..5b5d4450a6 100644
--- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
+++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Integer.cpp
@@ -501,18 +501,18 @@ void Interpreter::divwx(UGeckoInstruction inst)
{
const s32 a = rGPR[inst.RA];
const s32 b = rGPR[inst.RB];
- const bool overflow = b == 0 || ((u32)a == 0x80000000 && b == -1);
+ const bool overflow = b == 0 || (static_cast<u32>(a) == 0x80000000 && b == -1);
if (overflow)
{
- if (((u32)a & 0x80000000) && b == 0)
+ if (a < 0)
rGPR[inst.RD] = UINT32_MAX;
else
rGPR[inst.RD] = 0;
}
else
{
- rGPR[inst.RD] = (u32)(a / b);
+ rGPR[inst.RD] = static_cast<u32>(a / b);
}
if (inst.OE)