Optimize right shift of byte values with variable shift distance
This commit is contained in:
parent
5b9f865a9d
commit
d4caa6bb71
|
@ -2804,6 +2804,13 @@ bool InterOperand::IsPositive(void) const
|
|||
return mRange.mMinState == IntegerValueRange::S_BOUND && mRange.mMinValue >= 0;
|
||||
}
|
||||
|
||||
bool InterOperand::IsInRange(int lower, int upper) const
|
||||
{
|
||||
return
|
||||
mRange.mMinState == IntegerValueRange::S_BOUND && mRange.mMinValue >= lower &&
|
||||
mRange.mMaxState == IntegerValueRange::S_BOUND && mRange.mMaxValue <= upper;
|
||||
}
|
||||
|
||||
bool InterOperand::IsUnsigned(void) const
|
||||
{
|
||||
if (mRange.mMinState == IntegerValueRange::S_BOUND && mRange.mMinValue >= 0 && mRange.mMaxState == IntegerValueRange::S_BOUND)
|
||||
|
|
|
@ -277,6 +277,7 @@ public:
|
|||
bool IsSByte(void) const;
|
||||
bool IsUnsigned(void) const;
|
||||
bool IsPositive(void) const;
|
||||
bool IsInRange(int lower, int upper) const;
|
||||
|
||||
bool IsNotUByte(void) const;
|
||||
|
||||
|
|
|
@ -9842,6 +9842,40 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
|
|||
mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
}
|
||||
else if (ins->mSrc[1].IsUByte())
|
||||
{
|
||||
NativeCodeBasicBlock* lblock = nproc->AllocateBlock();
|
||||
NativeCodeBasicBlock* eblock = nproc->AllocateBlock();
|
||||
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp]));
|
||||
if (!ins->mSrc[0].IsUByte() || ins->mSrc[0].mRange.mMaxValue > 15)
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_AND, ASMIM_IMMEDIATE, 0x0f));
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_TAX, ASMIM_IMPLIED));
|
||||
|
||||
if (ins->mSrc[1].mTemp < 0)
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[1].mIntConst & 0xff));
|
||||
else if (ins->mSrc[1].mTemp != ins->mDst.mTemp)
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp]));
|
||||
else
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, treg));
|
||||
|
||||
if (ins->mSrc[0].IsInRange(1, 15))
|
||||
this->Close(ins, lblock, nullptr, ASMIT_JMP);
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_CPX, ASMIM_IMMEDIATE, 0x00));
|
||||
this->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
}
|
||||
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LSR, ASMIM_IMPLIED));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_DEX, ASMIM_IMPLIED));
|
||||
lblock->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg));
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_IMMEDIATE, 0));
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
return eblock;
|
||||
}
|
||||
else
|
||||
{
|
||||
NativeCodeBasicBlock* lblock = nproc->AllocateBlock();
|
||||
|
@ -9869,8 +9903,13 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
|
|||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
|
||||
if (ins->mSrc[0].IsInRange(1, 15))
|
||||
this->Close(ins, lblock, nullptr, ASMIT_JMP);
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_CPX, ASMIM_IMMEDIATE, 0x00));
|
||||
this->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
}
|
||||
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LSR, ASMIM_IMPLIED));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_ROR, ASMIM_ZERO_PAGE, treg + 0));
|
||||
|
@ -10143,8 +10182,13 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
|
|||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, treg));
|
||||
}
|
||||
|
||||
if (ins->mSrc[0].IsInRange(1, 15))
|
||||
this->Close(ins, lblock, nullptr, ASMIT_JMP);
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_CPX, ASMIM_IMMEDIATE, 0x00));
|
||||
this->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
}
|
||||
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LSR, ASMIM_IMPLIED));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_DEX, ASMIM_IMPLIED));
|
||||
|
@ -10154,6 +10198,46 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
|
|||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_IMMEDIATE, 0x00));
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
else if (ins->mSrc[1].IsSByte())
|
||||
{
|
||||
if (ins->mSrc[1].mTemp < 0)
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[1].mIntConst & 0xff));
|
||||
}
|
||||
else if (ins->mSrc[1].mTemp != ins->mDst.mTemp)
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp]));
|
||||
}
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, treg));
|
||||
}
|
||||
|
||||
if (ins->mSrc[0].IsInRange(1, 15))
|
||||
this->Close(ins, lblock, nullptr, ASMIT_JMP);
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_CPX, ASMIM_IMMEDIATE, 0x00));
|
||||
this->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
}
|
||||
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_CMP, ASMIM_IMMEDIATE, 0x80));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_ROR, ASMIM_IMPLIED));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_DEX, ASMIM_IMPLIED));
|
||||
lblock->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg));
|
||||
if (ins->mSrc[1].mTemp < 0)
|
||||
{
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_IMMEDIATE, (ins->mSrc[1].mIntConst >> 8) & 0xff));
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
else if (ins->mSrc[1].mTemp != ins->mDst.mTemp)
|
||||
{
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp] + 1));
|
||||
eblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ins->mSrc[1].mTemp < 0)
|
||||
|
@ -10173,8 +10257,13 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
|
|||
mIns.Push(NativeCodeInstruction(ins, ASMIT_LDA, ASMIM_ZERO_PAGE, treg + 1));
|
||||
}
|
||||
|
||||
if (ins->mSrc[0].IsInRange(1, 15))
|
||||
this->Close(ins, lblock, nullptr, ASMIT_JMP);
|
||||
else
|
||||
{
|
||||
mIns.Push(NativeCodeInstruction(ins, ASMIT_CPX, ASMIM_IMMEDIATE, 0x00));
|
||||
this->Close(ins, lblock, eblock, ASMIT_BNE);
|
||||
}
|
||||
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_CMP, ASMIM_IMMEDIATE, 0x80));
|
||||
lblock->mIns.Push(NativeCodeInstruction(ins, ASMIT_ROR, ASMIM_IMPLIED));
|
||||
|
@ -19204,7 +19293,7 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
|
|||
if (mTrueJump->mEntryRequiredRegs[ins.mAddress] && !mFalseJump->mEntryRequiredRegs[ins.mAddress] && mTrueJump->mEntryBlocks.Size() == 1)
|
||||
{
|
||||
mTrueJump->mIns.Insert(0, ins);
|
||||
mTrueJump->mIns[0].mLive |= LIVE_CPU_REG_C;
|
||||
mTrueJump->mIns[0].mLive |= LIVE_CPU_REG_C | mIns[ns - 1].mLive;
|
||||
mIns.Remove(ns - 2);
|
||||
mTrueJump->mEntryRequiredRegs += CPU_REG_A;
|
||||
mTrueJump->CheckLive();
|
||||
|
@ -19213,7 +19302,7 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
|
|||
else if (mFalseJump->mEntryRequiredRegs[ins.mAddress] && !mTrueJump->mEntryRequiredRegs[ins.mAddress] && mFalseJump->mEntryBlocks.Size() == 1)
|
||||
{
|
||||
mFalseJump->mIns.Insert(0, ins);
|
||||
mFalseJump->mIns[0].mLive |= LIVE_CPU_REG_C;
|
||||
mFalseJump->mIns[0].mLive |= LIVE_CPU_REG_C | mIns[ns - 1].mLive;
|
||||
mIns.Remove(ns - 2);
|
||||
mFalseJump->mEntryRequiredRegs += CPU_REG_A;
|
||||
mFalseJump->CheckLive();
|
||||
|
@ -26894,6 +26983,8 @@ bool NativeCodeBasicBlock::ValueForwarding(NativeCodeProcedure* proc, const Nati
|
|||
}
|
||||
|
||||
#if 1
|
||||
if (global)
|
||||
{
|
||||
NativeCodeBasicBlock* fork = this;
|
||||
if (!mFalseJump && mTrueJump && mTrueJump->mIns.Size() == 0)
|
||||
fork = mTrueJump;
|
||||
|
@ -27167,6 +27258,7 @@ bool NativeCodeBasicBlock::ValueForwarding(NativeCodeProcedure* proc, const Nati
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (global && mTrueJump && mTrueJump->mIns.Size() == 1 && mTrueJump->mTrueJump && !mTrueJump->mFalseJump)
|
||||
{
|
||||
|
@ -37595,6 +37687,26 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
|
|||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (sz >= 2 &&
|
||||
mIns[sz - 2].mType == ASMIT_LDA && mIns[sz - 2].mMode == ASMIM_IMMEDIATE && mIns[sz - 2].mAddress == 0 &&
|
||||
mIns[sz - 1].mType == ASMIT_ROL && mIns[sz - 1].mMode == ASMIM_IMPLIED && !(mIns[sz - 1].mLive & LIVE_CPU_REG_C) && !mExitRequiredRegs[CPU_REG_Z] &&
|
||||
mBranch == ASMIT_BNE && !mTrueJump->mEntryRequiredRegs[CPU_REG_A])
|
||||
{
|
||||
mBranch = ASMIT_BCS;
|
||||
mIns.SetSize(sz - 1);
|
||||
sz -= 1;
|
||||
changed = true;
|
||||
}
|
||||
else if (sz >= 2 &&
|
||||
mIns[sz - 2].mType == ASMIT_LDA && mIns[sz - 2].mMode == ASMIM_IMMEDIATE && mIns[sz - 2].mAddress == 0 &&
|
||||
mIns[sz - 1].mType == ASMIT_ROL && mIns[sz - 1].mMode == ASMIM_IMPLIED && !(mIns[sz - 1].mLive & LIVE_CPU_REG_C) && !mExitRequiredRegs[CPU_REG_Z] &&
|
||||
mBranch == ASMIT_BEQ && !mFalseJump->mEntryRequiredRegs[CPU_REG_A])
|
||||
{
|
||||
mBranch = ASMIT_BCC;
|
||||
mIns.SetSize(sz - 1);
|
||||
sz -= 1;
|
||||
changed = true;
|
||||
}
|
||||
else if (sz >= 3 &&
|
||||
mIns[sz - 3].mType == ASMIT_LDA && mIns[sz - 3].mMode == ASMIM_IMMEDIATE && mIns[sz - 3].mAddress == 0 &&
|
||||
mIns[sz - 2].mType == ASMIT_ROL && mIns[sz - 2].mMode == ASMIM_IMPLIED &&
|
||||
|
@ -38588,7 +38700,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
|
|||
{
|
||||
mInterProc = proc;
|
||||
|
||||
CheckFunc = !strcmp(mInterProc->mIdent->mString, "move");
|
||||
CheckFunc = !strcmp(mInterProc->mIdent->mString, "bmul");
|
||||
|
||||
int nblocks = proc->mBlocks.Size();
|
||||
tblocks = new NativeCodeBasicBlock * [nblocks];
|
||||
|
|
Loading…
Reference in New Issue