From 1f7180d9a860151063c547db2d00d7a8f36d0405 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 6 Jul 2023 22:54:13 +0200 Subject: [PATCH] math.multiply_words returns lower 16 bits of the result also in AY (to avoid repeating some load instructions) --- .../cpu6502/assignment/AssignmentAsmGen.kt | 9 ++------ .../assignment/AugmentableAssignmentAsmGen.kt | 23 +++++-------------- compiler/res/prog8lib/math.asm | 5 ++-- compiler/res/prog8lib/prog8_lib.asm | 3 +-- .../src/prog8/buildversion/BuildVersion.kt | 12 +++++----- docs/source/todo.rst | 4 ++++ 6 files changed, 22 insertions(+), 34 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 7038ea045..e99054619 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -745,10 +745,7 @@ internal class AssignmentAsmGen(private val program: PtProgram, } in WordDatatypes -> { asmgen.assignWordOperandsToAYAndVar(expr.right, expr.left, "P8ZP_SCRATCH_W1") - asmgen.out(""" - jsr math.multiply_words - lda math.multiply_words.result - ldy math.multiply_words.result+1""") + asmgen.out(" jsr math.multiply_words") assignRegisterpairWord(assign.target, RegisterOrPair.AY) return true } @@ -775,9 +772,7 @@ internal class AssignmentAsmGen(private val program: PtProgram, sty P8ZP_SCRATCH_W1+1 lda #<$value ldy #>$value - jsr math.multiply_words - lda math.multiply_words.result - ldy math.multiply_words.result+1""") + jsr math.multiply_words""") assignRegisterpairWord(assign.target, RegisterOrPair.AY) return true } diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 751f7ffc7..36a0882fa 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -1221,10 +1221,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, lda #<$value ldy #>$value jsr math.multiply_words - lda math.multiply_words.result sta $name - lda math.multiply_words.result+1 - sta $name+1""") + sty $name+1""") } } "/" -> { @@ -1682,10 +1680,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, lda $name ldy $name+1 jsr math.multiply_words - lda math.multiply_words.result sta $name - lda math.multiply_words.result+1 - sta $name+1""") + sty $name+1""") } "/" -> { if(dt==DataType.UWORD) { @@ -1822,11 +1818,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, lda $name ldy $name+1 jsr math.multiply_words - lda math.multiply_words.result sta $name - lda math.multiply_words.result+1 - sta $name+1 - """) + sty $name+1""") } "/" -> { if(dt==DataType.WORD) { @@ -1839,8 +1832,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, ldy $otherName+1 jsr math.divmod_w_asm sta $name - sty $name+1 - """) + sty $name+1""") } else { asmgen.out(""" @@ -1852,8 +1844,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, ldy $otherName+1 jsr math.divmod_uw_asm sta $name - sty $name+1 - """) + sty $name+1""") } } "%" -> { @@ -2016,10 +2007,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, lda $name ldy $name+1 jsr math.multiply_words - lda math.multiply_words.result sta $name - lda math.multiply_words.result+1 - sta $name+1 + sty $name+1 """) } diff --git a/compiler/res/prog8lib/math.asm b/compiler/res/prog8lib/math.asm index 957c86ae2..fa1ffa011 100644 --- a/compiler/res/prog8lib/math.asm +++ b/compiler/res/prog8lib/math.asm @@ -51,8 +51,7 @@ multiply_bytes_into_word .proc multiply_words .proc ; -- multiply two 16-bit words into a 32-bit result (signed and unsigned) ; input: A/Y = first 16-bit number, P8ZP_SCRATCH_W1 in ZP = second 16-bit number - ; output: multiply_words.result 4-bytes/32-bits product, LSB order (low-to-high) - ; clobbers: A + ; output: multiply_words.result 4-bytes/32-bits product, LSB order (low-to-high) low 16 bits also in AY. sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 @@ -79,6 +78,8 @@ mult16 lda #0 dex bne - ldx P8ZP_SCRATCH_REG + lda result + ldy result+1 rts result .byte 0,0,0,0 diff --git a/compiler/res/prog8lib/prog8_lib.asm b/compiler/res/prog8lib/prog8_lib.asm index a3aa523f5..e5e21b61b 100644 --- a/compiler/res/prog8lib/prog8_lib.asm +++ b/compiler/res/prog8lib/prog8_lib.asm @@ -167,9 +167,8 @@ mul_word .proc lda P8ESTACK_LO+1,x ldy P8ESTACK_HI+1,x jsr math.multiply_words - lda math.multiply_words.result sta P8ESTACK_LO+1,x - lda math.multiply_words.result+1 + tya sta P8ESTACK_HI+1,x rts .pend diff --git a/compiler/src/prog8/buildversion/BuildVersion.kt b/compiler/src/prog8/buildversion/BuildVersion.kt index 1cdaaa2b5..b50ae16cd 100644 --- a/compiler/src/prog8/buildversion/BuildVersion.kt +++ b/compiler/src/prog8/buildversion/BuildVersion.kt @@ -6,10 +6,10 @@ package prog8.buildversion const val MAVEN_GROUP = "prog8" const val MAVEN_NAME = "compiler" const val VERSION = "9.1-SNAPSHOT" -const val GIT_REVISION = 3924 -const val GIT_SHA = "204f5591a91d51bc514d4c753907559da0ffa61b" -const val GIT_DATE = "2023-07-03T19:57:32Z" +const val GIT_REVISION = 3930 +const val GIT_SHA = "b4e94ae4dd1c29a966bb5ea0454ab31f1e9863cb" +const val GIT_DATE = "2023-07-05T21:15:04Z" const val GIT_BRANCH = "master" -const val BUILD_DATE = "2023-07-03T19:57:42Z" -const val BUILD_UNIX_TIME = 1688414262709L -const val DIRTY = 0 +const val BUILD_DATE = "2023-07-05T21:15:07Z" +const val BUILD_UNIX_TIME = 1688591707834L +const val DIRTY = 1 diff --git a/docs/source/todo.rst b/docs/source/todo.rst index d28f97d31..e01fee141 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,6 +1,10 @@ TODO ==== +- upgrade to Kotlin 1.9.0 enum.values() -> enum.entries +- IR: don't use ext.b to clear the msb of an unsigned word, add a specialized instruction for this zmsb.w? +- Fix expericodegen errors (on rockrunners etc) + ...