Move accu eval trains up to connect them

This commit is contained in:
drmortalwombat 2022-07-23 14:12:11 +02:00
parent 67142bdb01
commit f9f2516a65
7 changed files with 198 additions and 15 deletions

View File

@ -608,7 +608,17 @@ static int64 ConstantFolding(InterOperator oper, InterType type, int64 val1, int
return -val1; return -val1;
break; break;
case IA_NOT: case IA_NOT:
switch (type)
{
case IT_INT8:
return uint8(~val1);
case IT_INT16:
return uint16(~val1);
case IT_INT32:
return uint32(~val1);
default:
return ~val1; return ~val1;
}
break; break;
case IA_SHL: case IA_SHL:
return val1 << val2; return val1 << val2;
@ -777,6 +787,20 @@ static void ConversionConstantFold(InterInstruction * ins, const InterOperand &
ins->mSrc[0].mTemp = -1; ins->mSrc[0].mTemp = -1;
ins->mNumOperands = 0; ins->mNumOperands = 0;
break; break;
case IA_EXT8TO32S:
ins->mCode = IC_CONSTANT;
ins->mConst.mIntConst = (int8)(cop.mIntConst);
ins->mConst.mType = IT_INT32;
ins->mSrc[0].mTemp = -1;
ins->mNumOperands = 0;
break;
case IA_EXT8TO32U:
ins->mCode = IC_CONSTANT;
ins->mConst.mIntConst = (uint8)(cop.mIntConst);
ins->mConst.mType = IT_INT32;
ins->mSrc[0].mTemp = -1;
ins->mNumOperands = 0;
break;
} }
} }
@ -3406,7 +3430,7 @@ bool InterInstruction::ConstantFolding(void)
if (mDst.mType == IT_FLOAT) if (mDst.mType == IT_FLOAT)
mConst.mFloatConst = ::ConstantFolding(mOperator, mSrc[0].mFloatConst); mConst.mFloatConst = ::ConstantFolding(mOperator, mSrc[0].mFloatConst);
else else
mConst.mIntConst = ::ConstantFolding(mOperator, mSrc[0].mIntConst); mConst.mIntConst = ::ConstantFolding(mOperator, mDst.mType, mSrc[0].mIntConst);
mNumOperands = 0; mNumOperands = 0;
return true; return true;
} }
@ -11107,6 +11131,53 @@ void InterCodeBasicBlock::PeepholeOptimization(const GrowingVariableArray& stati
changed = true; changed = true;
} }
#endif #endif
#if 1
else if (
mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mOperator == IA_SHR && mInstructions[i + 0]->mSrc[0].mTemp < 0 &&
mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 1]->mOperator == IA_SHL && mInstructions[i + 1]->mSrc[0].mTemp < 0 &&
mInstructions[i + 1]->mSrc[1].mTemp == mInstructions[i + 0]->mDst.mTemp && mInstructions[i + 1]->mSrc[1].mFinal)
{
int shift = mInstructions[i + 0]->mSrc[0].mIntConst;
int mshift = mInstructions[i + 1]->mSrc[0].mIntConst;
mInstructions[i + 0]->mOperator = IA_AND;
mInstructions[i + 0]->mSrc[0].mType = IT_INT16;
mInstructions[i + 0]->mSrc[0].mType = mInstructions[i + 1]->mSrc[0].mType;
switch (mInstructions[i + 0]->mSrc[0].mType)
{
case IT_INT8:
mInstructions[i + 0]->mSrc[0].mIntConst = (0xffu >> shift) << shift;
break;
case IT_INT16:
mInstructions[i + 0]->mSrc[0].mIntConst = (0xffffu >> shift) << shift;
break;
case IT_INT32:
mInstructions[i + 0]->mSrc[0].mIntConst = (0xffffffffu >> shift) << shift;
break;
}
if (shift > mshift)
{
mInstructions[i + 1]->mOperator = IA_SHR;
mInstructions[i + 1]->mSrc[0].mIntConst = shift - mshift;
}
else if (shift < mshift)
{
mInstructions[i + 1]->mOperator = IA_SHL;
mInstructions[i + 1]->mSrc[0].mIntConst = mshift - shift;
}
else
{
mInstructions[i + 0]->mDst = mInstructions[i + 1]->mDst;
mInstructions[i + 1]->mCode = IC_NONE;
mInstructions[i + 1]->mNumOperands = 0;
}
changed = true;
}
#endif
#if 1 #if 1
else if ( else if (
mInstructions[i + 0]->mCode == IC_LOAD_TEMPORARY && mInstructions[i + 0]->mCode == IC_LOAD_TEMPORARY &&

View File

@ -1163,7 +1163,7 @@ bool NativeCodeInstruction::MayBeSameAddress(const NativeCodeInstruction& ins, b
return false; return false;
} }
bool NativeCodeInstruction::MayBeChangedOnAddress(const NativeCodeInstruction& ins) const bool NativeCodeInstruction::MayBeChangedOnAddress(const NativeCodeInstruction& ins, bool sameXY) const
{ {
if (!ins.ChangesAddress()) if (!ins.ChangesAddress())
return false; return false;
@ -1195,7 +1195,12 @@ bool NativeCodeInstruction::MayBeChangedOnAddress(const NativeCodeInstruction& i
else if (ins.mMode == ASMIM_ABSOLUTE_X || ins.mMode == ASMIM_ABSOLUTE_Y) else if (ins.mMode == ASMIM_ABSOLUTE_X || ins.mMode == ASMIM_ABSOLUTE_Y)
{ {
if (mMode == ASMIM_ABSOLUTE || mMode == ASMIM_ABSOLUTE_X || mMode == ASMIM_ABSOLUTE_Y) if (mMode == ASMIM_ABSOLUTE || mMode == ASMIM_ABSOLUTE_X || mMode == ASMIM_ABSOLUTE_Y)
return mLinkerObject == ins.mLinkerObject; {
if (mLinkerObject != ins.mLinkerObject)
return false;
else
return mMode != ins.mMode || !sameXY || mAddress == ins.mAddress;
}
else if (mMode == ASMIM_INDIRECT_Y || mMode == ASMIM_INDIRECT_X) else if (mMode == ASMIM_INDIRECT_Y || mMode == ASMIM_INDIRECT_X)
return mAddress != BC_REG_STACK; return mAddress != BC_REG_STACK;
else else
@ -7097,6 +7102,35 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 3)); mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 3));
} }
} }
else if (shift == 2)
{
if (sreg != treg)
{
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg));
mIns.Push(NativeCodeInstruction(ASMIT_ASL, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 3));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 3));
}
else
{
mIns.Push(NativeCodeInstruction(ASMIT_ASL, ASMIM_ZERO_PAGE, treg));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 3));
}
mIns.Push(NativeCodeInstruction(ASMIT_ASL, ASMIM_ZERO_PAGE, treg));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROL, ASMIM_ZERO_PAGE, treg + 3));
}
else else
{ {
NativeCodeBasicBlock* lblock = nproc->AllocateBlock(); NativeCodeBasicBlock* lblock = nproc->AllocateBlock();
@ -7270,6 +7304,35 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 0)); mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 0));
} }
} }
else if (shift == 2)
{
if (sreg != treg)
{
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 3));
mIns.Push(NativeCodeInstruction(ASMIT_LSR, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 3));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, sreg + 0));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_IMPLIED));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 0));
}
else
{
mIns.Push(NativeCodeInstruction(ASMIT_LSR, ASMIM_ZERO_PAGE, treg + 3));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 0));
}
mIns.Push(NativeCodeInstruction(ASMIT_LSR, ASMIM_ZERO_PAGE, treg + 3));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 2));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 1));
mIns.Push(NativeCodeInstruction(ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 0));
}
else else
{ {
NativeCodeBasicBlock* lblock = nproc->AllocateBlock(); NativeCodeBasicBlock* lblock = nproc->AllocateBlock();
@ -11836,7 +11899,7 @@ bool NativeCodeBasicBlock::MoveAccuTrainUp(int at, int end)
return false; return false;
if (mIns[j].RequiresYReg() && mIns[i].ChangesYReg() || mIns[j].ChangesYReg() && mIns[i].RequiresYReg()) if (mIns[j].RequiresYReg() && mIns[i].ChangesYReg() || mIns[j].ChangesYReg() && mIns[i].RequiresYReg())
return false; return false;
if (mIns[j].MayBeChangedOnAddress(mIns[i]) || mIns[i].MayBeChangedOnAddress(mIns[j])) if (mIns[j].MayBeChangedOnAddress(mIns[i], true) || mIns[i].MayBeChangedOnAddress(mIns[j], true))
return false; return false;
} }
} }
@ -16490,6 +16553,23 @@ bool NativeCodeBasicBlock::MoveAbsoluteLoadStoreUp(int at)
mIns[at + 2].mMode = ASMIM_IMPLIED; mIns[at + 2].mMode = ASMIM_IMPLIED;
return true; return true;
} }
else if (mIns[j].mType == ASMIT_LDA && mIns[j].mMode == ASMIM_ZERO_PAGE && mIns[j].mAddress == mIns[at].mAddress)
{
while (j < at && !mIns[j + 1].ChangesAccu() && (mIns[j].mLive & LIVE_CPU_REG_A))
j++;
if (j < at)
{
mIns[j].mLive |= LIVE_CPU_REG_A;
mIns.Insert(j + 1, mIns[at + 1]);
mIns[j + 1].mLive |= LIVE_CPU_REG_A;
mIns[j + 1].mLive |= mIns[j].mLive;
mIns[at + 2].mType = ASMIT_NOP;
mIns[at + 2].mMode = ASMIM_IMPLIED;
return true;
}
else
return false;
}
if (mIns[j].ChangesZeroPage(mIns[at].mAddress)) if (mIns[j].ChangesZeroPage(mIns[at].mAddress))
return false; return false;
if (mIns[j].MayBeSameAddress(mIns[at + 1], true)) if (mIns[j].MayBeSameAddress(mIns[at + 1], true))
@ -25356,6 +25436,34 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
} }
} }
#endif
#if 1
if (pass == 0 &&
mIns[i + 0].mType == ASMIT_CLC &&
mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_IMMEDIATE &&
mIns[i + 2].mType == ASMIT_ADC &&
mIns[i + 3].mType == ASMIT_STA && mIns[i + 3].mMode == ASMIM_ZERO_PAGE &&
mIns[i + 4].mType == ASMIT_LDA && mIns[i + 4].mMode == ASMIM_IMMEDIATE &&
mIns[i + 5].mType == ASMIT_ADC && mIns[i + 5].mMode == ASMIM_IMMEDIATE && mIns[i + 5].mAddress == 0 &&
mIns[i + 6].mType == ASMIT_STA && mIns[i + 6].mMode == ASMIM_ZERO_PAGE && mIns[i + 6].mAddress == mIns[i + 3].mAddress + 1 &&
!(mIns[i + 6].mLive & LIVE_CPU_REG_A))
{
proc->ResetPatched();
if (CheckGlobalAddressSumYPointer(this, mIns[i + 3].mAddress, i + 7, -1))
{
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED;
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
mIns[i + 2].mType = ASMIT_LDA;
mIns[i + 4].mType = ASMIT_NOP; mIns[i + 4].mMode = ASMIM_IMPLIED;
mIns[i + 5].mType = ASMIT_NOP; mIns[i + 5].mMode = ASMIM_IMPLIED;
mIns[i + 6].mType = ASMIT_NOP; mIns[i + 6].mMode = ASMIM_IMPLIED;
proc->ResetPatched();
if (PatchGlobalAddressSumYPointer(this, mIns[i + 3].mAddress, i + 7, -1, nullptr, mIns[i + 1].mAddress + 256 * mIns[i + 4].mAddress))
progress = true;
}
}
#endif #endif
#if 0 #if 0

