Use array of struct assignments for index range validation

This commit is contained in:
drmortalwombat 2022-05-26 13:55:00 +02:00
parent 3dc35c5fff
commit d833ca6834
8 changed files with 155 additions and 39 deletions

View File

@ -13,8 +13,8 @@ enum SIDFXState
static struct SIDFXChannel static struct SIDFXChannel
{ {
SIDFX * com; SIDFX * com;
byte delay, cnt; byte delay, cnt, priority;
SIDFXState state; volatile SIDFXState state;
unsigned freq, pwm; unsigned freq, pwm;
} channels[3]; } channels[3];
@ -25,21 +25,28 @@ void sidfx_init(void)
{ {
channels[i].com = nullptr; channels[i].com = nullptr;
channels[i].state = SIDFX_IDLE; channels[i].state = SIDFX_IDLE;
channels[i].priority = 0;
} }
} }
void sidfx_play(byte chn, SIDFX * fx, byte cnt) void sidfx_play(byte chn, SIDFX * fx, byte cnt)
{ {
if (!channels[chn].com || channels[chn].com->priority <= fx->priority) SIDFXState ns = channels[chn].state;
{
if (channels[chn].state == SIDFX_IDLE) if (ns == SIDFX_IDLE)
channels[chn].state = SIDFX_READY; ns = SIDFX_READY;
else if (channels[chn].priority <= fx->priority)
ns = SIDFX_RESET_0;
else else
channels[chn].state = SIDFX_RESET_0; return;
channels[chn].state = SIDFX_IDLE;
channels[chn].com = fx; channels[chn].com = fx;
channels[chn].cnt = cnt - 1; channels[chn].cnt = cnt - 1;
} channels[chn].priority = fx->priority;
channels[chn].state = ns;
} }
void sidfx_stop(byte chn) void sidfx_stop(byte chn)

View File

@ -5521,6 +5521,13 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(void)
msize[ins->mSrc[0].mTemp] = int64max(msize[ins->mSrc[0].mTemp], ins->mSrc[0].mIntConst + InterTypeSize[ins->mDst.mType]); msize[ins->mSrc[0].mTemp] = int64max(msize[ins->mSrc[0].mTemp], ins->mSrc[0].mIntConst + InterTypeSize[ins->mDst.mType]);
else if (ins->mCode == IC_STORE && ins->mSrc[1].mMemory == IM_INDIRECT && ins->mSrc[1].mTemp >= 0) else if (ins->mCode == IC_STORE && ins->mSrc[1].mMemory == IM_INDIRECT && ins->mSrc[1].mTemp >= 0)
msize[ins->mSrc[1].mTemp] = int64max(msize[ins->mSrc[1].mTemp], ins->mSrc[1].mIntConst + InterTypeSize[ins->mSrc[0].mType]); msize[ins->mSrc[1].mTemp] = int64max(msize[ins->mSrc[1].mTemp], ins->mSrc[1].mIntConst + InterTypeSize[ins->mSrc[0].mType]);
else if (ins->mCode == IC_COPY)
{
if (ins->mSrc[0].mMemory == IM_INDIRECT && ins->mSrc[0].mTemp >= 0)
msize[ins->mSrc[0].mTemp] = ins->mConst.mOperandSize;
if (ins->mSrc[1].mMemory == IM_INDIRECT && ins->mSrc[1].mTemp >= 0)
msize[ins->mSrc[1].mTemp] = ins->mConst.mOperandSize;
}
else if (ins->mCode == IC_LEA && ins->mSrc[1].mMemory != IM_INDIRECT && ins->mSrc[0].mTemp >= 0 && msize[ins->mDst.mTemp] > 0) else if (ins->mCode == IC_LEA && ins->mSrc[1].mMemory != IM_INDIRECT && ins->mSrc[0].mTemp >= 0 && msize[ins->mDst.mTemp] > 0)
{ {
int asize = 0; int asize = 0;

View File

@ -438,7 +438,7 @@ void Linker::Link(void)
} }
} }
} }
else else if (obj->mSection->mType == LST_DATA)
{ {
memcpy(mMemory + obj->mAddress, obj->mData, obj->mSize); memcpy(mMemory + obj->mAddress, obj->mData, obj->mSize);
} }

View File

