optimized for loop over const bytes, fixed downto 1

This commit is contained in:
Irmen de Jong 2021-02-13 13:27:06 +01:00
parent 1e22170302
commit f6136891cc
3 changed files with 40 additions and 34 deletions

View File

@ -369,7 +369,7 @@ $loopLabel""")
throw AssemblyError("step 0, 1 and -1 should have been handled specifically $stmt")
}
2 -> {
if(range.last==255) {
if(range.last==255 || range.last==254) {
asmgen.out("""
inc $varname
beq $endLabel
@ -377,12 +377,11 @@ $loopLabel""")
bne $loopLabel""")
} else {
asmgen.out("""
inc $varname
inc $varname
lda $varname
cmp #${range.last}
beq $endLabel
inc $varname
inc $varname
jmp $loopLabel""")
cmp #${range.last+2}
bne $loopLabel""")
}
}
-2 -> {
@ -399,12 +398,11 @@ $loopLabel""")
dec $varname
bne $loopLabel""")
else -> asmgen.out("""
dec $varname
dec $varname
lda $varname
cmp #${range.last}
beq $endLabel
dec $varname
dec $varname
jmp $loopLabel""")
cmp #${range.last-2}
bne $loopLabel""")
}
}
else -> {
@ -480,11 +478,10 @@ $loopLabel""")
$endLabel""")
} else {
asmgen.out("""
lda $varname
cmp #${range.last}
beq $endLabel
inc $varname
jmp $loopLabel
lda $varname
cmp #${range.last+1}
bne $loopLabel
$endLabel""")
}
asmgen.loopEndLabels.pop()
@ -512,16 +509,15 @@ $endLabel""")
1 -> {
asmgen.out("""
dec $varname
jmp $loopLabel
bne $loopLabel
$endLabel""")
}
else -> {
asmgen.out("""
lda $varname
cmp #${range.last}
beq $endLabel
dec $varname
jmp $loopLabel
lda $varname
cmp #${range.last-1}
bne $loopLabel
$endLabel""")
}
}
@ -546,7 +542,6 @@ $loopLabel""")
bne +
lda $varname+1
cmp #>${range.last}
bne +
beq $endLabel
+ inc $varname
bne $loopLabel
@ -574,7 +569,6 @@ $loopLabel""")
bne +
lda $varname+1
cmp #>${range.last}
bne +
beq $endLabel
+ lda $varname
bne +

View File

@ -2,7 +2,6 @@
TODO
====
- optimize for loop iterations better to allow proper inx, cpx #value, bne loop instructions (like repeat loop)
- implement the linked_list millfork benchmark
- refactor the asmgen into their own submodule?

View File

@ -4,16 +4,29 @@
main {
sub start() {
txt.print("hello\n")
txt.column(3)
txt.print("hello2\n")
txt.column(8)
txt.print("hello3\n")
txt.column(34)
txt.print("hello4\n")
txt.column(1)
txt.print("hello5\n")
txt.column(0)
txt.print("hello6\n")
ubyte ib
uword iw
ubyte xx
xx=0
for ib in 241 to 253 step 2 {
txt.print_ub(ib)
txt.nl()
xx++
}
for ib in 10 downto 2 step -2 {
txt.print_ub(ib)
txt.nl()
xx--
}
for ib in 6 downto 0 step -2 {
txt.print_ub(ib)
txt.nl()
xx--
}
txt.print_ub(xx)
}
}