math.multiply_words returns lower 16 bits of the result also in AY (to avoid repeating some load instructions)

This commit is contained in:
Irmen de Jong 2023-07-06 22:54:13 +02:00
parent b4e94ae4dd
commit 1f7180d9a8
6 changed files with 22 additions and 34 deletions

View File

@ -745,10 +745,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
} }
in WordDatatypes -> { in WordDatatypes -> {
asmgen.assignWordOperandsToAYAndVar(expr.right, expr.left, "P8ZP_SCRATCH_W1") asmgen.assignWordOperandsToAYAndVar(expr.right, expr.left, "P8ZP_SCRATCH_W1")
asmgen.out(""" asmgen.out(" jsr math.multiply_words")
jsr math.multiply_words
lda math.multiply_words.result
ldy math.multiply_words.result+1""")
assignRegisterpairWord(assign.target, RegisterOrPair.AY) assignRegisterpairWord(assign.target, RegisterOrPair.AY)
return true return true
} }
@ -775,9 +772,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
sty P8ZP_SCRATCH_W1+1 sty P8ZP_SCRATCH_W1+1
lda #<$value lda #<$value
ldy #>$value ldy #>$value
jsr math.multiply_words jsr math.multiply_words""")
lda math.multiply_words.result
ldy math.multiply_words.result+1""")
assignRegisterpairWord(assign.target, RegisterOrPair.AY) assignRegisterpairWord(assign.target, RegisterOrPair.AY)
return true return true
} }

View File

@ -1221,10 +1221,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
lda #<$value lda #<$value
ldy #>$value ldy #>$value
jsr math.multiply_words jsr math.multiply_words
lda math.multiply_words.result
sta $name sta $name
lda math.multiply_words.result+1 sty $name+1""")
sta $name+1""")
} }
} }
"/" -> { "/" -> {
@ -1682,10 +1680,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
lda $name lda $name
ldy $name+1 ldy $name+1
jsr math.multiply_words jsr math.multiply_words
lda math.multiply_words.result
sta $name sta $name
lda math.multiply_words.result+1 sty $name+1""")
sta $name+1""")
} }
"/" -> { "/" -> {
if(dt==DataType.UWORD) { if(dt==DataType.UWORD) {
@ -1822,11 +1818,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
lda $name lda $name
ldy $name+1 ldy $name+1
jsr math.multiply_words jsr math.multiply_words
lda math.multiply_words.result
sta $name sta $name
lda math.multiply_words.result+1 sty $name+1""")
sta $name+1
""")
} }
"/" -> { "/" -> {
if(dt==DataType.WORD) { if(dt==DataType.WORD) {
@ -1839,8 +1832,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
ldy $otherName+1 ldy $otherName+1
jsr math.divmod_w_asm jsr math.divmod_w_asm
sta $name sta $name
sty $name+1 sty $name+1""")
""")
} }
else { else {
asmgen.out(""" asmgen.out("""
@ -1852,8 +1844,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
ldy $otherName+1 ldy $otherName+1
jsr math.divmod_uw_asm jsr math.divmod_uw_asm
sta $name sta $name
sty $name+1 sty $name+1""")
""")
} }
} }
"%" -> { "%" -> {
@ -2016,10 +2007,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
lda $name lda $name
ldy $name+1 ldy $name+1
jsr math.multiply_words jsr math.multiply_words
lda math.multiply_words.result
sta $name sta $name
lda math.multiply_words.result+1 sty $name+1
sta $name+1
""") """)
} }

View File

@ -51,8 +51,7 @@ multiply_bytes_into_word .proc
multiply_words .proc multiply_words .proc
; -- multiply two 16-bit words into a 32-bit result (signed and unsigned) ; -- 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 ; 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) ; output: multiply_words.result 4-bytes/32-bits product, LSB order (low-to-high) low 16 bits also in AY.
; clobbers: A
sta P8ZP_SCRATCH_W2 sta P8ZP_SCRATCH_W2
sty P8ZP_SCRATCH_W2+1 sty P8ZP_SCRATCH_W2+1
@ -79,6 +78,8 @@ mult16 lda #0
dex dex
bne - bne -
ldx P8ZP_SCRATCH_REG ldx P8ZP_SCRATCH_REG
lda result
ldy result+1
rts rts
result .byte 0,0,0,0 result .byte 0,0,0,0

View File

@ -167,9 +167,8 @@ mul_word .proc
lda P8ESTACK_LO+1,x lda P8ESTACK_LO+1,x
ldy P8ESTACK_HI+1,x ldy P8ESTACK_HI+1,x
jsr math.multiply_words jsr math.multiply_words
lda math.multiply_words.result
sta P8ESTACK_LO+1,x sta P8ESTACK_LO+1,x
lda math.multiply_words.result+1 tya
sta P8ESTACK_HI+1,x sta P8ESTACK_HI+1,x
rts rts
.pend .pend

View File

@ -6,10 +6,10 @@ package prog8.buildversion
const val MAVEN_GROUP = "prog8" const val MAVEN_GROUP = "prog8"
const val MAVEN_NAME = "compiler" const val MAVEN_NAME = "compiler"
const val VERSION = "9.1-SNAPSHOT" const val VERSION = "9.1-SNAPSHOT"
const val GIT_REVISION = 3924 const val GIT_REVISION = 3930
const val GIT_SHA = "204f5591a91d51bc514d4c753907559da0ffa61b" const val GIT_SHA = "b4e94ae4dd1c29a966bb5ea0454ab31f1e9863cb"
const val GIT_DATE = "2023-07-03T19:57:32Z" const val GIT_DATE = "2023-07-05T21:15:04Z"
const val GIT_BRANCH = "master" const val GIT_BRANCH = "master"
const val BUILD_DATE = "2023-07-03T19:57:42Z" const val BUILD_DATE = "2023-07-05T21:15:07Z"
const val BUILD_UNIX_TIME = 1688414262709L const val BUILD_UNIX_TIME = 1688591707834L
const val DIRTY = 0 const val DIRTY = 1

View File

@ -1,6 +1,10 @@
TODO 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)
... ...