From 92b2c3429330e5b02313624237723a5dd6f9dac6 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 16 Nov 2021 12:59:16 +0100 Subject: [PATCH] Byte code size optimizations --- include/crt.c | 19 +++++++++++++++++++ include/crt.h | 1 + oscar64/ByteCodeGenerator.cpp | 19 +++++++++++++++++++ oscar64/ByteCodeGenerator.h | 1 + oscar64/Disassembler.cpp | 4 ++++ 5 files changed, 44 insertions(+) diff --git a/include/crt.c b/include/crt.c index facabb1..c2587be 100644 --- a/include/crt.c +++ b/include/crt.c @@ -1273,6 +1273,25 @@ __asm inp_load_local_8 } #pragma bytecode(BC_LOAD_LOCAL_8, inp_load_local_8) + +__asm inp_load_local_u8 +{ + lda (ip), y + tax + iny + lda (ip), y + iny + sty tmpy + tay + lda (fp), y + sta $00, x + lda #0 + sta $01, x + ldy tmpy + jmp startup.exec +} + +#pragma bytecode(BC_LOAD_LOCAL_U8, inp_load_local_u8) __asm inp_store_local_8 { diff --git a/include/crt.h b/include/crt.h index c954327..1b4f6ba 100644 --- a/include/crt.h +++ b/include/crt.h @@ -37,6 +37,7 @@ enum ByteCode BC_LEA_ACCU_INDEX, BC_LOAD_LOCAL_8, + BC_LOAD_LOCAL_U8, BC_LOAD_LOCAL_16, BC_LOAD_LOCAL_32, diff --git a/oscar64/ByteCodeGenerator.cpp b/oscar64/ByteCodeGenerator.cpp index 7648943..d1d81b4 100644 --- a/oscar64/ByteCodeGenerator.cpp +++ b/oscar64/ByteCodeGenerator.cpp @@ -577,6 +577,7 @@ void ByteCodeInstruction::Assemble(ByteCodeGenerator* generator, ByteCodeBasicBl break; case BC_LOAD_LOCAL_8: + case BC_LOAD_LOCAL_U8: case BC_LOAD_LOCAL_16: case BC_LOAD_LOCAL_32: case BC_STORE_LOCAL_8: @@ -4539,6 +4540,24 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) progress = true; } #endif + else if ( + mIns[i + 0].mCode == BC_LOAD_LOCAL_8 && + mIns[i + 1].mCode == BC_LOAD_REG_8 && mIns[i + 1].mRegister == mIns[i + 0].mRegister && mIns[i + 1].mRegisterFinal) + { + mIns[i + 0].mCode = BC_LOAD_LOCAL_U8; + mIns[i + 0].mRegister = BC_REG_ACCU; + mIns[i + 0].mLive |= LIVE_ACCU; + mIns[i + 1].mCode = BC_NOP; + progress = true; + } + else if ( + mIns[i + 0].mCode == BC_LOAD_LOCAL_U8 && mIns[i + 0].mRegister == BC_REG_ACCU && + mIns[i + 1].mCode == BC_STORE_REG_16 && !(mIns[i + 1].mLive & LIVE_ACCU)) + { + mIns[i + 0].mRegister = mIns[i + 1].mRegister; + mIns[i + 1].mCode = BC_NOP; + progress = true; + } #if 0 else if ((mIns[i].mCode == BC_LOAD_LOCAL_16 || mIns[i].mCode == BC_LOAD_ABS_16) && mIns[i + 1].mCode == BC_ADDR_REG && mIns[i].mRegister == mIns[i + 1].mRegister && mIns[i + 1].mRegisterFinal) diff --git a/oscar64/ByteCodeGenerator.h b/oscar64/ByteCodeGenerator.h index 2779ae1..cc16c13 100644 --- a/oscar64/ByteCodeGenerator.h +++ b/oscar64/ByteCodeGenerator.h @@ -38,6 +38,7 @@ enum ByteCode BC_LEA_ACCU_INDEX, BC_LOAD_LOCAL_8, + BC_LOAD_LOCAL_U8, BC_LOAD_LOCAL_16, BC_LOAD_LOCAL_32, diff --git a/oscar64/Disassembler.cpp b/oscar64/Disassembler.cpp index 34b9843..9cd7a47 100644 --- a/oscar64/Disassembler.cpp +++ b/oscar64/Disassembler.cpp @@ -193,6 +193,10 @@ void ByteCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int star fprintf(file, "MOVB\t%s, %d(FP)", TempName(memory[start + i + 0], tbuffer, proc), memory[start + i + 1]); i += 2; break; + case BC_LOAD_LOCAL_U8: + fprintf(file, "MOVUB\t%s, %d(FP)", TempName(memory[start + i + 0], tbuffer, proc), memory[start + i + 1]); + i += 2; + break; case BC_LOAD_LOCAL_16: fprintf(file, "MOV\t%s, %d(FP)", TempName(memory[start + i + 0], tbuffer, proc), memory[start + i + 1]); i += 2;