Skip to content

Commit

Permalink
Bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Sep 24, 2022
1 parent 03be76f commit 121f047
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 23 deletions.
115 changes: 113 additions & 2 deletions oscar64/InterCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7107,6 +7107,92 @@ bool InterCodeBasicBlock::MergeIndexedLoadStore(const GrowingInstructionPtrArra
return changed;
}

static bool CheckSimplifyPointerOffsets(const InterInstruction* ins, int temp, int& mino, int& maxo)
{
if (ins->mDst.mTemp == temp)
return false;

if (ins->mCode == IC_LOAD && ins->mSrc[0].mTemp == temp)
{
if (ins->mSrc[0].mIntConst < mino)
mino = ins->mSrc[0].mIntConst;
if (ins->mSrc[0].mIntConst > maxo)
maxo = ins->mSrc[0].mIntConst;

return true;
}

if (ins->mCode == IC_STORE && ins->mSrc[1].mTemp == temp)
{
if (ins->mSrc[0].mTemp == temp)
return false;

if (ins->mSrc[1].mIntConst < mino)
mino = ins->mSrc[1].mIntConst;
if (ins->mSrc[1].mIntConst > maxo)
maxo = ins->mSrc[1].mIntConst;

return true;
}

for (int i = 0; i < ins->mNumOperands; i++)
if (ins->mSrc[i].mTemp == temp)
return false;

return true;
}

bool InterCodeBasicBlock::SimplifyPointerOffsets(void)
{
bool changed = false;

if (!mVisited)
{
mVisited = true;

for (int i = 0; i < mInstructions.Size(); i++)
{
InterInstruction* ins = mInstructions[i];

if (ins->mCode == IC_LEA && (ins->mSrc[0].mTemp < 0 || ins->mSrc[1].mTemp < 0) && !mExitRequiredTemps[ins->mDst.mTemp])
{
int minoffset = 65535, maxoffset = -65535;

int j = i + 1;
while (j < mInstructions.Size() && CheckSimplifyPointerOffsets(mInstructions[j], ins->mDst.mTemp, minoffset, maxoffset))
j++;

if (j == mInstructions.Size() && (minoffset < 0 || maxoffset > 255) && maxoffset - minoffset < 256)
{
if (ins->mSrc[0].mTemp < 0)
ins->mSrc[0].mIntConst += minoffset;
else
ins->mSrc[1].mIntConst += minoffset;

changed = true;

for (int j = i + 1; j < mInstructions.Size(); j++)
{
InterInstruction* tins = mInstructions[j];
if (tins->mCode == IC_LOAD && tins->mSrc[0].mTemp == ins->mDst.mTemp)
tins->mSrc[0].mIntConst -= minoffset;
else if (tins->mCode == IC_STORE && tins->mSrc[1].mTemp == ins->mDst.mTemp)
tins->mSrc[1].mIntConst -= minoffset;
}
}
}
}

if (mTrueJump && mTrueJump->SimplifyPointerOffsets())
changed = true;
if (mFalseJump && mFalseJump->SimplifyPointerOffsets())
changed = true;
}

return true;
}


bool InterCodeBasicBlock::SimplifyIntegerNumeric(const GrowingInstructionPtrArray& tvalue, int& spareTemps)
{
bool changed = false;
Expand Down Expand Up @@ -12410,6 +12496,11 @@ void InterCodeProcedure::MergeIndexedLoadStore(void)
RemoveUnusedInstructions();

DisassembleDebug("MergeIndexedLoadStore");

ResetVisited();
mEntryBlock->SimplifyPointerOffsets();

DisassembleDebug("SimplifyPointerOffsets");
}

void InterCodeProcedure::SimplifyIntegerNumeric(FastNumberSet& activeSet)
Expand Down Expand Up @@ -13199,10 +13290,10 @@ bool InterCodeBasicBlock::SameExitCode(const InterCodeBasicBlock* block) const
{
if (ins0->mCode == IC_STORE && ins0->mSrc[1].mTemp >= 0)
{
int j0 = mInstructions.Size() - 2;
int j0 = mInstructions.Size() - 3;
while (j0 >= 0 && mInstructions[j0]->mDst.mTemp != ins0->mSrc[1].mTemp)
j0--;
int j1 = block->mInstructions.Size() - 2;
int j1 = block->mInstructions.Size() - 3;
while (j1 >= 0 && block->mInstructions[j1]->mDst.mTemp != ins0->mSrc[1].mTemp)
j1--;

Expand All @@ -13217,6 +13308,26 @@ bool InterCodeBasicBlock::SameExitCode(const InterCodeBasicBlock* block) const
}
}
}
else if (ins0->mCode == IC_LOAD && ins0->mSrc[0].mTemp >= 0)
{
int j0 = mInstructions.Size() - 3;
while (j0 >= 0 && mInstructions[j0]->mDst.mTemp != ins0->mSrc[0].mTemp)
j0--;
int j1 = block->mInstructions.Size() - 3;
while (j1 >= 0 && block->mInstructions[j1]->mDst.mTemp != ins0->mSrc[0].mTemp)
j1--;

if (j0 >= 0 && j1 >= 0)
{
if (!(mInstructions[j0]->IsEqual(block->mInstructions[j1])))
{
if (mInstructions[j0]->mCode == IC_LEA && mInstructions[j0]->mSrc[1].mTemp < 0)
return false;
if (block->mInstructions[j1]->mCode == IC_LEA && mInstructions[j1]->mSrc[1].mTemp < 0)
return false;
}
}
}

