optimized byte comparison expressions

This commit is contained in:
Irmen de Jong 2023-05-07 15:15:58 +02:00
parent 533d825f1a
commit ffb54110e9
2 changed files with 90 additions and 12 deletions

View File

@ -728,7 +728,16 @@ internal class AssignmentAsmGen(private val program: PtProgram,
"<" -> {
assignExpressionOperandsLeftScratchRightA()
if(signed)
return false // TODO("< signed")
asmgen.out("""
clc
sbc P8ZP_SCRATCH_B1
bvc +
eor #$80
+ bpl +
lda #0
beq ++
+ lda #1
+""")
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1
@ -742,7 +751,16 @@ internal class AssignmentAsmGen(private val program: PtProgram,
"<=" -> {
assignExpressionOperandsLeftScratchRightA()
if(signed)
return false // TODO("< signed")
asmgen.out("""
sec
sbc P8ZP_SCRATCH_B1
bvc +
eor #$80
+ bpl +
lda #0
beq ++
+ lda #1
+""")
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1
@ -752,7 +770,16 @@ internal class AssignmentAsmGen(private val program: PtProgram,
">" -> {
assignExpressionOperandsLeftScratchRightA()
if(signed)
return false // TODO("< signed")
asmgen.out("""
sec
sbc P8ZP_SCRATCH_B1
bvc +
eor #$80
+ bmi +
lda #0
beq ++
+ lda #1
+""")
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1
@ -765,7 +792,16 @@ internal class AssignmentAsmGen(private val program: PtProgram,
">=" -> {
assignExpressionOperandsLeftScratchRightA()
if(signed)
return false // TODO(">= signed")
asmgen.out("""
clc
sbc P8ZP_SCRATCH_B1
bvc +
eor #$80
+ bmi +
lda #0
beq ++
+ lda #1
+""")
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1

View File

@ -4,16 +4,58 @@
main {
sub start() {
txt.print("hello")
; foobar()
}
ubyte[10] envelope_attacks = 99
asmsub foobar() {
%asm {{
nop
rts
}}
; signed and unsigned word:
; ==
; !=
; >
; >=
; <
; <=
; expect yep yep nope nope nope
cx16.r0sL = -10
cx16.r2sL = -9
if (cx16.r0sL <= cx16.r2sL) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0sL = -9
cx16.r2sL = -9
if (cx16.r0sL <= cx16.r2sL) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0sL = -8
cx16.r2sL = -9
if (cx16.r0sL <= cx16.r2sL) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0sL = 0
cx16.r2sL = -9
if (cx16.r0sL <= cx16.r2sL) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
cx16.r0sL = 10
cx16.r2sL = 1
if (cx16.r0sL <= cx16.r2sL) or (envelope_attacks[cx16.r1L]==0) {
txt.print("\nyep\n")
} else {
txt.print("\nnope\n")
}
}
}