From 880abea32efcd84b89e31290a1eb274dbc8bb665 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 29 May 2025 13:38:00 +0200 Subject: [PATCH] Shortcut tiny jump detours after placement --- oscar64/NativeCodeGenerator.cpp | 28 ++++++++++++++++++++++++++++ oscar64/NativeCodeGenerator.h | 1 + 2 files changed, 29 insertions(+) diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index cfccc11..3f3caf0 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -54908,6 +54908,31 @@ void NativeCodeBasicBlock::BuildPlacement(ExpandingArray& } } +void NativeCodeBasicBlock::OptimizePlacement(void) +{ + if (!mFalseJump && mTrueJump && !mTrueJump->mFalseJump && mTrueJump->mTrueJump && mTrueJump->mTrueJump->mPlace == mPlace + 1 && mTrueJump->mCode.Size() <= 3) + { + for (int i = 0; i < mTrueJump->mRelocations.Size(); i++) + { + LinkerReference rl = mTrueJump->mRelocations[i]; + rl.mOffset += mCode.Size(); + if (rl.mFlags & LREF_INBLOCK) + { + rl.mRefOffset += mCode.Size(); + rl.mFlags &= ~LREF_INBLOCK; + } + mRelocations.Push(rl); + } + for (int i = 0; i < mTrueJump->mCode.Size(); i++) + mCode.Push(mTrueJump->mCode[i]); + mTrueJump->mEntryBlocks.RemoveAll(this); + mTrueJump->mNumEntries--; + mTrueJump = mTrueJump->mTrueJump; + mTrueJump->mEntryBlocks.Push(this); + mTrueJump->mNumEntries++; + } +} + void NativeCodeBasicBlock::InitialOffset(int& total) { mAsmFromJump = -1; @@ -56064,6 +56089,9 @@ void NativeCodeProcedure::Assemble(void) mEntryBlock->BuildPlacement(placement); + for (int i = 0; i < placement.Size(); i++) + placement[i]->OptimizePlacement();; + for (int i = 0; i < placement.Size(); i++) placement[i]->InitialOffset(total); diff --git a/oscar64/NativeCodeGenerator.h b/oscar64/NativeCodeGenerator.h index 8fbc0e9..62a43f9 100644 --- a/oscar64/NativeCodeGenerator.h +++ b/oscar64/NativeCodeGenerator.h @@ -303,6 +303,7 @@ public: int LeadsInto(NativeCodeBasicBlock* block, int dist); NativeCodeBasicBlock* PlaceSequence(ExpandingArray& placement, NativeCodeBasicBlock* block); void BuildPlacement(ExpandingArray& placement); + void OptimizePlacement(void); void InitialOffset(int& total); bool CalculateOffset(int& total, bool final);