diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 06169a6..0562e1e 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -1,6 +1,8 @@ #include "NativeCodeGenerator.h" #include "CompilerTypes.h" +#define JUMP_TO_BRANCH 1 + static bool CheckFunc; static bool CheckCase; @@ -4504,7 +4506,7 @@ int NativeCodeBasicBlock::PutJump(NativeCodeProcedure* proc, NativeCodeBasicBloc return 1; } } -#if 1 +#if JUMP_TO_BRANCH else if (offset >= -126 && offset <= 129) { if (mNDataSet.mRegs[CPU_REG_C].mMode == NRDM_IMMEDIATE) @@ -4564,7 +4566,7 @@ int NativeCodeBasicBlock::JumpByteSize(NativeCodeBasicBlock* target, int offset) else return 1; } -#if 1 +#if JUMP_TO_BRANCH else if (offset >= -126 && offset <= 129) { if (mNDataSet.mRegs[CPU_REG_C].mMode == NRDM_IMMEDIATE) @@ -13197,10 +13199,16 @@ bool NativeCodeBasicBlock::CombineSameXtoY(int xpos, int ypos, int end) if (xpos < ypos) { if (CanCombineSameXtoY(xpos, ypos) && - CanCombineSameXtoY(ypos, end)) + CanCombineSameXtoY(ypos + 1, end) && + !ReferencesYReg(xpos, ypos)) { ReplaceXRegWithYReg(xpos, ypos); - ReplaceXRegWithYReg(ypos, end); + ReplaceXRegWithYReg(ypos + 1, end); + if (!(mIns[ypos].mLive & LIVE_CPU_REG_Z)) + { + mIns[ypos].mType = ASMIT_NOP; + mIns[ypos].mMode = ASMIM_IMPLIED; + } return true; } } @@ -13209,13 +13217,11 @@ bool NativeCodeBasicBlock::CombineSameXtoY(int xpos, int ypos, int end) if (CanCombineSameXtoY(xpos, end)) { ReplaceXRegWithYReg(xpos, end); -#if 0 if (!(mIns[xpos].mLive & LIVE_CPU_REG_Z)) { mIns[xpos].mType = ASMIT_NOP; mIns[xpos].mMode = ASMIM_IMPLIED; } -#endif return true; } } @@ -13228,10 +13234,16 @@ bool NativeCodeBasicBlock::CombineSameYtoX(int xpos, int ypos, int end) if (ypos < xpos) { if (CanCombineSameYtoX(ypos, xpos) && - CanCombineSameYtoX(xpos + 1, end)) + CanCombineSameYtoX(xpos + 1, end) && + !ReferencesXReg(ypos, xpos)) { ReplaceYRegWithXReg(ypos, xpos); ReplaceYRegWithXReg(xpos + 1, end); + if (!(mIns[xpos].mLive & LIVE_CPU_REG_Z)) + { + mIns[xpos].mType = ASMIT_NOP; + mIns[xpos].mMode = ASMIM_IMPLIED; + } return true; } } @@ -13240,13 +13252,11 @@ bool NativeCodeBasicBlock::CombineSameYtoX(int xpos, int ypos, int end) if (CanCombineSameYtoX(ypos, end)) { ReplaceYRegWithXReg(ypos, end); -#if 0 if (!(mIns[ypos].mLive & LIVE_CPU_REG_Z)) { mIns[ypos].mType = ASMIT_NOP; mIns[ypos].mMode = ASMIM_IMPLIED; } -#endif return true; } } @@ -19553,8 +19563,10 @@ bool NativeCodeBasicBlock::BypassRegisterConditionBlock(void) for (i = 0; i < cblock->mIns.Size(); i++) cblock->mIns[i].mLive |= LIVE_CPU_REG_Y; - changed = true; - + changed = true; + cblock->mEntryRequiredRegs += CPU_REG_Y; + cblock->mExitRequiredRegs += CPU_REG_Y; + eblock->mEntryRequiredRegs += CPU_REG_Y; CheckLive(); } } @@ -23629,7 +23641,7 @@ bool NativeCodeBasicBlock::Propagate16BitHighSum(void) for (int i = 0; i + 5 < mIns.Size(); i++) { - if (mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && + if (mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && !(mIns[i + 0].mLive & LIVE_MEM) && mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 2].mType == ASMIT_CLC && mIns[i + 3].mType == ASMIT_LDA && mIns[i + 3].mMode == ASMIM_ZERO_PAGE && mIns[i + 3].mAddress == mIns[i + 0].mAddress + 1 && !(mIns[i + 3].mLive & LIVE_MEM) && @@ -27047,8 +27059,13 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc { if (!prevBlock) return OptimizeSimpleLoopInvariant(proc, full); - prevBlock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mIns[i + 0].mAddress)); - prevBlock->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, mIns[i + 1].mAddress)); + + int k = prevBlock->mIns.Size(); + while (k > 0 && (prevBlock->mIns[k - 1].mLive && LIVE_CPU_REG_A)) + k--; + + prevBlock->mIns.Insert(k, NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mIns[i + 0].mAddress)); + prevBlock->mIns.Insert(k + 1, NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, mIns[i + 1].mAddress)); mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED; } } @@ -37410,7 +37427,7 @@ void NativeCodeProcedure::RebuildEntry(void) void NativeCodeProcedure::Optimize(void) { - CheckFunc = !strcmp(mInterProc->mIdent->mString, "tile_draw_p"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "main"); #if 1 int step = 0; @@ -37536,8 +37553,9 @@ void NativeCodeProcedure::Optimize(void) } while (changed); #endif - - + BuildDataFlowSets(); + ResetVisited(); + mEntryBlock->RemoveUnusedResultInstructions(); #if _DEBUG ResetVisited(); @@ -37569,7 +37587,6 @@ void NativeCodeProcedure::Optimize(void) } } - #if 1 if (step == 3) { @@ -37601,6 +37618,7 @@ void NativeCodeProcedure::Optimize(void) if (mEntryBlock->PropagateCommonSubExpression()) changed = true; } + #if 1 if (step > 0) { @@ -37900,10 +37918,18 @@ void NativeCodeProcedure::Optimize(void) if (mEntryBlock->SimplifyDiamond(this)) changed = true; +#if _DEBUG + ResetVisited(); + mEntryBlock->CheckBlocks(); +#endif ResetVisited(); if (mEntryBlock->SimplifyLoopEnd(this)) changed = true; +#if _DEBUG + ResetVisited(); + mEntryBlock->CheckBlocks(); +#endif } #endif @@ -38025,6 +38051,7 @@ void NativeCodeProcedure::Optimize(void) else cnt++; + } while (changed); #if 1 @@ -38071,6 +38098,11 @@ void NativeCodeProcedure::Optimize(void) } } + BuildDataFlowSets(); + ResetVisited(); + if (mEntryBlock->RemoveUnusedResultInstructions()) + changed = true; + #if _DEBUG ResetVisited(); mEntryBlock->CheckBlocks(); diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 500b9b6..9818128 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.17.189"); + strcpy(strProductVersion, "1.17.190"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 2ea9d66..d2e6df5 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,17,189,0 - PRODUCTVERSION 1,17,189,0 + FILEVERSION 1,17,190,0 + PRODUCTVERSION 1,17,190,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.17.189.0" + VALUE "FileVersion", "1.17.190.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.17.189.0" + VALUE "ProductVersion", "1.17.190.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index cdb5b91..8b35ed3 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -5066,15 +5066,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{85311ED7-CC4D-4512-840D-20C87C74DAC0}" - "PackageCode" = "8:{9C4FC9E1-982E-42B2-B9D0-8D5984BC0B2B}" + "ProductCode" = "8:{CE09AF37-F5A2-455C-9AA1-8BAEAE79A777}" + "PackageCode" = "8:{01E6782F-1F11-4C56-A8FA-B82388BF217B}" "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.17.189" + "ProductVersion" = "8:1.17.190" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"