From 04da44eb988e4c2abef4099f86888b95074cc453 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 29 Jun 2023 22:56:26 +0200 Subject: [PATCH] fix certain inefficient codegen when assigning a type casted value --- .gitignore | 2 ++ .../assignment/AugmentableAssignmentAsmGen.kt | 17 ++++++++--------- docs/source/todo.rst | 2 -- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b449fc760..452c2d8e2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ out/ parser/**/*.interp parser/**/*.tokens parser/**/*.java +compiler/src/prog8/buildversion/* *.py[cod] *.egg *.egg-info @@ -32,3 +33,4 @@ compiler/lib/ /prog8compiler.jar sd*.img *.d64 + diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 42d351b18..751f7ffc7 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -177,7 +177,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, SourceStorageKind.ARRAY -> inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.array!!) SourceStorageKind.EXPRESSION -> { if(value.expression is PtTypeCast) { - if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) return inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression) } else { inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression!!) @@ -259,6 +258,10 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, indexVar!=null -> { when (target.datatype) { in ByteDatatypes -> { + if(value.kind==SourceStorageKind.EXPRESSION + && value.expression is PtTypeCast + && tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) + return asmgen.loadScaledArrayIndexIntoRegister(target.array, DataType.UBYTE, CpuRegister.Y) asmgen.out(" lda ${target.array.variable.name},y | sta P8ZP_SCRATCH_B1") asmgen.saveRegisterLocal(CpuRegister.Y, target.scope!!) @@ -270,10 +273,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, SourceStorageKind.ARRAY -> inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.array!!) SourceStorageKind.EXPRESSION -> { if(value.expression is PtTypeCast) { - if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) { - asmgen.restoreRegisterLocal(CpuRegister.Y) - return - } inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression) } else { inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression!!) @@ -285,6 +284,10 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, asmgen.out(" lda P8ZP_SCRATCH_B1 | sta ${target.array.variable.name},y") } in WordDatatypes -> { + if(value.kind==SourceStorageKind.EXPRESSION + && value.expression is PtTypeCast + && tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) + return asmgen.loadScaledArrayIndexIntoRegister(target.array, DataType.UWORD, CpuRegister.Y) if(target.array.splitWords) { asmgen.out(" lda ${target.array.variable.name}_lsb,y | sta P8ZP_SCRATCH_W1") @@ -302,10 +305,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, SourceStorageKind.ARRAY -> inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.array!!) SourceStorageKind.EXPRESSION -> { if(value.expression is PtTypeCast) { - if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) { - asmgen.restoreRegisterLocal(CpuRegister.Y) - return - } inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression) } else { inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression!!) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b0d1cbd4a..8ccb1c5ac 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -- fix double code gen with tryInplaceModifyWithRemovedRedundantCast() ? word birdX[j] += testbyte - - prog8->asm symbol name prefixing: prefix ALL symbols with p8_ Also update manual. EXCEPTION: library symbols such as cbm.CHROUT, cx16.r0 etc. should NOT be prefixed. Solution: add %option no_symbol_prefix to those blocks?