@ -11597,6 +11597,43 @@ bool NativeCodeBasicBlock::ExpandADCToBranch(NativeCodeProcedure* proc)
break; break;
} }
#endif #endif
#if 1
if (i + 4 < mIns.Size() &&
mIns[i + 0].ChangesAccuAndFlag() &&
mIns[i + 1].mType == ASMIT_CMP && mIns[i + 1].mMode == ASMIM_IMMEDIATE && mIns[i + 1].mAddress == 0x01 &&
mIns[i + 2].mType == ASMIT_LDA && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 0x00 &&
mIns[i + 3].mType == ASMIT_ADC && mIns[i + 3].mMode == ASMIM_IMMEDIATE && mIns[i + 3].mAddress == 0xff &&
mIns[i + 4].mType == ASMIT_AND && mIns[i + 4].mMode == ASMIM_IMMEDIATE)
{
char veq = mIns[i + 4].mAddress, vne = 0;
changed = true;
NativeCodeBasicBlock* eblock = proc->AllocateBlock();
NativeCodeBasicBlock* neblock = proc->AllocateBlock();
NativeCodeBasicBlock* rblock = proc->AllocateBlock();
rblock->mTrueJump = mTrueJump;
rblock->mFalseJump = mFalseJump;
rblock->mBranch = mBranch;
for (int j = i + 5; j < mIns.Size(); j++)
rblock->mIns.Push(mIns[j]);
mIns.SetSize(i + 1);
mTrueJump = neblock;
mFalseJump = eblock;
mBranch = ASMIT_BNE;
if (veq != 0)
eblock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, veq));
neblock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, vne));
eblock->Close(rblock, nullptr, ASMIT_JMP);
neblock->Close(rblock, nullptr, ASMIT_JMP);
break;
}
#endif
#if 1 #if 1
if (i + 12 < mIns.Size()) if (i + 12 < mIns.Size())
{ {
@ -12791,6 +12828,51 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
} }
} }
#endif #endif
#if 1
if (mIns.Size() >= 1 && mIns[0].mType == ASMIT_TAX && !(mIns[0].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)))
{
int i = 0;
while (i < mEntryBlocks.Size() && mEntryBlocks[i]->mIns.Size() > 0 && mEntryBlocks[i]->mIns.Last().mType == ASMIT_LDA && HasAsmInstructionMode(ASMIT_LDX, mEntryBlocks[i]->mIns.Last().mMode) && !mEntryBlocks[i]->mFalseJump)
i++;
if (i == mEntryBlocks.Size())
{
for (int i = 0; i < mEntryBlocks.Size(); i++)
{
NativeCodeBasicBlock* b = mEntryBlocks[i];
int sz = b->mIns.Size();
b->mIns[sz - 1].mType = ASMIT_LDX;
b->mIns[sz - 1].mLive |= LIVE_CPU_REG_X;
changed = true;
}
mIns[0].mType = ASMIT_NOP; mIns[0].mMode = ASMIM_IMPLIED;
}
}
#endif
#if 1
if (mIns.Size() >= 1 && mIns[0].mMode == ASMIM_ABSOLUTE_X && !(mIns[0].mLive & (LIVE_CPU_REG_X | LIVE_CPU_REG_Z)))
{
int i = 0;
while (i < mEntryBlocks.Size() && mEntryBlocks[i]->mIns.Size() > 0 && mEntryBlocks[i]->mIns.Last().mType == ASMIT_LDX && mEntryBlocks[i]->mIns.Last().mMode == ASMIM_IMMEDIATE && !mEntryBlocks[i]->mFalseJump)
i++;
if (i == mEntryBlocks.Size())
{
for (int i = 0; i < mEntryBlocks.Size(); i++)
{
NativeCodeBasicBlock* b = mEntryBlocks[i];
int sz = b->mIns.Size();
int index = b->mIns[sz - 1].mAddress;
b->mIns[sz - 1] = mIns[0];
b->mIns[sz - 1].mMode = ASMIM_ABSOLUTE;
b->mIns[sz - 1].mAddress += index;
changed = true;
}
mIns[0].mType = ASMIT_NOP; mIns[0].mMode = ASMIM_IMPLIED;
}
}
#endif
#if 1 #if 1
if (mIns.Size() >= 1 && mIns.Last().mType == ASMIT_STA && mIns.Last().mMode == ASMIM_ZERO_PAGE && mTrueJump && mFalseJump && mTrueJump->mEntryRequiredRegs.Size() && mFalseJump->mEntryRequiredRegs.Size()) if (mIns.Size() >= 1 && mIns.Last().mType == ASMIT_STA && mIns.Last().mMode == ASMIM_ZERO_PAGE && mTrueJump && mFalseJump && mTrueJump->mEntryRequiredRegs.Size() && mFalseJump->mEntryRequiredRegs.Size())
{ {
@ -19024,6 +19106,8 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
// move stx up // move stx up
for (int i = 1; i < mIns.Size(); i++) for (int i = 1; i < mIns.Size(); i++)
{
if (!(mIns[i].mFlags & NCIF_VOLATILE))
{ {
if (mIns[i].mType == ASMIT_STX && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE)) if (mIns[i].mType == ASMIT_STX && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE))
{ {
@ -19049,6 +19133,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
changed = true; changed = true;
} }
} }
}
CheckLive(); CheckLive();
#endif #endif
@ -19568,6 +19653,11 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED;; mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED;;
progress = true; progress = true;
} }
else if (mIns[i].mType == ASMIT_EOR && mIns[i].mMode == ASMIM_IMMEDIATE && mIns[i].mAddress == 0x00 && (mIns[i].mLive & LIVE_CPU_REG_Z) == 0)
{
mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED;;
progress = true;
}
else if (mIns[i].mType == ASMIT_ROR && mIns[i].mMode == ASMIM_IMPLIED && (mIns[i].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)) == 0) else if (mIns[i].mType == ASMIT_ROR && mIns[i].mMode == ASMIM_IMPLIED && (mIns[i].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)) == 0)
{ {
mIns[i].mType = ASMIT_LSR; mIns[i].mType = ASMIT_LSR;
@ -20760,6 +20850,15 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED;
progress = true; progress = true;
} }
else if (
mIns[i + 0].mType == ASMIT_ADC && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress == 0 &&
mIns[i + 1].mType == ASMIT_CLC &&
mIns[i + 2].mType == ASMIT_ADC)
{
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED;
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
progress = true;
}
else if ( else if (
mIns[i + 0].mType == ASMIT_STA && !(mIns[i + 0].mFlags & NCIF_VOLATILE) && 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]) && mIns[i + 2].mType == ASMIT_STA && mIns[i + 0].SameEffectiveAddress(mIns[i + 2]) &&
@ -23966,7 +24065,7 @@ void NativeCodeProcedure::Optimize(void)
ResetVisited(); ResetVisited();
NativeRegisterDataSet data; NativeRegisterDataSet data;
if (mEntryBlock->ValueForwarding(data, step > 0, step == 6)) if (mEntryBlock->ValueForwarding(data, step > 0, step == 7))
changed = true; changed = true;
} while (changed); } while (changed);

