improve byte '<' and '>' codegen

This commit is contained in:
Irmen de Jong 2021-03-15 22:24:09 +01:00
parent ded1d19737
commit bf23ad78e6
2 changed files with 110 additions and 48 deletions

View File

@ -410,23 +410,48 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
return
} else {
if (left is IdentifierReference) {
val name = asmgen.asmVariableName(left)
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
if(rightConstVal.number.toInt()!=0)
asmgen.out("""
lda $name
sec
sbc #${rightConstVal.number}
bvc +
eor #$80
+ bpl $jumpIfFalseLabel""")
else
asmgen.out(" lda $name | bpl $jumpIfFalseLabel")
asmgen.out(" bpl $jumpIfFalseLabel")
return
}
}
}
// TODO optimize if right is variable or mem-read to avoid use of ZP location
if(right is IdentifierReference) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""
sec
sbc ${asmgen.asmVariableName(right)}
bvc +
eor #$80
+ bpl $jumpIfFalseLabel""")
return
}
var memread = right as? DirectMemoryRead
if(memread==null && right is TypecastExpression)
memread = right.expression as? DirectMemoryRead
if(memread!=null) {
val address = memread.addressExpression as? NumericLiteralValue
if(address!=null) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""
sec
sbc ${address.number.toHex()}
bvc +
eor #$80
+ bpl $jumpIfFalseLabel""")
return
}
}
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""
@ -547,10 +572,9 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
return
} else {
if (left is IdentifierReference) {
val name = asmgen.asmVariableName(left)
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
if(rightConstVal.number.toInt()!=0)
asmgen.out("""
lda $name
clc
sbc #${rightConstVal.number}
bvc +
@ -559,13 +583,43 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
bmi $jumpIfFalseLabel
+""")
else
asmgen.out(" lda $name | bmi $jumpIfFalseLabel | beq $jumpIfFalseLabel")
asmgen.out(" bmi $jumpIfFalseLabel | beq $jumpIfFalseLabel")
return
}
}
}
// TODO optimize if right is variable or mem-read to avoid use of ZP location
if(right is IdentifierReference) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""
clc
sbc ${asmgen.asmVariableName(right)}
bvc +
eor #$80
+ bpl +
bmi $jumpIfFalseLabel
+""")
return
}
var memread = right as? DirectMemoryRead
if(memread==null && right is TypecastExpression)
memread = right.expression as? DirectMemoryRead
if(memread!=null) {
val address = memread.addressExpression as? NumericLiteralValue
if(address!=null) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""
clc
sbc ${address.number.toHex()}
bvc +
eor #$80
+ bpl +
bmi $jumpIfFalseLabel
+""")
return
}
}
asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
asmgen.assignExpressionToRegister(left, RegisterOrPair.A)
asmgen.out("""

View File

@ -1,8 +1,8 @@
%import graphics
; %import graphics
%zeropage basicsafe
main {
sub start() {
sub start2() {
word xx
word yy
@ -45,7 +45,7 @@ main {
; yy++
}
sub start3() {
sub start() {
byte xx
byte yy
@ -85,42 +85,50 @@ main {
if xx!=value
yy++
; while xx>value {
; yy++
; }
; do {
; yy++
; } until xx>value
while xx>value {
yy++
}
while xx<value {
yy++
}
do {
yy++
} until xx>value
do {
yy++
} until xx<value
if xx>value
yy++
if xx<value
yy++
}
; sub start2() {
;
; if xx>value
; yy++
}
sub start2() {
graphics.enable_bitmap_mode()
uword xx
ubyte yy
graphics.line(150,50,150,50)
for yy in 0 to 199-60 step 16 {
for xx in 0 to 319-50 step 16 {
graphics.line(30+xx, 10+yy, 50+xx, 30+yy)
graphics.line(49+xx, 30+yy, 10+xx, 30+yy)
graphics.line(11+xx, 29+yy, 29+xx, 11+yy)
; triangle 2, counter-clockwise
graphics.line(30+xx, 40+yy, 10+xx, 60+yy)
graphics.line(11+xx, 60+yy, 50+xx, 60+yy)
graphics.line(49+xx, 59+yy, 31+xx,41+yy)
}
}
repeat {
}
}
; graphics.enable_bitmap_mode()
;
; uword xx
; ubyte yy
;
; graphics.line(150,50,150,50)
;
; for yy in 0 to 199-60 step 16 {
;
; for xx in 0 to 319-50 step 16 {
; graphics.line(30+xx, 10+yy, 50+xx, 30+yy)
; graphics.line(49+xx, 30+yy, 10+xx, 30+yy)
; graphics.line(11+xx, 29+yy, 29+xx, 11+yy)
;
; ; triangle 2, counter-clockwise
; graphics.line(30+xx, 40+yy, 10+xx, 60+yy)
; graphics.line(11+xx, 60+yy, 50+xx, 60+yy)
; graphics.line(49+xx, 59+yy, 31+xx,41+yy)
; }
; }
;
; repeat {
; }
; }
}