From 121f0476e12c60d008d137ddbd509259b8a2546c Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 24 Sep 2022 14:31:09 +0200 Subject: [PATCH] Bump version number --- oscar64/InterCode.cpp | 115 +++++++++++++++++++++- oscar64/InterCode.h | 1 + oscar64/NativeCodeGenerator.cpp | 160 ++++++++++++++++++++++++++++--- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 +- oscar64setup/oscar64setup.vdproj | 6 +- 6 files changed, 269 insertions(+), 23 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index eafc403..1dfcf0f 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -7107,6 +7107,92 @@ bool InterCodeBasicBlock::MergeIndexedLoadStore(const GrowingInstructionPtrArra return changed; } +static bool CheckSimplifyPointerOffsets(const InterInstruction* ins, int temp, int& mino, int& maxo) +{ + if (ins->mDst.mTemp == temp) + return false; + + if (ins->mCode == IC_LOAD && ins->mSrc[0].mTemp == temp) + { + if (ins->mSrc[0].mIntConst < mino) + mino = ins->mSrc[0].mIntConst; + if (ins->mSrc[0].mIntConst > maxo) + maxo = ins->mSrc[0].mIntConst; + + return true; + } + + if (ins->mCode == IC_STORE && ins->mSrc[1].mTemp == temp) + { + if (ins->mSrc[0].mTemp == temp) + return false; + + if (ins->mSrc[1].mIntConst < mino) + mino = ins->mSrc[1].mIntConst; + if (ins->mSrc[1].mIntConst > maxo) + maxo = ins->mSrc[1].mIntConst; + + return true; + } + + for (int i = 0; i < ins->mNumOperands; i++) + if (ins->mSrc[i].mTemp == temp) + return false; + + return true; +} + +bool InterCodeBasicBlock::SimplifyPointerOffsets(void) +{ + bool changed = false; + + if (!mVisited) + { + mVisited = true; + + for (int i = 0; i < mInstructions.Size(); i++) + { + InterInstruction* ins = mInstructions[i]; + + if (ins->mCode == IC_LEA && (ins->mSrc[0].mTemp < 0 || ins->mSrc[1].mTemp < 0) && !mExitRequiredTemps[ins->mDst.mTemp]) + { + int minoffset = 65535, maxoffset = -65535; + + int j = i + 1; + while (j < mInstructions.Size() && CheckSimplifyPointerOffsets(mInstructions[j], ins->mDst.mTemp, minoffset, maxoffset)) + j++; + + if (j == mInstructions.Size() && (minoffset < 0 || maxoffset > 255) && maxoffset - minoffset < 256) + { + if (ins->mSrc[0].mTemp < 0) + ins->mSrc[0].mIntConst += minoffset; + else + ins->mSrc[1].mIntConst += minoffset; + + changed = true; + + for (int j = i + 1; j < mInstructions.Size(); j++) + { + InterInstruction* tins = mInstructions[j]; + if (tins->mCode == IC_LOAD && tins->mSrc[0].mTemp == ins->mDst.mTemp) + tins->mSrc[0].mIntConst -= minoffset; + else if (tins->mCode == IC_STORE && tins->mSrc[1].mTemp == ins->mDst.mTemp) + tins->mSrc[1].mIntConst -= minoffset; + } + } + } + } + + if (mTrueJump && mTrueJump->SimplifyPointerOffsets()) + changed = true; + if (mFalseJump && mFalseJump->SimplifyPointerOffsets()) + changed = true; + } + + return true; +} + + bool InterCodeBasicBlock::SimplifyIntegerNumeric(const GrowingInstructionPtrArray& tvalue, int& spareTemps) { bool changed = false; @@ -12410,6 +12496,11 @@ void InterCodeProcedure::MergeIndexedLoadStore(void) RemoveUnusedInstructions(); DisassembleDebug("MergeIndexedLoadStore"); + + ResetVisited(); + mEntryBlock->SimplifyPointerOffsets(); + + DisassembleDebug("SimplifyPointerOffsets"); } void InterCodeProcedure::SimplifyIntegerNumeric(FastNumberSet& activeSet) @@ -13199,10 +13290,10 @@ bool InterCodeBasicBlock::SameExitCode(const InterCodeBasicBlock* block) const { if (ins0->mCode == IC_STORE && ins0->mSrc[1].mTemp >= 0) { - int j0 = mInstructions.Size() - 2; + int j0 = mInstructions.Size() - 3; while (j0 >= 0 && mInstructions[j0]->mDst.mTemp != ins0->mSrc[1].mTemp) j0--; - int j1 = block->mInstructions.Size() - 2; + int j1 = block->mInstructions.Size() - 3; while (j1 >= 0 && block->mInstructions[j1]->mDst.mTemp != ins0->mSrc[1].mTemp) j1--; @@ -13217,6 +13308,26 @@ bool InterCodeBasicBlock::SameExitCode(const InterCodeBasicBlock* block) const } } } + else if (ins0->mCode == IC_LOAD && ins0->mSrc[0].mTemp >= 0) + { + int j0 = mInstructions.Size() - 3; + while (j0 >= 0 && mInstructions[j0]->mDst.mTemp != ins0->mSrc[0].mTemp) + j0--; + int j1 = block->mInstructions.Size() - 3; + while (j1 >= 0 && block->mInstructions[j1]->mDst.mTemp != ins0->mSrc[0].mTemp) + j1--; + + if (j0 >= 0 && j1 >= 0) + { + if (!(mInstructions[j0]->IsEqual(block->mInstructions[j1]))) + { + if (mInstructions[j0]->mCode == IC_LEA && mInstructions[j0]->mSrc[1].mTemp < 0) + return false; + if (block->mInstructions[j1]->mCode == IC_LEA && mInstructions[j1]->mSrc[1].mTemp < 0) + return false; + } + } + } return true; } diff --git a/oscar64/InterCode.h b/oscar64/InterCode.h index 6c413c8..01c1324 100644 --- a/oscar64/InterCode.h +++ b/oscar64/InterCode.h @@ -434,6 +434,7 @@ public: bool MergeIndexedLoadStore(const GrowingInstructionPtrArray& tvalue); bool SimplifyIntegerNumeric(const GrowingInstructionPtrArray& tvalue, int& spareTemps); + bool SimplifyPointerOffsets(void); bool EliminateAliasValues(const GrowingInstructionPtrArray& tvalue, const GrowingInstructionPtrArray& avalue); bool CalculateSingleAssignmentTemps(FastNumberSet& tassigned, GrowingInstructionPtrArray& tvalue, NumberSet& modifiedParams, InterMemory paramMemory); diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index b7427e3..04f23b8 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -3088,14 +3088,14 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data, AsmInsT mMode = ASMIM_IMMEDIATE; changed = true; } - else if (data.mRegs[CPU_REG_A].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_A].mValue == mAddress) + else if (final && data.mRegs[CPU_REG_A].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_A].mValue == mAddress) { mType = ASMIT_TAY; mMode = ASMIM_IMPLIED; data.mRegs[CPU_REG_Y] = data.mRegs[CPU_REG_A]; changed = true; } - else if (data.mRegs[mAddress].SameData(data.mRegs[CPU_REG_A])) + else if (final && data.mRegs[mAddress].SameData(data.mRegs[CPU_REG_A])) { mType = ASMIT_TAY; mMode = ASMIM_IMPLIED; @@ -10053,6 +10053,59 @@ void NativeCodeBasicBlock::RelationalOperator(InterCodeProcedure* proc, const In this->Close(falseJump, trueJump, ASMIT_BEQ); } #endif + else if (ins->mSrc[0].IsUByte() && ins->mSrc[1].IsUByte()) + { + NativeCodeBasicBlock* eblock = nproc->AllocateBlock(); + NativeCodeBasicBlock* nblock = nproc->AllocateBlock(); + + int li = 1, ri = 0; + if (op == IA_CMPLEU || op == IA_CMPGU || op == IA_CMPLES || op == IA_CMPGS) + { + li = 0; ri = 1; + } + + int iconst = 0; + bool rconst = false; + + if (ins->mSrc[ri].mTemp < 0) + { + iconst = ins->mSrc[ri].mIntConst; + rconst = true; + } + + if (ins->mSrc[li].mTemp < 0) + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[li].mIntConst & 0xff)); + else + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[li].mTemp])); + if (rconst) + mIns.Push(NativeCodeInstruction(ASMIT_CMP, ASMIM_IMMEDIATE, iconst & 0xff)); + else + mIns.Push(NativeCodeInstruction(ASMIT_CMP, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[ri].mTemp])); + + switch (op) + { + case IA_CMPEQ: + this->Close(trueJump, falseJump, ASMIT_BEQ); + break; + case IA_CMPNE: + this->Close(falseJump, trueJump, ASMIT_BEQ); + break; + case IA_CMPLU: + case IA_CMPLS: + case IA_CMPGU: + case IA_CMPGS: + this->Close(trueJump, falseJump, ASMIT_BCC); + break; + case IA_CMPLEU: + case IA_CMPLES: + case IA_CMPGEU: + case IA_CMPGES: + this->Close(falseJump, trueJump, ASMIT_BCC); + break; + + } + + } else { NativeCodeBasicBlock* eblock = nproc->AllocateBlock(); @@ -14344,8 +14397,14 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) #endif - if (mTrueJump && mFalseJump && mTrueJump->mNumEntries == 1 && mFalseJump->mNumEntries == 1) + if (mTrueJump && mFalseJump) { + uint32 live = 0; + if (mExitRequiredRegs[CPU_REG_X]) + live |= LIVE_CPU_REG_X; + if (mExitRequiredRegs[CPU_REG_Y]) + live |= LIVE_CPU_REG_Y; + int i = 0; while (i < mIns.Size()) { @@ -14358,14 +14417,9 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) if (!ReferencedOnPath(this, i + 2, mIns.Size(), mIns[i + 1].mAddress) && !ChangedOnPath(this, i + 2, mIns.Size(), mIns[i + 0].mAddress)) { - uint32 live = 0; - if (mExitRequiredRegs[CPU_REG_X]) - live |= LIVE_CPU_REG_X; - if (mExitRequiredRegs[CPU_REG_Y]) - live |= LIVE_CPU_REG_Y; - if (mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress] && - !mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress]) + !mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress] && + mTrueJump->mNumEntries == 1) { for (int j = 0; j < 2; j++) { @@ -14376,7 +14430,8 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) changed = true; } else if (mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress] && - !mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress]) + !mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress] && + mFalseJump->mNumEntries == 1) { for (int j = 0; j < 2; j++) { @@ -14408,10 +14463,18 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) !ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 4].mAddress)) { if (mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && - !mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress]) + !mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mTrueJump->mEntryRequiredRegs[CPU_REG_C] && + mTrueJump->mNumEntries == 1) { + mTrueJump->mEntryRequiredRegs += mIns[i + 1].mAddress; + mTrueJump->mEntryRequiredRegs += mIns[i + 2].mAddress; + mTrueJump->mEntryRequiredRegs += mIns[i + 4].mAddress; + mTrueJump->mEntryRequiredRegs += mIns[i + 5].mAddress; + for (int j = 0; j < 7; j++) { + mIns[i].mLive |= live; mTrueJump->mIns.Insert(j, mIns[i]); mIns.Remove(i); } @@ -14419,10 +14482,72 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) i--; } else if (mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && - !mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress]) + !mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mFalseJump->mEntryRequiredRegs[CPU_REG_C] && + mFalseJump->mNumEntries == 1) { + mFalseJump->mEntryRequiredRegs += mIns[i + 1].mAddress; + mFalseJump->mEntryRequiredRegs += mIns[i + 2].mAddress; + mFalseJump->mEntryRequiredRegs += mIns[i + 4].mAddress; + mFalseJump->mEntryRequiredRegs += mIns[i + 5].mAddress; + for (int j = 0; j < 7; j++) { + mIns[i].mLive |= live; + mFalseJump->mIns.Insert(j, mIns[i]); + mIns.Remove(i); + } + changed = true; + i--; + } + } + } +#endif +#if 1 + if (!mExitRequiredRegs[CPU_REG_A] && + i + 6 < mIns.Size() && + mIns[i + 0].mType == ASMIT_CLC && + mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && + mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && + mIns[i + 3].mType == ASMIT_STA && mIns[i + 3].mMode == ASMIM_ZERO_PAGE && + mIns[i + 4].mType == ASMIT_LDA && mIns[i + 4].mMode == ASMIM_ZERO_PAGE && + mIns[i + 5].mType == ASMIT_ADC && mIns[i + 5].mMode == ASMIM_IMMEDIATE && + mIns[i + 6].mType == ASMIT_STA && mIns[i + 6].mMode == ASMIM_ZERO_PAGE && + !(mIns[i + 6].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C | LIVE_CPU_REG_Z))) + { + if (!ReferencedOnPath(this, i + 7, mIns.Size(), mIns[i + 3].mAddress) && + !ReferencedOnPath(this, i + 7, mIns.Size(), mIns[i + 6].mAddress) && + !ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 1].mAddress) && + !ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 4].mAddress)) + { + if (mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mTrueJump->mEntryRequiredRegs[CPU_REG_C] && + mTrueJump->mNumEntries == 1) + { + mTrueJump->mEntryRequiredRegs += mIns[i + 1].mAddress; + mTrueJump->mEntryRequiredRegs += mIns[i + 4].mAddress; + + for (int j = 0; j < 7; j++) + { + mIns[i].mLive |= live; + mTrueJump->mIns.Insert(j, mIns[i]); + mIns.Remove(i); + } + changed = true; + i--; + } + else if (mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] && + !mFalseJump->mEntryRequiredRegs[CPU_REG_C] && + mFalseJump->mNumEntries == 1) + { + mFalseJump->mEntryRequiredRegs += mIns[i + 1].mAddress; + mFalseJump->mEntryRequiredRegs += mIns[i + 4].mAddress; + + for (int j = 0; j < 7; j++) + { + mIns[i].mLive |= live; mFalseJump->mIns.Insert(j, mIns[i]); mIns.Remove(i); } @@ -25514,6 +25639,15 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_EOR && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress == 0x80 && + mIns[i + 1].mType == ASMIT_CLC && + mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && !(mIns[i + 2].mLive & LIVE_CPU_REG_C)) + { + mIns[i + 2].mAddress ^= 0x80; + mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED; + progress = true; + } else if ( mIns[i + 0].mType == ASMIT_STA && !(mIns[i + 0].mFlags & NCIF_VOLATILE) && mIns[i + 2].mType == ASMIT_STA && mIns[i + 0].SameEffectiveAddress(mIns[i + 2]) && diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 8ceca9f..7aaa8f7 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -74,7 +74,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.10.159"); + strcpy(strProductVersion, "1.10.160"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 288a597..b997414 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,10,159,0 - PRODUCTVERSION 1,10,159,0 + FILEVERSION 1,10,160,0 + PRODUCTVERSION 1,10,160,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.10.159.0" + VALUE "FileVersion", "1.10.160.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.10.159.0" + VALUE "ProductVersion", "1.10.160.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index 83c93d7..0f96897 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -4283,15 +4283,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{DFC9DE17-3A31-412F-8F77-10A45F86A501}" - "PackageCode" = "8:{5354F88F-7B2C-41B8-8333-6BDD97B1DA2E}" + "ProductCode" = "8:{19B844D1-6434-4C0B-B688-10F2E54094E5}" + "PackageCode" = "8:{87C23B44-6BED-4149-BA41-995EC9878D8C}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.10.159" + "ProductVersion" = "8:1.10.160" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"