From a3bf7296bb5f38512c63dd3cedfb4395bde09c82 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:24:02 +0200 Subject: [PATCH] Reduce index register usage, where ORA Imm would suffice --- oscar64/InterCode.cpp | 10 +++++++++- oscar64/NativeCodeGenerator.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 6a83dde..a60311f 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -8284,6 +8284,14 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSetsForward(const GrowingVariab vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND; break; #if 1 + case IA_DIVU: + vr = mProc->mLocalValueRange[ins->mSrc[1].mTemp]; + vr.LimitMin(0); + vr.mMinValue = 0; + if (ins->mSrc[0].mTemp < 0 && ins->mSrc[0].mIntConst > 1) + vr.mMaxValue /= ins->mSrc[0].mIntConst; + break; + case IA_MODU: vr.LimitMin(0); if (ins->mSrc[0].mTemp < 0) @@ -15229,7 +15237,7 @@ void InterCodeBasicBlock::EliminateDoubleLoopCounter(void) if (lcs.Size() >= 2) { - int loop = -1; + int64 loop = -1; int k = 0; while (k < lcs.Size() && !lcs[k].mCmp) k++; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 4607831..6520e6b 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -42175,6 +42175,20 @@ bool NativeCodeBasicBlock::PeepHoleOptimizerIterate1(int i, int pass) mIns[i].mType = ASMIT_ASL; return true; } + else if (mIns[i].mType == ASMIT_TAY && !(mIns[i].mLive & LIVE_CPU_REG_Y)) + { + mIns[i].mType = ASMIT_ORA; + mIns[i].mMode = ASMIM_IMMEDIATE; + mIns[i].mAddress = 0; + return true; + } + else if (mIns[i].mType == ASMIT_TAX && !(mIns[i].mLive & LIVE_CPU_REG_X)) + { + mIns[i].mType = ASMIT_ORA; + mIns[i].mMode = ASMIM_IMMEDIATE; + mIns[i].mAddress = 0; + return true; + } int apos; if (mIns[i].mMode == ASMIM_INDIRECT_Y && FindGlobalAddress(i, mIns[i].mAddress, apos)) @@ -44400,6 +44414,16 @@ bool NativeCodeBasicBlock::PeepHoleOptimizerIterate3(int i, int pass) mIns.Remove(i + 2); return true; } + else if ( + mIns[i + 0].ChangesAccuAndFlag() && mIns[i + 0].mMode == ASMIM_IMPLIED && + (mIns[i + 1].mType == ASMIT_INX || mIns[i + 1].mType == ASMIT_DEX || mIns[i + 1].mType == ASMIT_INY || mIns[i + 1].mType == ASMIT_DEY) && + mIns[i + 2].mType == ASMIT_ORA && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 0) + { + mIns[i + 2] = mIns[i + 0]; + mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED; + mIns[i + 1].mLive |= LIVE_CPU_REG_A; + return true; + } else if ( mIns[i + 0].mType == ASMIT_LDA && mIns[i + 1].mType == ASMIT_STA && @@ -49486,7 +49510,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc = proc; mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "main"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "clz"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks];