From 2fc414ed6b19a4bd6c39082a545006e82c5d4fbb Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 25 Sep 2021 23:08:45 +0200 Subject: [PATCH] Byte forwardiong optimisation in native mode --- autotest/autotest.bat | 6 ++++++ autotest/byteindextest.c | 8 +++++--- oscar64/NativeCodeGenerator.cpp | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 9c615cf..af63c66 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -96,6 +96,12 @@ if %errorlevel% neq 0 goto :error ..\release\oscar64 -e -n loopdomtest.c if %errorlevel% neq 0 goto :error +..\release\oscar64 -e byteindextest.c +if %errorlevel% neq 0 goto :error + +..\release\oscar64 -e -n byteindextest.c +if %errorlevel% neq 0 goto :error + exit /b 0 :error echo Failed with error #%errorlevel%. diff --git a/autotest/byteindextest.c b/autotest/byteindextest.c index 69bc49e..ef1a502 100644 --- a/autotest/byteindextest.c +++ b/autotest/byteindextest.c @@ -1,5 +1,6 @@ -// short index ops + #include +#include char a[20]; @@ -10,7 +11,8 @@ int main(void) char x = 0; for(char i=0; i<20; i++) x += a[i]; - - printf("Sum %d\n", x); + + assert(x == 190); + return 0; } diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index e22772c..55f6ecf 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -779,10 +779,19 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data) switch (mType) { case ASMIT_LDA: - if (data.mRegs[CPU_REG_A].mZeroPage && data.mRegs[CPU_REG_A].mValue == mAddress && !(mLive & LIVE_CPU_REG_Z)) + if (data.mRegs[CPU_REG_A].mZeroPage && data.mRegs[CPU_REG_A].mValue == mAddress) { - mType = ASMIT_NOP; - mMode = ASMIM_IMPLIED; + if (mLive & LIVE_CPU_REG_Z) + { + mType = ASMIT_ORA; + mMode = ASMIM_IMMEDIATE; + mAddress = 0; + } + else + { + mType = ASMIT_NOP; + mMode = ASMIM_IMPLIED; + } changed = true; } else if (data.mRegs[mAddress].mImmediate)