Fix global array aliasing error

This commit is contained in:
drmortalwombat 2023-11-20 22:53:12 +01:00
parent a9fc83d63c
commit eec4ed45d1
4 changed files with 37 additions and 11 deletions

View File

@ -630,19 +630,31 @@ unsigned long lmul16f16(unsigned long x, unsigned long y)
__native long lmul16f16s(long x, 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) r += lmul16u(lox, hiy);
return lmul16f16(-x, -y); if (hiy < 0)
else r -= (unsigned long)lox << 16;
return -lmul16f16(-x, y);
} }
else if (y < 0) if (loy)
{ {
return -lmul16f16(x, -y); r += lmul16u(loy, hix);
if (hix < 0)
r -= (unsigned long)loy << 16;
} }
else if (lox && loy)
return lmul16f16(x, y); {
r += lmul16u(lox, loy) >> 16;
}
return r;
} }
__native unsigned long ldiv16f16(unsigned long x, unsigned long y) __native unsigned long ldiv16f16(unsigned long x, unsigned long y)

View File

@ -18594,7 +18594,7 @@ void InterCodeProcedure::Close(void)
{ {
GrowingTypeArray tstack(IT_NONE); GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "test"); CheckFunc = !strcmp(mIdent->mString, "interpret_expression");
CheckCase = false; CheckCase = false;
mEntryBlock = mBlocks[0]; mEntryBlock = mBlocks[0];

View File

@ -686,7 +686,7 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
var->mDeclaration = dec; var->mDeclaration = dec;
mod->mGlobalVars.Push(var); 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; var->mAliased = true;
dec->mVarIndex = var->mIndex; dec->mVarIndex = var->mIndex;

View File

@ -40431,6 +40431,20 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
else else
mIns[i + 4].mType = ASMIT_NOP; 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; progress = true;
} }
#endif #endif