Improve accu train movement

This commit is contained in:
drmortalwombat 2022-10-09 13:44:59 +02:00
parent bd32b38027
commit 4a49456a57
5 changed files with 147 additions and 40 deletions

View File

@ -5780,14 +5780,31 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(const GrowingVariableArray
vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND; vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND;
break; break;
case IA_AND: case IA_AND:
if (ins->mSrc[0].mTemp < 0) 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));
int64 v1 = (ins->mSrc[1].mRange.mMaxValue & BuildLowerBitsMask(ins->mSrc[0].mRange.mMaxValue));
vr.mMaxValue = (v0 > v1) ? v0 : v1;
vr.mMinValue = 0;
}
else if (ins->mSrc[0].mTemp < 0)
{ {
vr = mLocalValueRange[ins->mSrc[1].mTemp]; vr = mLocalValueRange[ins->mSrc[1].mTemp];
if (ins->mSrc[0].mIntConst >= 0) if (ins->mSrc[0].mIntConst >= 0)
{ {
vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; if (ins->mSrc[1].IsUnsigned())
vr.mMaxValue = ins->mSrc[0].mIntConst; {
vr.mMinValue = 0; 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) else if (ins->mSrc[1].mTemp < 0)
@ -5795,19 +5812,20 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(const GrowingVariableArray
vr = mLocalValueRange[ins->mSrc[0].mTemp]; vr = mLocalValueRange[ins->mSrc[0].mTemp];
if (ins->mSrc[1].mIntConst >= 0) if (ins->mSrc[1].mIntConst >= 0)
{ {
vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; if (ins->mSrc[0].IsUnsigned())
vr.mMaxValue = ins->mSrc[1].mIntConst; {
vr.mMinValue = 0; 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 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));
int64 v1 = (ins->mSrc[1].mRange.mMaxValue & BuildLowerBitsMask(ins->mSrc[0].mRange.mMaxValue));
vr.mMaxValue = (v0 > v1) ? v0 : v1;
vr.mMinValue = 0;
}
else else
vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND; vr.mMaxState = vr.mMinState = IntegerValueRange::S_UNBOUND;
break; break;

View File

@ -1031,7 +1031,7 @@ bool NativeCodeInstruction::ReferencesXReg(void) const
bool NativeCodeInstruction::ReferencesZeroPage(int address) const bool NativeCodeInstruction::ReferencesZeroPage(int address) const
{ {
return UsesZeroPage(address); return UsesZeroPage(address) || ChangesZeroPage(address);
} }
bool NativeCodeInstruction::ChangesZeroPage(int address) const bool NativeCodeInstruction::ChangesZeroPage(int address) const
@ -1044,6 +1044,8 @@ bool NativeCodeInstruction::ChangesZeroPage(int address) const
return true; return true;
if (address >= BC_REG_WORK && address < BC_REG_WORK + 8) if (address >= BC_REG_WORK && address < BC_REG_WORK + 8)
return true; return true;
if (address >= BC_REG_ADDR && address < BC_REG_ADDR + 4)
return true;
if (!(mFlags & NCIF_RUNTIME) || (mFlags & NCIF_FEXEC)) 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 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()) if (!ins.ChangesAddress())
return false; return false;
@ -12439,12 +12451,20 @@ bool NativeCodeBasicBlock::MoveAccuTrainDown(int end, int start)
return false; return false;
if (mIns[j].MayBeChangedOnAddress(mIns[i], true) || mIns[i].MayBeChangedOnAddress(mIns[j], true)) if (mIns[j].MayBeChangedOnAddress(mIns[i], true) || mIns[i].MayBeChangedOnAddress(mIns[j], true))
return false; return false;
if (mIns[j].RequiresCarry() && mIns[i].ChangesCarry() || mIns[j].ChangesCarry() && mIns[i].RequiresCarry())
return false;
} }
if (mIns[i].mType == ASMIT_LDA) 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++) 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--) for (int j = end; j >= i; j--)
{ {
@ -12474,18 +12494,22 @@ bool NativeCodeBasicBlock::MoveAccuTrainsDown(void)
{ {
mVisited = true; 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++) 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))) 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; apos[mIns[i].mAddress] = i;
addr = mIns[i].mAddress;
} }
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()) if (mIns[i].RequiresXReg())
mIns[i].mLive |= LIVE_CPU_REG_X; mIns[i].mLive |= LIVE_CPU_REG_X;
@ -12495,11 +12519,70 @@ bool NativeCodeBasicBlock::MoveAccuTrainsDown(void)
mIns[i + 1].CopyMode(mIns[i]); mIns[i + 1].CopyMode(mIns[i]);
mIns[i] = NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, addr); mIns[i] = NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, addr);
changed = true; 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 1
if (step >= 4) if (step >= 4)
{ {
if (step == 8)
{
ResetVisited();
mEntryBlock->ReduceLocalYPressure();
}
ResetVisited(); ResetVisited();
if (mEntryBlock->MoveAccuTrainsUp()) if (mEntryBlock->MoveAccuTrainsUp())
changed = true; changed = true;
@ -30663,7 +30752,7 @@ void NativeCodeProcedure::Optimize(void)
} }
#if 1 #if 1
if (!changed && step < 8) if (!changed && step < 9)
{ {
cnt = 0; cnt = 0;
step++; step++;

View File

@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.10.163"); strcpy(strProductVersion, "1.10.164");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,10,163,0 FILEVERSION 1,10,164,0
PRODUCTVERSION 1,10,163,0 PRODUCTVERSION 1,10,164,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.10.163.0" VALUE "FileVersion", "1.10.164.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.10.163.0" VALUE "ProductVersion", "1.10.164.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -4283,15 +4283,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{DC8BA477-B3C1-421D-87A5-7A72F7F7329E}" "ProductCode" = "8:{BD8162B1-0E46-49AE-B175-3744635D30CB}"
"PackageCode" = "8:{7C245B88-A203-4534-8DFE-82D241F807D6}" "PackageCode" = "8:{C35B4B0B-03DD-4A60-A44F-6A3EFA3204B4}"
"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.10.163" "ProductVersion" = "8:1.10.164"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"