From dcfa50e36e88e37c80f7dbbeb32012e875f478d8 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:01:50 +0200 Subject: [PATCH] Fix float fast parameter aliasing --- oscar64/InterCode.cpp | 19 ++++++++++++++++++- oscar64/NativeCodeGenerator.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 6b88483..d5e7d9d 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -18982,7 +18982,9 @@ bool InterCodeBasicBlock::PeepholeReplaceOptimization(const GrowingVariableArray #endif else if ( mInstructions[i + 0]->mDst.mTemp >= 0 && - mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && IsCommutative(mInstructions[i + 1]->mOperator) && mInstructions[i + 0]->mDst.mTemp == mInstructions[i + 1]->mSrc[0].mTemp && mInstructions[i + 0]->mDst.mTemp != mInstructions[i + 1]->mSrc[1].mTemp) + mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && IsCommutative(mInstructions[i + 1]->mOperator) && + mInstructions[i + 0]->mDst.mTemp == mInstructions[i + 1]->mSrc[0].mTemp && + mInstructions[i + 0]->mDst.mTemp != mInstructions[i + 1]->mSrc[1].mTemp) { InterOperand io = mInstructions[i + 1]->mSrc[1]; mInstructions[i + 1]->mSrc[1] = mInstructions[i + 1]->mSrc[0]; @@ -19450,6 +19452,21 @@ bool InterCodeBasicBlock::PeepholeReplaceOptimization(const GrowingVariableArray } #endif +#if 0 + if (i + 2 < mInstructions.Size() && + mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mDst.mType == IT_FLOAT && + + mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && (mInstructions[i + 1]->mOperator == IA_ADD || mInstructions[i + 1]->mOperator == IA_MUL) && + mInstructions[i + 1]->mSrc[0].mTemp != mInstructions[i + 0]->mDst.mTemp && + mInstructions[i + 1]->mSrc[1].mTemp == mInstructions[i + 0]->mDst.mTemp) + { + InterOperand op = mInstructions[i + 1]->mSrc[0]; + mInstructions[i + 1]->mSrc[0] = mInstructions[i + 1]->mSrc[1]; + mInstructions[i + 1]->mSrc[1] = op; + + changed = true; + } +#endif #if 1 if (i + 2 < mInstructions.Size() && mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index abcbaa9..a168f9e 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -9486,6 +9486,10 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p sop0 = 1; sop1 = 0; const InterInstruction* sins = sins0; sins0 = sins1; sins1 = sins; } + else if (!sins1 && !sins0 && ins->mSrc[sop1].mTemp >= 0 && CheckPredAccuStore(BC_REG_TMP + proc->mTempOffset[ins->mSrc[sop1].mTemp]) && ins->mSrc[sop1].mFinal) + { + // no flip in this case + } else if (!sins0 && !sins1 && ins->mSrc[sop0].mTemp >= 0 && ins->mSrc[sop1].mTemp >= 0 && ins->mDst.mTemp == ins->mSrc[sop0].mTemp) { flipop = true; @@ -14593,6 +14597,15 @@ void NativeCodeBasicBlock::FindZeroPageAlias(const NumberSet& statics, NumberSet else if (mIns[i].ChangesAddress()) invalid += mIns[i].mAddress; } + else if (mIns[i].mType == ASMIT_JSR && (mIns[i].mFlags & NCIF_USE_ZP_32_X)) + { + int j = mIns[i].mParam; + invalid += j; + invalid += j + 1; + invalid += j + 2; + invalid += j + 3; + accu = -1; + } else if (mIns[i].ChangesAccu()) accu = -1; } @@ -14720,6 +14733,14 @@ void NativeCodeBasicBlock::CollectZeroPageUsage(NumberSet& used, NumberSet &modi modified += BC_REG_ACCU + j; modified += BC_REG_WORK + j; } + + if (mIns[i].mFlags & NCIF_USE_ZP_32_X) + { + for (int j = 0; j < 4; j++) + used += mIns[i].mParam + j; + for (int j = 0; j < 3; j++) + pairs += mIns[i].mParam + j; + } } if (mIns[i].mLinkerObject) @@ -50514,7 +50535,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc = proc; mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "sformat"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "sqrt"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; @@ -51352,7 +51373,6 @@ void NativeCodeProcedure::Optimize(void) mEntryBlock->ReplaceFinalZeroPageUse(this); } #endif - if (step > 1) { ResetVisited(); @@ -51377,7 +51397,6 @@ void NativeCodeProcedure::Optimize(void) mEntryBlock->CheckAsmCode(); #endif - int t = 0; #if 1 do @@ -51478,7 +51497,6 @@ void NativeCodeProcedure::Optimize(void) #endif - if (step == 2) { ResetVisited();