removed double mul code

This commit is contained in:
Irmen de Jong 2020-10-19 21:32:44 +02:00
parent 702cf304d0
commit c0a5f8fef0
3 changed files with 26 additions and 51 deletions

View File

@ -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}")
}
}

View File

@ -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""")
}
}
"/" -> {

View File

@ -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()