From c0a5f8fef0920a57314b0e31190c5377975b824b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 19 Oct 2020 21:32:44 +0200 Subject: [PATCH] removed double mul code --- .../codegen/assignment/AssignmentAsmGen.kt | 4 -- .../assignment/AugmentableAssignmentAsmGen.kt | 49 ++++++------------- examples/test.p8 | 24 +++++---- 3 files changed, 26 insertions(+), 51 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt index b5c5012aa..ca39c9724 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -49,10 +49,6 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen DataType.UWORD, DataType.WORD -> assignVariableWord(assign.target, variable) DataType.FLOAT -> assignVariableFloat(assign.target, variable) DataType.STR -> assignVariableString(assign.target, variable) - in PassByReferenceDatatypes -> { - // TODO what about when the name is a struct? name.firstStructVarName(program.namespace) **************************************** - assignAddressOf(assign.target, variable) - } else -> throw AssemblyError("unsupported assignment target type ${assign.target.datatype}") } } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt index f7dc0bccf..f0c009943 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -720,41 +720,22 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, } } "*" -> { - if(dt == DataType.UWORD){ - if(value in asmgen.optimizedWordMultiplications) { - asmgen.out(" lda $name | ldy $name+1 | jsr math.mul_word_$value | sta $name | sty $name+1") - } else { - asmgen.out(""" - lda $name - sta P8ZP_SCRATCH_W1 - lda $name+1 - sta P8ZP_SCRATCH_W1+1 - lda #<$value - ldy #>$value - jsr math.multiply_words - lda math.multiply_words.result - sta $name - lda math.multiply_words.result+1 - sta $name+1""") - } + // the mul code works for both signed and unsigned + if(value in asmgen.optimizedWordMultiplications) { + asmgen.out(" lda $name | ldy $name+1 | jsr math.mul_word_$value | sta $name | sty $name+1") } else { - if(value.absoluteValue in asmgen.optimizedWordMultiplications) { - asmgen.out(" lda $name | ldy $name+1 | jsr math.mul_word_$value | sta $name | sty $name+1") - } else { - // TODO does this work for signed words? if so the uword/word distinction can be removed altogether **************************************** - asmgen.out(""" - lda $name - sta P8ZP_SCRATCH_W1 - lda $name+1 - sta P8ZP_SCRATCH_W1+1 - lda #<$value - ldy #>$value - jsr math.multiply_words - lda math.multiply_words.result - sta $name - lda math.multiply_words.result+1 - sta $name+1""") - } + asmgen.out(""" + lda $name + sta P8ZP_SCRATCH_W1 + lda $name+1 + sta P8ZP_SCRATCH_W1+1 + lda #<$value + ldy #>$value + jsr math.multiply_words + lda math.multiply_words.result + sta $name + lda math.multiply_words.result+1 + sta $name+1""") } } "/" -> { diff --git a/examples/test.p8 b/examples/test.p8 index f0a12a0b3..d8c687334 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -7,20 +7,18 @@ main { sub start() { - float[] array = [1111.1,2222.2,3333.3,4444.4,5555.5] + uword vv = 1111 + vv *= 23 + txt.print_uw(vv) + txt.chrout('\n') - float fw - ubyte i1 = 1 - ubyte i2 = 3 - ubyte zero = 0 - ubyte four = 4 - swap(array[i1], array[0]) - swap(array[4], array[i2]) - - for i1 in 0 to len(array)-1 { - floats.print_f(array[i1]) - txt.chrout(',') - } + word ww = -1111 + ww *= 23 + txt.print_w(ww) + txt.chrout('\n') + ww = -1111 + ww *= -23 + txt.print_w(ww) txt.chrout('\n') testX()