From df733d09a809c723c1db9bd991b9e455dcdb9f74 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 1 May 2023 19:16:25 +0200 Subject: [PATCH] Fix add cross move in native code optimizer --- include/fixmath.c | 25 +++++++++++++++++++++++++ include/fixmath.h | 2 ++ oscar64/NativeCodeGenerator.cpp | 10 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/fixmath.c b/include/fixmath.c index 19e9066..2dcd8f8 100644 --- a/include/fixmath.c +++ b/include/fixmath.c @@ -585,3 +585,28 @@ int lmuldiv16sby8(int a, char b, char c) else return lmuldiv16by8(a, b, c); } + +unsigned usqrt(unsigned n) +{ + unsigned p, q, r, h; + + p = 0; + r = n; + +#assign q 0x4000 +#repeat + { + h = p | q; + p >>= 1; + if (r >= h) + { + p |= q; + r -= h; + } + } +#assign q q >> 2 +#until q == 0 +#undef q + + return p; +} diff --git a/include/fixmath.h b/include/fixmath.h index 2a7a983..9c913af 100644 --- a/include/fixmath.h +++ b/include/fixmath.h @@ -48,6 +48,8 @@ inline int lmuldiv16sby8(int a, char b, char c); __native unsigned lmuldiv8by8(char a, char b, char c); +__native unsigned usqrt(unsigned n); + #pragma compile("fixmath.c") #endif diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 216f470..a3d4596 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -25991,6 +25991,13 @@ bool NativeCodeBasicBlock::MoveLoadAddZPStoreUp(int at) { if (mIns[j].mType == ASMIT_STA && mIns[j].mMode == ASMIM_ZERO_PAGE && mIns[j].mAddress == mIns[at + 0].mAddress) { + while (j < at && (mIns[j].mLive & LIVE_CPU_REG_A)) + { + if (mIns[j].ChangesAccu()) + return false; + j++; + } + mIns[at + 1].mLive |= mIns[j].mLive; mIns[at + 2].mLive |= mIns[j].mLive; @@ -31953,6 +31960,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass if (MoveCLCLoadAddZPStoreUp(i)) changed = true; } +#if 1 else if ( mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mType == ASMIT_ADC && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && @@ -31961,6 +31969,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass if (MoveLoadAddZPStoreUp(i)) changed = true; } +#endif #if 1 else if ( mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && @@ -39596,7 +39605,6 @@ void NativeCodeProcedure::Optimize(void) else cnt++; - } while (changed); #if 1