summaryrefslogtreecommitdiff
path: root/Source/Core/Common/x64Emitter.cpp
diff options
context:
space:
mode:
authorMarkus Wick <degasus@users.noreply.github.com>2016-06-27 23:53:27 +0200
committerGitHub <noreply@github.com>2016-06-27 23:53:27 +0200
commit93a5efa347c62ca97e375a1a226d7741d584fd2f (patch)
treed52b956df06ab0ff2a25c4c2b237db7e54ec8c4a /Source/Core/Common/x64Emitter.cpp
parentadcef046f6069fd72e1a10faff050f192e78c417 (diff)
parent1e08ad0d978683e096bc8161778b71f763cc52a6 (diff)
Merge pull request #3956 from mmastrac/mov_sum
Add MOV optimizations and MOV_sum
Diffstat (limited to 'Source/Core/Common/x64Emitter.cpp')
-rw-r--r--Source/Core/Common/x64Emitter.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp
index 8ad1d46e40..9a4ca705a0 100644
--- a/Source/Core/Common/x64Emitter.cpp
+++ b/Source/Core/Common/x64Emitter.cpp
@@ -1540,6 +1540,13 @@ void XEmitter::XOR(int bits, const OpArg& a1, const OpArg& a2)
}
void XEmitter::MOV(int bits, const OpArg& a1, const OpArg& a2)
{
+ // Shortcut to zero a register
+ if (a2.IsZero() && a1.IsSimpleReg() && !flags_locked)
+ {
+ XOR(bits, a1, a1);
+ return;
+ }
+
if (a1.IsSimpleReg() && a2.IsSimpleReg() && a1.GetSimpleReg() == a2.GetSimpleReg())
ERROR_LOG(DYNA_REC, "Redundant MOV @ %p - bug in JIT?", code);
WriteNormalOp(bits, nrmMOV, a1, a2);
@@ -1572,6 +1579,76 @@ void XEmitter::CMP_or_TEST(int bits, const OpArg& a1, const OpArg& a2)
}
}
+void XEmitter::MOV_sum(int bits, X64Reg dest, const OpArg& a1, const OpArg& a2)
+{
+ // This stomps on flags, so ensure they aren't locked
+ _dbg_assert_(DYNA_REC, !flags_locked);
+
+ // Zero shortcuts (note that this can generate no code in the case where a1 == dest && a2 == zero
+ // or a2 == dest && a1 == zero)
+ if (a1.IsZero())
+ {
+ if (!a2.IsSimpleReg() || a2.GetSimpleReg() != dest)
+ {
+ MOV(bits, R(dest), a2);
+ }
+ return;
+ }
+ if (a2.IsZero())
+ {
+ if (!a1.IsSimpleReg() || a1.GetSimpleReg() != dest)
+ {
+ MOV(bits, R(dest), a1);
+ }
+ return;
+ }
+
+ // If dest == a1 or dest == a2 we can simplify this
+ if (a1.IsSimpleReg() && a1.GetSimpleReg() == dest)
+ {
+ ADD(bits, R(dest), a2);
+ return;
+ }
+
+ if (a2.IsSimpleReg() && a2.GetSimpleReg() == dest)
+ {
+ ADD(bits, R(dest), a1);
+ return;
+ }
+
+ // TODO: 32-bit optimizations may apply to other bit sizes (confirm)
+ if (bits == 32)
+ {
+ if (a1.IsImm() && a2.IsImm())
+ {
+ MOV(32, R(dest), Imm32(a1.Imm32() + a2.Imm32()));
+ return;
+ }
+
+ if (a1.IsSimpleReg() && a2.IsSimpleReg())
+ {
+ LEA(32, dest, MRegSum(a1.GetSimpleReg(), a2.GetSimpleReg()));
+ return;
+ }
+
+ if (a1.IsSimpleReg() && a2.IsImm())
+ {
+ LEA(32, dest, MDisp(a1.GetSimpleReg(), a2.Imm32()));
+ return;
+ }
+
+ if (a1.IsImm() && a2.IsSimpleReg())
+ {
+ LEA(32, dest, MDisp(a2.GetSimpleReg(), a1.Imm32()));
+ return;
+ }
+ }
+
+ // Fallback
+ MOV(bits, R(dest), a1);
+ ADD(bits, R(dest), a2);
+}
+
void XEmitter::IMUL(int bits, X64Reg regOp, const OpArg& a1, const OpArg& a2)
{
CheckFlags();