View File

@ -127,7 +127,7 @@ public:
bool ChangesGlobalMemory(void) const; bool ChangesGlobalMemory(void) const;
bool UsesMemoryOf(const NativeCodeInstruction& ins) const; bool UsesMemoryOf(const NativeCodeInstruction& ins) const;
bool SameEffectiveAddress(const NativeCodeInstruction& ins) const; bool SameEffectiveAddress(const NativeCodeInstruction& ins) const;
bool MayBeChangedOnAddress(const NativeCodeInstruction& ins) const; bool MayBeChangedOnAddress(const NativeCodeInstruction& ins, bool sameXY = false) const;
bool MayBeSameAddress(const NativeCodeInstruction& ins, bool sameXY = false) const; bool MayBeSameAddress(const NativeCodeInstruction& ins, bool sameXY = false) const;
bool IsSame(const NativeCodeInstruction& ins) const; bool IsSame(const NativeCodeInstruction& ins) const;
bool IsCommutative(void) const; bool IsCommutative(void) const;

View File

@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.7.148"); strcpy(strProductVersion, "1.7.149");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);
@ -303,15 +303,17 @@ int main2(int argc, const char** argv)
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
#if 1
#ifdef _WIN32 #ifdef _WIN32
#ifndef _DEBUG #ifndef _DEBUG
__try __try
{ {
#endif #endif
#endif #endif
#endif
return main2(argc, argv); return main2(argc, argv);
#if 1
#ifdef _WIN32 #ifdef _WIN32
#ifndef _DEBUG #ifndef _DEBUG
} }
@ -322,4 +324,5 @@ int main(int argc, const char** argv)
} }
#endif #endif
#endif #endif
#endif
} }

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,7,148,0 FILEVERSION 1,7,149,0
PRODUCTVERSION 1,7,148,0 PRODUCTVERSION 1,7,149,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "oscar64" VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler" VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.7.148.0" VALUE "FileVersion", "1.7.149.0"
VALUE "InternalName", "oscar64.exe" VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe" VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64" VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.7.148.0" VALUE "ProductVersion", "1.7.149.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -111,6 +111,7 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<StackReserveSize>16000000</StackReserveSize>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy $(TargetPath) $(SolutionDir)bin</Command> <Command>copy $(TargetPath) $(SolutionDir)bin</Command>

View File

@ -4231,15 +4231,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{142E4BF0-B9DB-47DB-9EA2-FF3404EFD5D0}" "ProductCode" = "8:{7C4429C0-F5A0-4041-9049-DA5A6CB331BF}"
"PackageCode" = "8:{C2449794-2B3A-435B-9211-ED0ED63EAEB7}" "PackageCode" = "8:{0CF4448C-B1E3-4471-A7D8-9929B12A24C4}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0" "AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.7.148" "ProductVersion" = "8:1.7.149"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"