optimize more carry flag assembly

This commit is contained in:
Irmen de Jong 2023-05-07 23:49:02 +02:00
parent 8cbfe64f19
commit ab02e8a546
2 changed files with 58 additions and 103 deletions

View File

@ -771,15 +771,13 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
"<" -> { "<" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name
cmp $otherName
bcc +
lda #0 lda #0
beq ++ ldy $name
+ lda #1 cpy $otherName
+ sta $name""") rol a
eor #1
sta $name""")
} }
else { else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
@ -798,15 +796,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
"<=" -> { "<=" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $otherName
cmp $name
bcs +
lda #0 lda #0
beq ++ ldy $otherName
+ lda #1 cpy $name
+ sta $name""") rol a
sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
asmgen.out(""" asmgen.out("""
@ -824,15 +819,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
">" -> { ">" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name lda #0
cmp $otherName ldy $name
cpy $otherName
beq + beq +
bcs ++ rol a
+ lda #0
beq ++
+ lda #1
+ sta $name""") + sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
@ -851,15 +843,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
">=" -> { ">=" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name
cmp $otherName
bcs +
lda #0 lda #0
beq ++ ldy $name
+ lda #1 cpy $otherName
+ sta $name""") rol a
sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
asmgen.out(""" asmgen.out("""
@ -966,15 +955,13 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
"<" -> { "<" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name
cmp #$value
bcc +
lda #0 lda #0
beq ++ ldy $name
+ lda #1 cpy #$value
+ sta $name""") rol a
eor #1
sta $name""")
} }
else { else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
@ -993,15 +980,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
"<=" -> { "<=" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda #$value
cmp $name
bcs +
lda #0 lda #0
beq ++ ldy #$value
+ lda #1 cpy $name
+ sta $name""") rol a
sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
asmgen.out(""" asmgen.out("""
@ -1019,15 +1003,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
">" -> { ">" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name lda #0
cmp #$value ldy $name
cpy #$value
beq + beq +
bcs ++ rol a
+ lda #0
beq ++
+ lda #1
+ sta $name""") + sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
@ -1046,15 +1027,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
} }
">=" -> { ">=" -> {
if(dt==DataType.UBYTE) { if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out(""" asmgen.out("""
lda $name
cmp #$value
bcs +
lda #0 lda #0
beq ++ ldy $name
+ lda #1 cpy #$value
+ sta $name""") rol a
sta $name""")
} else { } else {
// see http://www.6502.org/tutorials/compare_beyond.html // see http://www.6502.org/tutorials/compare_beyond.html
asmgen.out(""" asmgen.out("""

View File

@ -4,55 +4,32 @@
main { main {
sub start() { sub start() {
ubyte[10] envelope_attacks = 99 ubyte[10] envelope_attacks = 99
ubyte @shared xx = 4
ubyte yy
; 110
xx = 4
yy = 10
xx = xx <= yy
if xx
txt.chrout('1')
else
txt.chrout('0')
; expect nope yep yep nope yep yep xx = 4
cx16.r0L = 8 yy = 4
cx16.r2L = 9 xx = xx <= yy
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) { if xx
txt.print("\nyep\n") txt.chrout('1')
} else { else
txt.print("\nnope\n") txt.chrout('0')
}
cx16.r0L = 9 xx = 4
cx16.r2L = 9 yy = 2
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) { xx = xx <= yy
txt.print("\nyep\n") if xx
} else { txt.chrout('1')
txt.print("\nnope\n") else
} txt.chrout('0')
cx16.r0L = 10
cx16.r2L = 9
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0L = 0
cx16.r2L = 9
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0L = 9
cx16.r2L = 0
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0L = 255
cx16.r2L = 9
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
} }
} }