optimized in-place memory var modification, not using translateExpression()

This commit is contained in:
Irmen de Jong 2020-11-24 21:41:44 +01:00
parent ab1232d742
commit 09f25ffbd9
2 changed files with 31 additions and 56 deletions

View File

@ -228,26 +228,19 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
private fun inplaceModification_byte_value_to_pointer(pointervar: IdentifierReference, operator: String, value: Expression) { private fun inplaceModification_byte_value_to_pointer(pointervar: IdentifierReference, operator: String, value: Expression) {
if(asmgen.options.slowCodegenWarnings) asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
println("warning: slow stack evaluation used (3): @(${pointervar.nameInSource.last()}) $operator= ${value::class.simpleName} at ${value.position}") // TODO
asmgen.translateExpression(value)
val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar)
when (operator) { when (operator) {
// note: ** (power) operator requires floats. // note: ** (power) operator requires floats.
"+" -> asmgen.out(" clc | adc P8ESTACK_LO+1,x") "+" -> asmgen.out(" clc | adc P8ZP_SCRATCH_B1")
"-" -> asmgen.out(" sec | sbc P8ESTACK_LO+1,x") "-" -> asmgen.out(" sec | sbc P8ZP_SCRATCH_B1")
"*" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.multiply_bytes | ldy #0") "*" -> asmgen.out(" ldy P8ZP_SCRATCH_B1 | jsr math.multiply_bytes | ldy #0")
"/" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.divmod_ub_asm | tya | ldy #0") "/" -> asmgen.out(" ldy P8ZP_SCRATCH_B1 | jsr math.divmod_ub_asm | tya | ldy #0")
"%" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.divmod_ub_asm | ldy #0") "%" -> asmgen.out(" ldy P8ZP_SCRATCH_B1 | jsr math.divmod_ub_asm | ldy #0")
"<<" -> { "<<" -> {
asmgen.out(""" asmgen.out("""
pha ldy P8ZP_SCRATCH_B1
lda P8ESTACK_LO+1,x beq +
bne +
pla
rts
+ tay
pla
- asl a - asl a
dey dey
bne - bne -
@ -255,28 +248,22 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
">>" -> { ">>" -> {
asmgen.out(""" asmgen.out("""
pha ldy P8ZP_SCRATCH_B1
lda P8ESTACK_LO+1,x beq +
bne +
pla
rts
+ tay
pla
- lsr a - lsr a
dey dey
bne - bne -
+""") +""")
} }
"&" -> asmgen.out(" and P8ESTACK_LO+1,x") "&" -> asmgen.out(" and P8ZP_SCRATCH_B1")
"^" -> asmgen.out(" eor P8ESTACK_LO+1,x") "^" -> asmgen.out(" eor P8ZP_SCRATCH_B1")
"|" -> asmgen.out(" ora P8ESTACK_LO+1,x") "|" -> asmgen.out(" ora P8ZP_SCRATCH_B1")
else -> throw AssemblyError("invalid operator for in-place modification $operator") else -> throw AssemblyError("invalid operator for in-place modification $operator")
} }
if(ptrOnZp) if(ptrOnZp)
asmgen.out(" sta ($sourceName),y") asmgen.out(" sta ($sourceName),y")
else else
asmgen.out(" sta (P8ZP_SCRATCH_W1),y") asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
asmgen.out(" inx")
} }
private fun inplaceModification_byte_variable_to_pointer(pointervar: IdentifierReference, operator: String, value: IdentifierReference) { private fun inplaceModification_byte_variable_to_pointer(pointervar: IdentifierReference, operator: String, value: IdentifierReference) {

View File

@ -7,43 +7,31 @@ main {
sub start() { sub start() {
float fl = 2.0 uword address = $c000
float cf = 1.5 ubyte ub = 1
ubyte ub2 = 1
if fl == cf+0.5 @(address) = 13
txt.print(".\n")
else
txt.print("!\n")
if fl != cf+0.5 @(address) <<= ub+ub2
txt.print("!\n")
else
txt.print(".\n")
if fl < cf+0.5 txt.print_ub(@(address))
txt.print("!\n") txt.chrout('\n')
else txt.print_ub(13 << (ub+ub2))
txt.print(".\n") txt.chrout('\n')
if fl <= cf+0.5
txt.print(".\n")
else
txt.print("!\n")
if fl > cf+0.5 @(address) = 200
txt.print("!\n")
else
txt.print(".\n")
if fl >= cf+0.5 @(address) >>= ub+ub2
txt.print(".\n")
else
txt.print("!\n")
} txt.print_ub(@(address))
txt.chrout('\n')
txt.print_ub(200 >> (ub+ub2))
txt.chrout('\n')
test_stack.test()
sub func(float fa) -> float {
fa = fa*99.0
return fa + 1.0
} }
} }