From f590284ae2fc2c21dfc96acb0fc332833107db0b Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:32:32 +0100 Subject: [PATCH] Fix volatile code movement --- oscar64/NativeCodeGenerator.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 50ad1be..db7e32a 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -19842,6 +19842,9 @@ bool NativeCodeBasicBlock::CheckSingleUseGlobalLoad(const NativeCodeBasicBlock* { NativeCodeInstruction& ins(mIns[at]); + if (ains.mFlags & ins.mFlags & NCIF_VOLATILE) + return false; + if (ins.mMode == ASMIM_ZERO_PAGE && ins.mAddress == reg) { if (ins.UsesAddress()) @@ -31039,7 +31042,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass #if 1 if (mIns[i].mType == ASMIT_LDY) { - if (!mIns[i + 1].RequiresYReg() && !mIns[i + 1].ChangesYReg() && !(mIns[i + 1].mLive & LIVE_CPU_REG_Z)) + if (!mIns[i + 1].RequiresYReg() && !mIns[i + 1].ChangesYReg() && !(mIns[i + 1].mLive & LIVE_CPU_REG_Z) && !(mIns[i].mFlags & mIns[i + 1].mFlags & NCIF_VOLATILE)) { if (mIns[i].mMode != ASMIM_ABSOLUTE_X || !mIns[i + 1].ChangesXReg()) { @@ -31061,7 +31064,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass } else if (mIns[i].mType == ASMIT_LDX) { - if (!mIns[i + 1].RequiresXReg() && !mIns[i + 1].ChangesXReg() && !(mIns[i + 1].mLive & LIVE_CPU_REG_Z)) + if (!mIns[i + 1].RequiresXReg() && !mIns[i + 1].ChangesXReg() && !(mIns[i + 1].mLive & LIVE_CPU_REG_Z) && !(mIns[i].mFlags & mIns[i + 1].mFlags & NCIF_VOLATILE)) { if (mIns[i].mMode != ASMIM_ABSOLUTE_Y || !mIns[i + 1].ChangesYReg()) { @@ -37785,7 +37788,7 @@ void NativeCodeProcedure::RebuildEntry(void) void NativeCodeProcedure::Optimize(void) { - CheckFunc = !strcmp(mInterProc->mIdent->mString, "pad_poll"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "check"); #if 1 int step = 0; @@ -38049,6 +38052,7 @@ void NativeCodeProcedure::Optimize(void) } #endif + #if _DEBUG ResetVisited(); mEntryBlock->CheckBlocks(true); @@ -38415,6 +38419,7 @@ void NativeCodeProcedure::Optimize(void) else cnt++; + } while (changed); #if 1