From 4a49456a577ae4a30141fd7cf2d848d0d56f8629 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 9 Oct 2022 13:44:59 +0200 Subject: [PATCH] Improve accu train movement --- oscar64/InterCode.cpp | 62 +++++++++++------- oscar64/NativeCodeGenerator.cpp | 109 ++++++++++++++++++++++++++++--- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 +-- oscar64setup/oscar64setup.vdproj | 6 +- 5 files changed, 147 insertions(+), 40 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 4a4ea5a..af9c49d 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -5780,27 +5780,7 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(const GrowingVariableArray vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND; break; case IA_AND: - if (ins->mSrc[0].mTemp < 0) - { - vr = mLocalValueRange[ins->mSrc[1].mTemp]; - if (ins->mSrc[0].mIntConst >= 0) - { - vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; - vr.mMaxValue = ins->mSrc[0].mIntConst; - vr.mMinValue = 0; - } - } - else if (ins->mSrc[1].mTemp < 0) - { - vr = mLocalValueRange[ins->mSrc[0].mTemp]; - if (ins->mSrc[1].mIntConst >= 0) - { - vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; - vr.mMaxValue = ins->mSrc[1].mIntConst; - vr.mMinValue = 0; - } - } - else if (ins->mSrc[0].IsUnsigned() && ins->mSrc[1].IsUnsigned()) + if (ins->mSrc[0].IsUnsigned() && ins->mSrc[1].IsUnsigned()) { vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; int64 v0 = (ins->mSrc[0].mRange.mMaxValue & BuildLowerBitsMask(ins->mSrc[1].mRange.mMaxValue)); @@ -5808,7 +5788,45 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(const GrowingVariableArray vr.mMaxValue = (v0 > v1) ? v0 : v1; vr.mMinValue = 0; } - else + else if (ins->mSrc[0].mTemp < 0) + { + vr = mLocalValueRange[ins->mSrc[1].mTemp]; + if (ins->mSrc[0].mIntConst >= 0) + { + if (ins->mSrc[1].IsUnsigned()) + { + vr.mMinState = IntegerValueRange::S_BOUND; + vr.mMinValue = 0; + vr.LimitMax(ins->mSrc[0].mIntConst); + } + else + { + vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; + vr.mMaxValue = ins->mSrc[0].mIntConst; + vr.mMinValue = 0; + } + } + } + else if (ins->mSrc[1].mTemp < 0) + { + vr = mLocalValueRange[ins->mSrc[0].mTemp]; + if (ins->mSrc[1].mIntConst >= 0) + { + if (ins->mSrc[0].IsUnsigned()) + { + vr.mMinState = IntegerValueRange::S_BOUND; + vr.mMinValue = 0; + vr.LimitMax(ins->mSrc[1].mIntConst); + } + else + { + vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; + vr.mMaxValue = ins->mSrc[1].mIntConst; + vr.mMinValue = 0; + } + } + } + else vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND; break; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index ff05980..a2f5bbf 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -1031,7 +1031,7 @@ bool NativeCodeInstruction::ReferencesXReg(void) const bool NativeCodeInstruction::ReferencesZeroPage(int address) const { - return UsesZeroPage(address); + return UsesZeroPage(address) || ChangesZeroPage(address); } bool NativeCodeInstruction::ChangesZeroPage(int address) const @@ -1044,6 +1044,8 @@ bool NativeCodeInstruction::ChangesZeroPage(int address) const return true; if (address >= BC_REG_WORK && address < BC_REG_WORK + 8) return true; + if (address >= BC_REG_ADDR && address < BC_REG_ADDR + 4) + return true; if (!(mFlags & NCIF_RUNTIME) || (mFlags & NCIF_FEXEC)) { @@ -1338,6 +1340,16 @@ bool NativeCodeInstruction::MayBeSameAddress(const NativeCodeInstruction& ins, b bool NativeCodeInstruction::MayBeChangedOnAddress(const NativeCodeInstruction& ins, bool sameXY) const { + if (ins.mType == ASMIT_JSR) + { + if (mMode == ASMIM_ZERO_PAGE) + return ins.ChangesZeroPage(mAddress); + else if (mMode == ASMIM_IMPLIED || mMode == ASMIM_IMMEDIATE || mMode == ASMIM_IMMEDIATE_ADDRESS) + return false; + else + return true; + } + if (!ins.ChangesAddress()) return false; @@ -12439,12 +12451,20 @@ bool NativeCodeBasicBlock::MoveAccuTrainDown(int end, int start) return false; if (mIns[j].MayBeChangedOnAddress(mIns[i], true) || mIns[i].MayBeChangedOnAddress(mIns[j], true)) return false; + if (mIns[j].RequiresCarry() && mIns[i].ChangesCarry() || mIns[j].ChangesCarry() && mIns[i].RequiresCarry()) + return false; } if (mIns[i].mType == ASMIT_LDA) { + int live = mIns[i].mLive; + if (mIns[i].RequiresXReg()) + live |= LIVE_CPU_REG_X; + if (mIns[i].RequiresYReg()) + live |= LIVE_CPU_REG_Y; + for (int j = end + 1; j < start; j++) - mIns[j].mLive |= mIns[i].mLive; + mIns[j].mLive |= live; for (int j = end; j >= i; j--) { @@ -12474,18 +12494,22 @@ bool NativeCodeBasicBlock::MoveAccuTrainsDown(void) { mVisited = true; - int apos = -1, addr = -1; + int apos[256]; + + for(int i=0; i<256; i++) + apos[i] = -1; for (int i = 0; i + 1 < mIns.Size(); i++) { if (mIns[i].mType == ASMIT_STA && mIns[i].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C))) { - apos = i; - addr = mIns[i].mAddress; + apos[mIns[i].mAddress] = i; } - else if (addr >= 0 && mIns[i].mType == ASMIT_LDA && mIns[i + 1].IsCommutative() && !(mIns[i + 1].RequiresCarry()) && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress == addr) + else if (mIns[i].mType == ASMIT_LDA && mIns[i + 1].IsCommutative() && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && apos[mIns[i + 1].mAddress] >= 0 && HasAsmInstructionMode(mIns[i + 1].mType, mIns[i].mMode)) { - if (MoveAccuTrainDown(apos, i)) + int addr = mIns[i + 1].mAddress; + + if (MoveAccuTrainDown(apos[addr], i)) { if (mIns[i].RequiresXReg()) mIns[i].mLive |= LIVE_CPU_REG_X; @@ -12495,11 +12519,70 @@ bool NativeCodeBasicBlock::MoveAccuTrainsDown(void) mIns[i + 1].CopyMode(mIns[i]); mIns[i] = NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, addr); changed = true; + + for (int j = 0; j < 256; j++) + apos[j] = -1; } } - else if (addr >= 0 && mIns[i].ReferencesZeroPage(addr)) + else if (mIns[i].mType == ASMIT_LDA && mIns[i].mMode == ASMIM_ZERO_PAGE && apos[mIns[i].mAddress] >= 0) { - addr = -1; + int addr = mIns[i].mAddress; + + if (MoveAccuTrainDown(apos[addr], i)) + { + if (mIns[i].RequiresXReg()) + mIns[i].mLive |= LIVE_CPU_REG_X; + if (mIns[i].RequiresYReg()) + mIns[i].mLive |= LIVE_CPU_REG_Y; + + changed = true; + + for (int j = 0; j < 256; j++) + apos[j] = -1; + } + } + else if (i + 2 < mIns.Size() && mIns[i].mType == ASMIT_LDA && mIns[i + 1].mType == ASMIT_CLC && + mIns[i + 2].IsCommutative() && mIns[i + 2].mMode == ASMIM_ZERO_PAGE && apos[mIns[i + 2].mAddress] >= 0 && HasAsmInstructionMode(mIns[i + 2].mType, mIns[i].mMode)) + { + int addr = mIns[i + 2].mAddress; + + if (MoveAccuTrainDown(apos[addr], i)) + { + if (mIns[i].RequiresXReg()) + { + mIns[i].mLive |= LIVE_CPU_REG_X; + mIns[i + 1].mLive |= LIVE_CPU_REG_X; + } + if (mIns[i].RequiresYReg()) + { + mIns[i].mLive |= LIVE_CPU_REG_Y; + mIns[i + 1].mLive |= LIVE_CPU_REG_Y; + } + + mIns[i + 2].CopyMode(mIns[i]); + mIns[i] = NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, addr); + changed = true; + + for (int j = 0; j < 256; j++) + apos[j] = -1; + } + } + else if (mIns[i].mMode == ASMIM_ZERO_PAGE) + { + apos[mIns[i].mAddress] = -1; + } + else if (mIns[i].mMode == ASMIM_INDIRECT_Y) + { + apos[mIns[i].mAddress] = -1; + apos[mIns[i].mAddress + 1] = -1; + } + else if (mIns[i].mType == ASMIT_JSR) + { + for (int j = 0; j < 256; j++) + { + if (apos[j] >= 0 && mIns[i].ReferencesZeroPage(j)) + apos[j] = -1; + } } } @@ -30571,6 +30654,12 @@ void NativeCodeProcedure::Optimize(void) #if 1 if (step >= 4) { + if (step == 8) + { + ResetVisited(); + mEntryBlock->ReduceLocalYPressure(); + } + ResetVisited(); if (mEntryBlock->MoveAccuTrainsUp()) changed = true; @@ -30663,7 +30752,7 @@ void NativeCodeProcedure::Optimize(void) } #if 1 - if (!changed && step < 8) + if (!changed && step < 9) { cnt = 0; step++; diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 15310b5..884e939 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.163"); + strcpy(strProductVersion, "1.10.164"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 6cc48c0..ddb945c 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,163,0 - PRODUCTVERSION 1,10,163,0 + FILEVERSION 1,10,164,0 + PRODUCTVERSION 1,10,164,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.10.163.0" + VALUE "FileVersion", "1.10.164.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.10.163.0" + VALUE "ProductVersion", "1.10.164.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index f4f0704..bcf689d 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -4283,15 +4283,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{DC8BA477-B3C1-421D-87A5-7A72F7F7329E}" - "PackageCode" = "8:{7C245B88-A203-4534-8DFE-82D241F807D6}" + "ProductCode" = "8:{BD8162B1-0E46-49AE-B175-3744635D30CB}" + "PackageCode" = "8:{C35B4B0B-03DD-4A60-A44F-6A3EFA3204B4}" "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.163" + "ProductVersion" = "8:1.10.164" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"