Skip to content

Commit

Permalink
Fix global array aliasing error
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Nov 20, 2023
1 parent a9fc83d commit eec4ed4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
30 changes: 21 additions & 9 deletions include/fixmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,31 @@ unsigned long lmul16f16(unsigned long x, unsigned long y)

__native long lmul16f16s(long x, long y)
{
if (x < 0)
unsigned lox = x;
int hix = x >> 16;
unsigned loy = y;
int hiy = y >> 16;

long r = (long)(hix * hiy) << 16;

if (lox)
{
if (y < 0)
return lmul16f16(-x, -y);
else
return -lmul16f16(-x, y);
r += lmul16u(lox, hiy);
if (hiy < 0)
r -= (unsigned long)lox << 16;
}
else if (y < 0)
if (loy)
{
return -lmul16f16(x, -y);
r += lmul16u(loy, hix);
if (hix < 0)
r -= (unsigned long)loy << 16;
}
else
return lmul16f16(x, y);
if (lox && loy)
{
r += lmul16u(lox, loy) >> 16;
}

return r;
}

__native unsigned long ldiv16f16(unsigned long x, unsigned long y)
Expand Down
2 changes: 1 addition & 1 deletion oscar64/InterCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18594,7 +18594,7 @@ void InterCodeProcedure::Close(void)
{
GrowingTypeArray tstack(IT_NONE);

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

mEntryBlock = mBlocks[0];
Expand Down
2 changes: 1 addition & 1 deletion oscar64/InterCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
var->mDeclaration = dec;
mod->mGlobalVars.Push(var);

if (dec->mFlags & DTF_VAR_ALIASING)
if ((dec->mFlags & DTF_VAR_ALIASING) || (dec->mBase->mType == DT_TYPE_ARRAY && !(type->mFlags & DTF_CONST)))
var->mAliased = true;

dec->mVarIndex = var->mIndex;
Expand Down
14 changes: 14 additions & 0 deletions oscar64/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40431,6 +40431,20 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
else
mIns[i + 4].mType = ASMIT_NOP;

progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_LDA &&
mIns[i + 1].mType == ASMIT_STA &&
mIns[i + 2].mType == ASMIT_CLC &&
mIns[i + 3].mType == ASMIT_ADC && mIns[i + 3].mMode == ASMIM_IMMEDIATE && mIns[i + 3].mAddress == 1 &&
mIns[i + 4].mType == ASMIT_STA && mIns[i + 4].SameEffectiveAddress(mIns[i + 0]) && !(mIns[i + 4].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)) &&
HasAsmInstructionMode(ASMIT_INC, mIns[i + 0].mMode))
{
mIns[i + 4].mType = ASMIT_INC;
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 3].mMode = ASMIM_IMPLIED;
mIns[i + 3].mType = ASMIT_NOP; mIns[i + 3].mMode = ASMIM_IMPLIED;

progress = true;
}
#endif
Expand Down

0 comments on commit eec4ed4

Please sign in to comment.