optimize some carry flag assembly

This commit is contained in:
Irmen de Jong 2023-05-07 21:03:14 +02:00
parent 68336a76c5
commit 8cbfe64f19
8 changed files with 42 additions and 43 deletions

View File

@ -740,12 +740,11 @@ internal class AssignmentAsmGen(private val program: PtProgram,
+""")
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1
tay
lda #0
cpy P8ZP_SCRATCH_B1
beq +
bcs ++
+ lda #0
beq ++
+ lda #1
rol a
+""")
}
"<=" -> {
@ -783,11 +782,9 @@ internal class AssignmentAsmGen(private val program: PtProgram,
else
asmgen.out("""
cmp P8ZP_SCRATCH_B1
bcc +
lda #0
beq ++
+ lda #1
+""")
rol a
eor #1""")
}
">=" -> {
assignExpressionOperandsLeftScratchRightA()
@ -803,10 +800,10 @@ internal class AssignmentAsmGen(private val program: PtProgram,
+ lda #1
+""")
else
asmgen.out("""
asmgen.out("""
cmp P8ZP_SCRATCH_B1
bcc +
beq +
bcc +
lda #0
beq ++
+ lda #1

View File

@ -771,6 +771,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
"<" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp $otherName
@ -797,6 +798,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
"<=" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $otherName
cmp $name
@ -822,6 +824,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
">" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp $otherName
@ -848,6 +851,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
">=" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp $otherName
@ -962,6 +966,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
"<" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp #$value
@ -988,6 +993,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
"<=" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda #$value
cmp $name
@ -1013,6 +1019,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
">" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp #$value
@ -1039,6 +1046,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
">=" -> {
if(dt==DataType.UBYTE) {
// TODO optimize Carry expr with rol?
asmgen.out("""
lda $name
cmp #$value

View File

@ -310,7 +310,7 @@ asmsub set_irq(uword handler @AY, ubyte useKernal @Pc) clobbers(A) {
sta _modified+1
sty _modified+2
lda #0
adc #0
rol a
sta _use_kernal
sei
lda #<_irq_handler
@ -404,7 +404,7 @@ asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0, ubyte useKernal @P
sta _modified+1
sty _modified+2
lda #0
adc #0
rol a
sta set_irq._use_kernal
lda cx16.r0
ldy cx16.r0+1

View File

@ -356,7 +356,7 @@ asmsub set_irq(uword handler @AY, ubyte useKernal @Pc) clobbers(A) {
sta _modified+1
sty _modified+2
lda #0
adc #0
rol a
sta _use_kernal
sei
lda #<_irq_handler
@ -450,7 +450,7 @@ asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0, ubyte useKernal @P
sta _modified+1
sty _modified+2
lda #0
adc #0
rol a
sta set_irq._use_kernal
lda cx16.r0
ldy cx16.r0+1

View File

@ -697,7 +697,7 @@ asmsub set_irq(uword handler @AY, ubyte useKernal @Pc) clobbers(A) {
sta _modified+1
sty _modified+2
lda #0
adc #0
rol a
sta _use_kernal
sei
lda #<_irq_handler

View File

@ -292,7 +292,7 @@ str = P8ZP_SCRATCH_W1
sta modify_pattern2+2
jsr _match
lda #0
adc #0
rol a
ldx P8ZP_SCRATCH_REG
rts

View File

@ -3,8 +3,7 @@ TODO
For next minor release
^^^^^^^^^^^^^^^^^^^^^^
- find bcc/bcs + lda branches that could be a rol?
- find adc #0 that could be a rol?
- find bcc/bcs + lda branches that could be a rol? (see "TODO optimize Carry expr with rol")
- try to optimize newexpr a bit more
...

View File

@ -1,59 +1,54 @@
%import textio
%option no_sysinit
%zeropage basicsafe
main {
sub start() {
ubyte[10] envelope_attacks = 99
; signed word:
; >
; expect yep nope nope nope yep nope
cx16.r0s = -1000
cx16.r2s = -999
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==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")
}
cx16.r0s = -999
cx16.r2s = -999
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==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.r0s = -998
cx16.r2s = -999
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==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.r0s = 0
cx16.r2s = -999
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==0) {
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.r0s = -999
cx16.r2s = 0
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==0) {
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.r0s = $7fff
cx16.r2s = $7eff
if (cx16.r0s < cx16.r2s) or (envelope_attacks[cx16.r1L]==0) {
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")