mirror of
https://github.com/PCSX2/pcsx2.git
synced 2026-12-03 19:33:33 +01:00
EE-INT: Correct D/SUB overflow checks giving incorrect result
This commit is contained in:
1 parent
b9ed7fb2b5
commit
bb1e4191f4
1 file changed
+27
-2
@@ -60,6 +60,31 @@ static __fi bool _add32_Overflow( s32 x, s32 y, s64 &ret )
|
||||
return false;
|
||||
}
|
||||
|
||||
static __fi bool _sub64_Overflow(s64 x, s64 y, s64& ret)
|
||||
{
|
||||
const s64 result = static_cast<s64>(static_cast<u64>(x) - static_cast<u64>(y));
|
||||
// Overflow only happens if the sign differs on the x and y.
|
||||
if (((x ^ y) & (x ^ result)) < 0)
|
||||
{
|
||||
cpuException(0x30, cpuRegs.branch);
|
||||
return true;
|
||||
}
|
||||
ret = result;
|
||||
return false;
|
||||
}
|
||||
|
||||
static __fi bool _sub32_Overflow(s32 x, s32 y, s64& ret)
|
||||
{
|
||||
const s64 result = static_cast<s64>(x) - y;
|
||||
|
||||
if (result != static_cast<s32>(result))
|
||||
{
|
||||
cpuException(0x30, cpuRegs.branch);
|
||||
return true;
|
||||
}
|
||||
ret = result;
|
||||
return false;
|
||||
}
|
||||
|
||||
const R5900::OPCODE& R5900::GetCurrentInstruction()
|
||||
{
|
||||
@@ -347,7 +372,7 @@ void DADD()
|
||||
void SUB()
|
||||
{
|
||||
s64 result;
|
||||
bool overflow = _add32_Overflow( cpuRegs.GPR.r[_Rs_].SD[0], -cpuRegs.GPR.r[_Rt_].SD[0], result );
|
||||
bool overflow = _sub32_Overflow(cpuRegs.GPR.r[_Rs_].SD[0], cpuRegs.GPR.r[_Rt_].SD[0], result);
|
||||
if (overflow || !_Rd_) return;
|
||||
cpuRegs.GPR.r[_Rd_].SD[0] = result;
|
||||
}
|
||||
@@ -356,7 +381,7 @@ void SUB()
|
||||
void DSUB()
|
||||
{
|
||||
s64 result;
|
||||
bool overflow = _add64_Overflow( cpuRegs.GPR.r[_Rs_].SD[0], -cpuRegs.GPR.r[_Rt_].SD[0], result );
|
||||
bool overflow = _sub64_Overflow(cpuRegs.GPR.r[_Rs_].SD[0], cpuRegs.GPR.r[_Rt_].SD[0], result);
|
||||
if (overflow || !_Rd_) return;
|
||||
cpuRegs.GPR.r[_Rd_].SD[0] = result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user