From 0f182d2d6d3fd90ffdca34ea84280a68dcb9ce3e Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:21:30 +0200 Subject: [PATCH] Fix over eager function parameter optimiztion --- oscar64/Declaration.cpp | 25 +++++++++++++++++++++ oscar64/Declaration.h | 1 + oscar64/GlobalAnalyzer.cpp | 2 +- oscar64/InterCodeGenerator.cpp | 2 +- oscar64/NativeCodeGenerator.cpp | 37 +++++++++++++++++++++++++++++++- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 +++---- oscar64setup/oscar64setup.vdproj | 6 +++--- 8 files changed, 72 insertions(+), 11 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 7aec82c..0964a8e 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -714,6 +714,11 @@ Declaration* Declaration::ToStriped(int stripe) p = p->mNext; } } + else if (mType == DT_TYPE_ARRAY) + { + ndec->mStride = stripe; + ndec->mBase = mBase->ToStriped(stripe); + } else { ndec->mScope = mScope; @@ -904,6 +909,26 @@ bool Declaration::IsSame(const Declaration* dec) const return false; } +bool Declaration::IsSameValue(const Declaration* dec) const +{ + if (mType != dec->mType || mSize != dec->mSize) + return false; + + switch (mType) + { + case DT_CONST_INTEGER: + return mInteger == dec->mInteger; + case DT_CONST_FLOAT: + return mNumber == dec->mNumber; + case DT_CONST_ADDRESS: + return mInteger == dec->mInteger; + case DT_CONST_POINTER: + return mValue && dec->mValue && mValue->mType == dec->mValue->mType && mValue->mDecValue == dec->mValue->mDecValue; + } + + return false; +} + bool Declaration::CanAssign(const Declaration* fromType) const { if (this->IsSame(fromType)) diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index b18eb16..1841df5 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -211,6 +211,7 @@ public: bool IsSame(const Declaration* dec) const; bool IsSubType(const Declaration* dec) const; bool IsConstSame(const Declaration* dec) const; + bool IsSameValue(const Declaration* dec) const; bool IsIntegerType(void) const; bool IsNumericType(void) const; diff --git a/oscar64/GlobalAnalyzer.cpp b/oscar64/GlobalAnalyzer.cpp index 263e1ae..bc4a5c5 100644 --- a/oscar64/GlobalAnalyzer.cpp +++ b/oscar64/GlobalAnalyzer.cpp @@ -682,7 +682,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo { if (pdec->mFlags & DTF_FPARAM_CONST) { - if (!pex->mDecValue->IsSame(pdec->mValue->mDecValue)) + if (!pex->mDecValue->IsSameValue(pdec->mValue->mDecValue)) { pdec->mFlags |= DTF_FPARAM_NOCONST; pdec->mFlags &= ~DTF_FPARAM_CONST; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 18ae86b..08a0bd3 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1556,7 +1556,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (vl.mType->mFlags & DTF_DEFINED) { int64 index = exp->mRight->mDecValue->mInteger; - if (index < 0 || index * stride >= vl.mType->mSize) + if (index < 0 || index * stride >= vl.mType->mSize * vl.mType->mStripe) mErrors->Error(exp->mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Constant array index out of bounds"); } } diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 2bb61d2..989efec 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -37441,7 +37441,6 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass mIns[i + 4].mType = ASMIT_NOP; mIns[i + 4].mMode = ASMIM_IMPLIED; progress = true; } - #endif } #endif @@ -37490,6 +37489,42 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass mIns[i + 3].mType = ASMIT_NOP; progress = true; } + else if (pass > 8 && + mIns[i + 0].mType == ASMIT_TYA && + mIns[i + 1].mType == ASMIT_CLC && + mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && (mIns[i + 2].mAddress & 0xff) < 4 && + mIns[i + 3].mType == ASMIT_TAY && + !(mIns[i + 3].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C))) + { + int n = mIns[i + 2].mAddress & 0xff; + for (int k = 0; k < n; k++) + { + mIns[i + k].mType = ASMIT_INY; mIns[i + k].mMode = ASMIM_IMPLIED; mIns[i + k].mLive |= LIVE_CPU_REG_Y; + } + for (int k = n; k < 4; k++) + { + mIns[i + k].mType = ASMIT_NOP; mIns[i + k].mMode = ASMIM_IMPLIED; + } + progress = true; + } + else if (pass > 8 && + mIns[i + 0].mType == ASMIT_TXA && + mIns[i + 1].mType == ASMIT_CLC && + mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && (mIns[i + 2].mAddress & 0xff) < 4 && + mIns[i + 3].mType == ASMIT_TAX && + !(mIns[i + 3].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C))) + { + int n = mIns[i + 2].mAddress & 0xff; + for (int k = 0; k < n; k++) + { + mIns[i + k].mType = ASMIT_INX; mIns[i + k].mMode = ASMIM_IMPLIED; mIns[i + k].mLive |= LIVE_CPU_REG_X; + } + for (int k = n; k < 4; k++) + { + mIns[i + k].mType = ASMIT_NOP; mIns[i + k].mMode = ASMIM_IMPLIED; + } + progress = true; + } } CheckLive(); diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 1355327..3ab051e 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.20.206"); + strcpy(strProductVersion, "1.20.207"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 7b1c606..9f246e0 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,20,206,0 - PRODUCTVERSION 1,20,206,0 + FILEVERSION 1,20,207,0 + PRODUCTVERSION 1,20,207,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.20.206.0" + VALUE "FileVersion", "1.20.207.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.20.206.0" + VALUE "ProductVersion", "1.20.207.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index 4d5c760..a233cab 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -5233,15 +5233,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{238E4EBC-D891-4E22-9F93-39D885860A68}" - "PackageCode" = "8:{2D672B29-2FA7-4586-B7DB-C19817A075E8}" + "ProductCode" = "8:{FEED3AD1-30EE-4FD2-954E-A54FFC19B2ED}" + "PackageCode" = "8:{88265E1D-B2B8-4C78-A582-11E0B0CF7FB7}" "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.20.206" + "ProductVersion" = "8:1.20.207" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"