Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #812 from FioraAeterna/fixundefined
JIT: don't rely on undefined behavior for constant overflow checking
  • Loading branch information
dolphin-emu-bot committed Aug 15, 2014
2 parents 1c06884 + 1669b36 commit 444e47a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/PowerPC/Jit64/Jit.h
Expand Up @@ -94,6 +94,7 @@ class Jit64 : public Jitx86Base
void Cleanup();

void GenerateConstantOverflow(bool overflow);
void GenerateConstantOverflow(s64 val);
void GenerateOverflow();
void FinalizeCarryOverflow(bool oe, bool inv = false);
void GetCarryEAXAndClear();
Expand Down
12 changes: 9 additions & 3 deletions Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp
Expand Up @@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <limits>
#include <vector>

#include "Core/PowerPC/Jit64/Jit.h"
Expand All @@ -10,6 +11,11 @@

using namespace Gen;

void Jit64::GenerateConstantOverflow(s64 val)
{
GenerateConstantOverflow(val > std::numeric_limits<s32>::max() || val < std::numeric_limits<s32>::min());
}

void Jit64::GenerateConstantOverflow(bool overflow)
{
if (overflow)
Expand Down Expand Up @@ -925,7 +931,7 @@ void Jit64::subfx(UGeckoInstruction inst)
}
if (inst.OE)
{
GenerateConstantOverflow((s64)(i - j) != (s64)i - (s64)j);
GenerateConstantOverflow((s64)i - (s64)j);
}
}
else
Expand Down Expand Up @@ -1014,7 +1020,7 @@ void Jit64::mullwx(UGeckoInstruction inst)
gpr.SetImmediate32(d, i * j);
if (inst.OE)
{
GenerateConstantOverflow((s64)(i*j) != (s64)i * (s64)j);
GenerateConstantOverflow((s64)i * (s64)j);
}
}
else
Expand Down Expand Up @@ -1330,7 +1336,7 @@ void Jit64::addx(UGeckoInstruction inst)
}
if (inst.OE)
{
GenerateConstantOverflow((s64)(i + j) != (s64)i + (s64)j);
GenerateConstantOverflow((s64)i + (s64)j);
}
}
else if (gpr.R(a).IsSimpleReg() && gpr.R(b).IsSimpleReg() && !inst.Rc && !inst.OE)
Expand Down

0 comments on commit 444e47a

Please sign in to comment.