Skip to content

Commit

Permalink
Join common branch code sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Nov 26, 2023
1 parent eec4ed4 commit 57537cd
Show file tree
Hide file tree
Showing 4 changed files with 470 additions and 41 deletions.
18 changes: 11 additions & 7 deletions include/fixmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,21 @@ __native unsigned long ldiv16f16(unsigned long x, unsigned long y)

__native long ldiv16f16s(long x, long y)
{
bool sign = false;
if (x < 0)
{
if (y < 0)
return ldiv16f16(-x, -y);
else
return -ldiv16f16(-x, y);
x = -x;
sign = true;
}
else if (y < 0)
if (y < 0)
{
return -ldiv16f16(x, -y);
y = -y;
sign = !sign;
}

x = ldiv16f16(x, y);
if (sign)
return -x;
else
return ldiv16f16(x, y);
return x;
}
57 changes: 35 additions & 22 deletions oscar64/InterCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9137,6 +9137,10 @@ bool InterCodeBasicBlock::RemoveUnusedIndirectStoreInstructions(void)
stores.Push(ins);
}
}
else if (ins->mCode == IC_CALL || ins->mCode == IC_CALL_NATIVE)
{
stores.SetSize(0);
}
else
{
int j = 0;
Expand Down Expand Up @@ -11406,30 +11410,33 @@ bool InterCodeBasicBlock::MergeCommonPathInstructions(void)
if (mTrueJump->CanMoveInstructionBeforeBlock(ti) && mFalseJump->CanMoveInstructionBeforeBlock(fi))
{
int tindex = mInstructions.Size() - 1;
if (mInstructions.Size() >= 2 && mInstructions[tindex - 1]->mDst.mTemp == mInstructions[tindex]->mSrc[0].mTemp &&
CanSwapInstructions(mInstructions[tindex - 1], tins))
// CanBypassUp(tins, mInstructions[tindex - 1]))
tindex--;

mInstructions.Insert(tindex, tins);
tindex++;
if (tins->mDst.mTemp != -1)
if (mInstructions[tindex]->mCode != IC_BRANCH || tins->mDst.mTemp != mInstructions[tindex]->mSrc[0].mTemp)
{
if (fins->mDst.mTemp != tins->mDst.mTemp)
if (mInstructions.Size() >= 2 && mInstructions[tindex - 1]->mDst.mTemp == mInstructions[tindex]->mSrc[0].mTemp &&
CanSwapInstructions(mInstructions[tindex - 1], tins))
// CanBypassUp(tins, mInstructions[tindex - 1]))
tindex--;

mInstructions.Insert(tindex, tins);
tindex++;
if (tins->mDst.mTemp != -1)
{
InterInstruction* nins = new InterInstruction(tins->mLocation, IC_LOAD_TEMPORARY);
nins->mDst.mTemp = fins->mDst.mTemp;
nins->mDst.mType = fins->mDst.mType;
nins->mSrc[0].mTemp = tins->mDst.mTemp;
nins->mSrc[0].mType = tins->mDst.mType;
assert(nins->mSrc[0].mTemp >= 0);
mFalseJump->mInstructions.Insert(0, nins);
fi++;
if (fins->mDst.mTemp != tins->mDst.mTemp)
{
InterInstruction* nins = new InterInstruction(tins->mLocation, IC_LOAD_TEMPORARY);
nins->mDst.mTemp = fins->mDst.mTemp;
nins->mDst.mType = fins->mDst.mType;
nins->mSrc[0].mTemp = tins->mDst.mTemp;
nins->mSrc[0].mType = tins->mDst.mType;
assert(nins->mSrc[0].mTemp >= 0);
mFalseJump->mInstructions.Insert(0, nins);
fi++;
}
}
mTrueJump->mInstructions.Remove(ti);
mFalseJump->mInstructions.Remove(fi);
changed = true;
}
mTrueJump->mInstructions.Remove(ti);
mFalseJump->mInstructions.Remove(fi);
changed = true;
}
}
}
Expand Down Expand Up @@ -18163,6 +18170,8 @@ void InterCodeProcedure::RemoveUnusedStoreInstructions(InterMemory paramMemory)

ResetVisited();
mEntryBlock->RemoveUnusedIndirectStoreInstructions();

DisassembleDebug("RemoveUnusedIndirectStoreInstructions");
}
}

Expand Down Expand Up @@ -18538,14 +18547,18 @@ void InterCodeProcedure::PropagateConstOperationsUp(void)
ResetVisited();
if (mEntryBlock->SplitSingleBranchUseConst())
changed = true;


DisassembleDebug("SplitSingleBranchUseConst");

ResetVisited();
if (mEntryBlock->CommonTailCodeMerge())
{
changed = true;
BuildDataFlowSets();
}

DisassembleDebug("CommonTailCodeMerge");

ResetVisited();
mEntryBlock->BuildConstTempSets();

Expand Down Expand Up @@ -18594,7 +18607,7 @@ void InterCodeProcedure::Close(void)
{
GrowingTypeArray tstack(IT_NONE);

CheckFunc = !strcmp(mIdent->mString, "interpret_expression");
CheckFunc = !strcmp(mIdent->mString, "parse_expression");
CheckCase = false;

mEntryBlock = mBlocks[0];
Expand Down
Loading

0 comments on commit 57537cd

Please sign in to comment.