From 9fa8b644a706fa3ef21fa41ddbd30dee3133f1b6 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 23 May 2024 09:54:07 +0200 Subject: [PATCH] Add object placement retry if page locking does not fit --- oscar64/Linker.cpp | 25 ++++++++++++++----------- oscar64/Linker.h | 4 ++-- oscar64/NativeCodeGenerator.cpp | 7 +++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index f86a6b6..29a0232 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -561,7 +561,7 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj) if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) { - if (!Allocate(linker, lobj->mSuffix, true)) + if (!Allocate(linker, lobj->mSuffix, true, false)) return false; } @@ -598,7 +598,7 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj) if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) { - if (!Allocate(linker, lobj->mSuffix, true)) + if (!Allocate(linker, lobj->mSuffix, true, false)) return false; } @@ -610,13 +610,13 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj) return false; } -bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge) +bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge, bool retry) { if (merge && lobj->mPrefix) { if (!(lobj->mPrefix->mFlags & LOBJF_PLACED)) { - if (!Allocate(linker, lobj->mPrefix, true)) + if (!Allocate(linker, lobj->mPrefix, true, false)) return false; if (lobj->mFlags & LOBJF_PLACED) @@ -673,7 +673,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge) if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) { - if (!Allocate(linker, lobj->mSuffix, true)) + if (!Allocate(linker, lobj->mSuffix, true, false)) return false; } @@ -685,7 +685,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge) int start = (mStart + mUsed + lobj->mAlignment - 1) & ~(lobj->mAlignment - 1); int end = start + lobj->mSize; - if (!(linker->mCompilerOptions & COPT_OPTIMIZE_CODE_SIZE) && (lobj->mFlags & LOBJF_NO_CROSS) && !(lobj->mFlags & LOBJF_FORCE_ALIGN) && lobj->mSize <= 256 && (start & 0xff00) != ((end - 1) & 0xff00) && !(lobj->mSection->mFlags & LSECF_PACKED)) + if (!(linker->mCompilerOptions & COPT_OPTIMIZE_CODE_SIZE) && !retry && (lobj->mFlags & LOBJF_NO_CROSS) && !(lobj->mFlags & LOBJF_FORCE_ALIGN) && lobj->mSize <= 256 && (start & 0xff00) != ((end - 1) & 0xff00) && !(lobj->mSection->mFlags & LSECF_PACKED)) { start = (start + 0x00ff) & 0xff00; end = start + lobj->mSize; @@ -719,7 +719,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge) if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) { - if (!Allocate(linker, lobj->mSuffix, true)) + if (!Allocate(linker, lobj->mSuffix, true, false)) return false; } @@ -924,7 +924,7 @@ void Linker::PatchReferences(bool inlays) } } -void Linker::PlaceObjects(void) +void Linker::PlaceObjects(bool retry) { for (int i = 0; i < mRegions.Size(); i++) { @@ -935,7 +935,7 @@ void Linker::PlaceObjects(void) for (int k = 0; k < lsec->mObjects.Size(); k++) { LinkerObject* lobj = lsec->mObjects[k]; - if (lobj->mType != LOT_INLAY && (lobj->mFlags & LOBJF_REFERENCED) && !(lobj->mFlags & LOBJF_PLACED) && lrgn->Allocate(this, lobj, mCompilerOptions & COPT_OPTIMIZE_MERGE_CALLS)) + if (lobj->mType != LOT_INLAY && (lobj->mFlags & LOBJF_REFERENCED) && !(lobj->mFlags & LOBJF_PLACED) && lrgn->Allocate(this, lobj, mCompilerOptions & COPT_OPTIMIZE_MERGE_CALLS, retry)) { if (lobj->mIdent && lobj->mIdent->mString && (mCompilerOptions & COPT_VERBOSE2)) printf("Placed object <%s> $%04x - $%04x\n", lobj->mIdent->mString, lobj->mAddress, lobj->mAddress + lobj->mSize); @@ -996,7 +996,10 @@ void Linker::Link(void) } // Move objects into regions - PlaceObjects(); + PlaceObjects(false); + + // Retry for alignment + PlaceObjects(true); // Place stack segment @@ -1051,7 +1054,7 @@ void Linker::Link(void) } } - PlaceObjects(); + PlaceObjects(false); // Calculate BSS storage diff --git a/oscar64/Linker.h b/oscar64/Linker.h index c448427..ec361fb 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -100,7 +100,7 @@ public: LinkerObject * mLastObject; bool AllocateAppend(Linker* linker, LinkerObject* obj); - bool Allocate(Linker * linker, LinkerObject* obj, bool merge); + bool Allocate(Linker * linker, LinkerObject* obj, bool merge, bool retry); void PlaceStackSection(LinkerSection* stackSection, LinkerSection* section); }; @@ -307,7 +307,7 @@ public: void InlineSimpleJumps(void); void PatchReferences(bool inlays); void CopyObjects(bool inlays); - void PlaceObjects(void); + void PlaceObjects(bool retry); void Link(void); protected: NativeCodeDisassembler mNativeDisassembler; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index ff3b68b..caf07d0 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -24180,9 +24180,11 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool { mEntryBlocks[i]->mIns.Push(mIns[0]); mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_X; + mEntryBlocks[i]->mExitRequiredRegs -= CPU_REG_Z; } } + mEntryRequiredRegs -= CPU_REG_Z; mEntryRequiredRegs += CPU_REG_X; mIns.Remove(0); changed = true; @@ -42746,7 +42748,8 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass else if ( mIns[i + 0].mType == ASMIT_STA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && !mIns[i + 1].ChangesZeroPage(mIns[i + 0].mAddress) && !mIns[i + 1].RequiresYReg() && !mIns[i + 1].ChangesYReg() && - mIns[i + 2].mType == ASMIT_LDY && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && !(mIns[i + 2].mLive & LIVE_MEM)) + mIns[i + 2].mType == ASMIT_LDY && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && !(mIns[i + 2].mLive & LIVE_MEM) && + (!mIns[i + 1].ChangesZFlag() || !(mIns[i + 2].mLive & LIVE_CPU_REG_Z))) { mIns[i + 0].mType = ASMIT_TAY; mIns[i + 0].mMode = ASMIM_IMPLIED; mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; @@ -48062,7 +48065,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) { mInterProc = proc; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "Actor::setupFrame"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "buildRamTiles"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks];