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

View File

@ -4,55 +4,32 @@
main {
sub start() {
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
cx16.r0L = 8
cx16.r2L = 9
if (cx16.r0L >= cx16.r2L) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
xx = 4
yy = 4
xx = xx <= yy
if xx
txt.chrout('1')
else
txt.chrout('0')
cx16.r0L = 9
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 = 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")
}
xx = 4
yy = 2
xx = xx <= yy
if xx
txt.chrout('1')
else
txt.chrout('0')
}
}