summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorFiora <fioraaeterna@gmail.com>2014-08-15 10:53:56 -0700
committerFiora <fioraaeterna@gmail.com>2014-08-15 11:26:10 -0700
commit1669b361a250c47b2ce45a06d30b04ea4fda9c8e (patch)
tree977351b109f8247836a2154cbcd0038fb70a8fa0 /Source/Core
parentd5d5580424d92c56f8f3d964e1437c744737c67d (diff)
JIT: don't rely on undefined behavior for constant overflow checking
I have no idea what the compiler does with these, and this code probably isn't triggered in most games, but it's probably better not to taunt the undefined behavior demon.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit.h1
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp12
2 files changed, 10 insertions, 3 deletions
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.h b/Source/Core/Core/PowerPC/Jit64/Jit.h
index 197e19d588..8c5265ae04 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit.h
+++ b/Source/Core/Core/PowerPC/Jit64/Jit.h
@@ -94,6 +94,7 @@ public:
void Cleanup();
void GenerateConstantOverflow(bool overflow);
+ void GenerateConstantOverflow(s64 val);
void GenerateOverflow();
void FinalizeCarryOverflow(bool oe, bool inv = false);
void GetCarryEAXAndClear();
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp
index 5676ca9af1..a6535b4b67 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp
+++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
+#include <limits>
#include <vector>
#include "Core/PowerPC/Jit64/Jit.h"
@@ -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)
@@ -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
@@ -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
@@ -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)