return true;
}
Expand Down
1 change: 1 addition & 0 deletions oscar64/InterCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class InterCodeBasicBlock

bool MergeIndexedLoadStore(const GrowingInstructionPtrArray& tvalue);
bool SimplifyIntegerNumeric(const GrowingInstructionPtrArray& tvalue, int& spareTemps);
bool SimplifyPointerOffsets(void);
bool EliminateAliasValues(const GrowingInstructionPtrArray& tvalue, const GrowingInstructionPtrArray& avalue);

bool CalculateSingleAssignmentTemps(FastNumberSet& tassigned, GrowingInstructionPtrArray& tvalue, NumberSet& modifiedParams, InterMemory paramMemory);
Expand Down
160 changes: 147 additions & 13 deletions oscar64/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,14 +3088,14 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data, AsmInsT
mMode = ASMIM_IMMEDIATE;
changed = true;
}
else if (data.mRegs[CPU_REG_A].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_A].mValue == mAddress)
else if (final && data.mRegs[CPU_REG_A].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_A].mValue == mAddress)
{
mType = ASMIT_TAY;
mMode = ASMIM_IMPLIED;
data.mRegs[CPU_REG_Y] = data.mRegs[CPU_REG_A];
changed = true;
}
else if (data.mRegs[mAddress].SameData(data.mRegs[CPU_REG_A]))
else if (final && data.mRegs[mAddress].SameData(data.mRegs[CPU_REG_A]))
{
mType = ASMIT_TAY;
mMode = ASMIM_IMPLIED;
Expand Down Expand Up @@ -10053,6 +10053,59 @@ void NativeCodeBasicBlock::RelationalOperator(InterCodeProcedure* proc, const In
this->Close(falseJump, trueJump, ASMIT_BEQ);
}
#endif
else if (ins->mSrc[0].IsUByte() && ins->mSrc[1].IsUByte())
{
NativeCodeBasicBlock* eblock = nproc->AllocateBlock();
NativeCodeBasicBlock* nblock = nproc->AllocateBlock();

int li = 1, ri = 0;
if (op == IA_CMPLEU || op == IA_CMPGU || op == IA_CMPLES || op == IA_CMPGS)
{
li = 0; ri = 1;
}

int iconst = 0;
bool rconst = false;

if (ins->mSrc[ri].mTemp < 0)
{
iconst = ins->mSrc[ri].mIntConst;
rconst = true;
}

if (ins->mSrc[li].mTemp < 0)
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[li].mIntConst & 0xff));
else
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[li].mTemp]));
if (rconst)
mIns.Push(NativeCodeInstruction(ASMIT_CMP, ASMIM_IMMEDIATE, iconst & 0xff));
else
mIns.Push(NativeCodeInstruction(ASMIT_CMP, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[ri].mTemp]));

switch (op)
{
case IA_CMPEQ:
this->Close(trueJump, falseJump, ASMIT_BEQ);
break;
case IA_CMPNE:
this->Close(falseJump, trueJump, ASMIT_BEQ);
break;
case IA_CMPLU:
case IA_CMPLS:
case IA_CMPGU:
case IA_CMPGS:
this->Close(trueJump, falseJump, ASMIT_BCC);
break;
case IA_CMPLEU:
case IA_CMPLES:
case IA_CMPGEU:
case IA_CMPGES:
this->Close(falseJump, trueJump, ASMIT_BCC);
break;

}

}
else
{
NativeCodeBasicBlock* eblock = nproc->AllocateBlock();
Expand Down Expand Up @@ -14344,8 +14397,14 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void)
#endif


