From df18dc273ebf1b527c844158a9a54f13d679fd42 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:54:55 +0100 Subject: [PATCH] Forward binary op in txax --- oscar64/NativeCodeGenerator.cpp | 43 +++++++++++++++++++++++++++++++++ oscar64/NativeCodeGenerator.h | 1 + 2 files changed, 44 insertions(+) diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 040fdd3..6688819 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -33827,6 +33827,33 @@ bool NativeCodeBasicBlock::CombineImmediateADCUp(int at) return false; } +bool NativeCodeBasicBlock::MoveTXALogicTAXDown(int at) +{ + int i = at + 3; + while (i < mIns.Size()) + { + if (mIns[i].ChangesXReg()) + return false; + + if (mIns[i].mType == ASMIT_TXA) + { + if (mIns[i].mLive & LIVE_CPU_REG_X) + return false; + mIns[at + 1].mLive |= mIns[i].mLive; + mIns.Insert(i + 1, mIns[at + 1]); + mIns.Remove(at, 3); + return true; + } + + if (mIns[i].RequiresXReg()) + return false; + + i++; + } + + return false; +} + bool NativeCodeBasicBlock::MoveTXADCDown(int at) { int i = at + 4; @@ -43827,6 +43854,22 @@ bool NativeCodeBasicBlock::PeepHoleOptimizerShuffle(int pass) #endif +#if 1 + for (int i = 0; i + 3 < mIns.Size(); i++) + { + if (mIns[i + 0].mType == ASMIT_TXA && + mIns[i + 1].IsLogic() && mIns[i + 1].mMode == ASMIM_IMMEDIATE && + mIns[i + 2].mType == ASMIT_TAX && !(mIns[i + 2].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z))) + { + if (MoveTXALogicTAXDown(i)) + changed = true; + } + } + + CheckLive(); + +#endif + #if 1 for (int i = 0; i + 1 < mIns.Size(); i++) { diff --git a/oscar64/NativeCodeGenerator.h b/oscar64/NativeCodeGenerator.h index 21ecf29..811c019 100644 --- a/oscar64/NativeCodeGenerator.h +++ b/oscar64/NativeCodeGenerator.h @@ -505,6 +505,7 @@ public: bool CombineImmediateADCUp(int at); bool CombineImmediateADCUpX(int at); bool MoveTXADCDown(int at); + bool MoveTXALogicTAXDown(int at); bool FoldShiftORAIntoLoadImmUp(int at); bool FindAccuExitValue(int& at);