View File

@ -1151,7 +1151,10 @@ Declaration* Parser::ParseDeclaration(bool variable)
} }
if (!(ndec->mFlags & DTF_EXTERN)) if (!(ndec->mFlags & DTF_EXTERN))
{
pdec->mFlags &= ~DTF_EXTERN; pdec->mFlags &= ~DTF_EXTERN;
pdec->mSection = ndec->mSection;
}
ndec = pdec; ndec = pdec;
} }

View File

@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.7.130"); strcpy(strProductVersion, "1.7.131");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,7,130,0 FILEVERSION 1,7,131,0
PRODUCTVERSION 1,7,130,0 PRODUCTVERSION 1,7,131,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "oscar64" VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler" VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.7.130.0" VALUE "FileVersion", "1.7.131.0"
VALUE "InternalName", "oscar64.exe" VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe" VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64" VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.7.130.0" VALUE "ProductVersion", "1.7.131.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -4127,15 +4127,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{C50454FA-D0C4-42C0-9D55-B9CC69CB68CB}" "ProductCode" = "8:{0C6C4C06-0820-4C2F-B1B9-1E525CEC0D53}"
"PackageCode" = "8:{2B506600-BA1E-41A8-AC6E-BD9D54BC5EA0}" "PackageCode" = "8:{CE1DC98E-EB19-476E-9D59-CA1D561B38E9}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0" "AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.7.130" "ProductVersion" = "8:1.7.131"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"