if (mTrueJump && mFalseJump && mTrueJump->mNumEntries == 1 && mFalseJump->mNumEntries == 1)
if (mTrueJump && mFalseJump)
{
uint32 live = 0;
if (mExitRequiredRegs[CPU_REG_X])
live |= LIVE_CPU_REG_X;
if (mExitRequiredRegs[CPU_REG_Y])
live |= LIVE_CPU_REG_Y;

int i = 0;
while (i < mIns.Size())
{
Expand All @@ -14358,14 +14417,9 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void)
if (!ReferencedOnPath(this, i + 2, mIns.Size(), mIns[i + 1].mAddress) &&
!ChangedOnPath(this, i + 2, mIns.Size(), mIns[i + 0].mAddress))
{
uint32 live = 0;
if (mExitRequiredRegs[CPU_REG_X])
live |= LIVE_CPU_REG_X;
if (mExitRequiredRegs[CPU_REG_Y])
live |= LIVE_CPU_REG_Y;

if (mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress] &&
!mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress])
!mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress] &&
mTrueJump->mNumEntries == 1)
{
for (int j = 0; j < 2; j++)
{
Expand All @@ -14376,7 +14430,8 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void)
changed = true;
}
else if (mFalseJump->mEntryRequiredRegs[mIns[i + 1].mAddress] &&
!mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress])
!mTrueJump->mEntryRequiredRegs[mIns[i + 1].mAddress] &&
mFalseJump->mNumEntries == 1)
{
for (int j = 0; j < 2; j++)
{
Expand Down Expand Up @@ -14408,21 +14463,91 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void)
!ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 4].mAddress))
{
if (mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress])
!mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mTrueJump->mEntryRequiredRegs[CPU_REG_C] &&
mTrueJump->mNumEntries == 1)
{
mTrueJump->mEntryRequiredRegs += mIns[i + 1].mAddress;
mTrueJump->mEntryRequiredRegs += mIns[i + 2].mAddress;
mTrueJump->mEntryRequiredRegs += mIns[i + 4].mAddress;
mTrueJump->mEntryRequiredRegs += mIns[i + 5].mAddress;

for (int j = 0; j < 7; j++)
{
mIns[i].mLive |= live;
mTrueJump->mIns.Insert(j, mIns[i]);
mIns.Remove(i);
}
changed = true;
i--;
}
else if (mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mFalseJump->mEntryRequiredRegs[CPU_REG_C] &&
mFalseJump->mNumEntries == 1)
{
mFalseJump->mEntryRequiredRegs += mIns[i + 1].mAddress;
mFalseJump->mEntryRequiredRegs += mIns[i + 2].mAddress;
mFalseJump->mEntryRequiredRegs += mIns[i + 4].mAddress;
mFalseJump->mEntryRequiredRegs += mIns[i + 5].mAddress;

for (int j = 0; j < 7; j++)
{
mIns[i].mLive |= live;
mFalseJump->mIns.Insert(j, mIns[i]);
mIns.Remove(i);
}
changed = true;
i--;
}
}
}
#endif
#if 1
if (!mExitRequiredRegs[CPU_REG_A] &&
i + 6 < mIns.Size() &&
mIns[i + 0].mType == ASMIT_CLC &&
mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE &&
mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE &&
mIns[i + 3].mType == ASMIT_STA && mIns[i + 3].mMode == ASMIM_ZERO_PAGE &&
mIns[i + 4].mType == ASMIT_LDA && mIns[i + 4].mMode == ASMIM_ZERO_PAGE &&
mIns[i + 5].mType == ASMIT_ADC && mIns[i + 5].mMode == ASMIM_IMMEDIATE &&
mIns[i + 6].mType == ASMIT_STA && mIns[i + 6].mMode == ASMIM_ZERO_PAGE &&
!(mIns[i + 6].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C | LIVE_CPU_REG_Z)))
{
if (!ReferencedOnPath(this, i + 7, mIns.Size(), mIns[i + 3].mAddress) &&
!ReferencedOnPath(this, i + 7, mIns.Size(), mIns[i + 6].mAddress) &&
!ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 1].mAddress) &&
!ChangedOnPath(this, i + 7, mIns.Size(), mIns[i + 4].mAddress))
{
if (mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mTrueJump->mEntryRequiredRegs[CPU_REG_C] &&
mTrueJump->mNumEntries == 1)
{
mTrueJump->mEntryRequiredRegs += mIns[i + 1].mAddress;
mTrueJump->mEntryRequiredRegs += mIns[i + 4].mAddress;

for (int j = 0; j < 7; j++)
{
mIns[i].mLive |= live;
mTrueJump->mIns.Insert(j, mIns[i]);
mIns.Remove(i);
}
changed = true;
i--;
}
else if (mFalseJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && mFalseJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress])
!mTrueJump->mEntryRequiredRegs[mIns[i + 3].mAddress] && !mTrueJump->mEntryRequiredRegs[mIns[i + 6].mAddress] &&
!mFalseJump->mEntryRequiredRegs[CPU_REG_C] &&
mFalseJump->mNumEntries == 1)
{
mFalseJump->mEntryRequiredRegs += mIns[i + 1].mAddress;
mFalseJump->mEntryRequiredRegs += mIns[i + 4].mAddress;

for (int j = 0; j < 7; j++)
{
mIns[i].mLive |= live;
mFalseJump->mIns.Insert(j, mIns[i]);
mIns.Remove(i);
}
Expand Down Expand Up @@ -25514,6 +25639,15 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_EOR && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress == 0x80 &&
mIns[i + 1].mType == ASMIT_CLC &&
mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && !(mIns[i + 2].mLive & LIVE_CPU_REG_C))
{
mIns[i + 2].mAddress ^= 0x80;
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_STA && !(mIns[i + 0].mFlags & NCIF_VOLATILE) &&
mIns[i + 2].mType == ASMIT_STA && mIns[i + 0].SameEffectiveAddress(mIns[i + 2]) &&
Expand Down
2 changes: 1 addition & 1 deletion oscar64/oscar64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main2(int argc, const char** argv)

#else
strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.10.159");
strcpy(strProductVersion, "1.10.160");

#ifdef __APPLE__
uint32_t length = sizeof(basePath);
Expand Down
Loading

0 comments on commit 121f047

Please sign in to comment.