mirror of
https://github.com/irmen/prog8.git
synced 2024-11-03 13:07:54 +00:00
optimized for loop over const bytes, fixed downto 1
This commit is contained in:
parent
1e22170302
commit
f6136891cc
@ -369,7 +369,7 @@ $loopLabel""")
|
|||||||
throw AssemblyError("step 0, 1 and -1 should have been handled specifically $stmt")
|
throw AssemblyError("step 0, 1 and -1 should have been handled specifically $stmt")
|
||||||
}
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
if(range.last==255) {
|
if(range.last==255 || range.last==254) {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
inc $varname
|
inc $varname
|
||||||
beq $endLabel
|
beq $endLabel
|
||||||
@ -377,12 +377,11 @@ $loopLabel""")
|
|||||||
bne $loopLabel""")
|
bne $loopLabel""")
|
||||||
} else {
|
} else {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
|
inc $varname
|
||||||
|
inc $varname
|
||||||
lda $varname
|
lda $varname
|
||||||
cmp #${range.last}
|
cmp #${range.last+2}
|
||||||
beq $endLabel
|
bne $loopLabel""")
|
||||||
inc $varname
|
|
||||||
inc $varname
|
|
||||||
jmp $loopLabel""")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-2 -> {
|
-2 -> {
|
||||||
@ -399,12 +398,11 @@ $loopLabel""")
|
|||||||
dec $varname
|
dec $varname
|
||||||
bne $loopLabel""")
|
bne $loopLabel""")
|
||||||
else -> asmgen.out("""
|
else -> asmgen.out("""
|
||||||
|
dec $varname
|
||||||
|
dec $varname
|
||||||
lda $varname
|
lda $varname
|
||||||
cmp #${range.last}
|
cmp #${range.last-2}
|
||||||
beq $endLabel
|
bne $loopLabel""")
|
||||||
dec $varname
|
|
||||||
dec $varname
|
|
||||||
jmp $loopLabel""")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@ -480,11 +478,10 @@ $loopLabel""")
|
|||||||
$endLabel""")
|
$endLabel""")
|
||||||
} else {
|
} else {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
lda $varname
|
|
||||||
cmp #${range.last}
|
|
||||||
beq $endLabel
|
|
||||||
inc $varname
|
inc $varname
|
||||||
jmp $loopLabel
|
lda $varname
|
||||||
|
cmp #${range.last+1}
|
||||||
|
bne $loopLabel
|
||||||
$endLabel""")
|
$endLabel""")
|
||||||
}
|
}
|
||||||
asmgen.loopEndLabels.pop()
|
asmgen.loopEndLabels.pop()
|
||||||
@ -512,16 +509,15 @@ $endLabel""")
|
|||||||
1 -> {
|
1 -> {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
dec $varname
|
dec $varname
|
||||||
jmp $loopLabel
|
bne $loopLabel
|
||||||
$endLabel""")
|
$endLabel""")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
lda $varname
|
|
||||||
cmp #${range.last}
|
|
||||||
beq $endLabel
|
|
||||||
dec $varname
|
dec $varname
|
||||||
jmp $loopLabel
|
lda $varname
|
||||||
|
cmp #${range.last-1}
|
||||||
|
bne $loopLabel
|
||||||
$endLabel""")
|
$endLabel""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -546,7 +542,6 @@ $loopLabel""")
|
|||||||
bne +
|
bne +
|
||||||
lda $varname+1
|
lda $varname+1
|
||||||
cmp #>${range.last}
|
cmp #>${range.last}
|
||||||
bne +
|
|
||||||
beq $endLabel
|
beq $endLabel
|
||||||
+ inc $varname
|
+ inc $varname
|
||||||
bne $loopLabel
|
bne $loopLabel
|
||||||
@ -574,7 +569,6 @@ $loopLabel""")
|
|||||||
bne +
|
bne +
|
||||||
lda $varname+1
|
lda $varname+1
|
||||||
cmp #>${range.last}
|
cmp #>${range.last}
|
||||||
bne +
|
|
||||||
beq $endLabel
|
beq $endLabel
|
||||||
+ lda $varname
|
+ lda $varname
|
||||||
bne +
|
bne +
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- optimize for loop iterations better to allow proper inx, cpx #value, bne loop instructions (like repeat loop)
|
|
||||||
- implement the linked_list millfork benchmark
|
- implement the linked_list millfork benchmark
|
||||||
|
|
||||||
- refactor the asmgen into their own submodule?
|
- refactor the asmgen into their own submodule?
|
||||||
|
@ -4,16 +4,29 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.print("hello\n")
|
ubyte ib
|
||||||
txt.column(3)
|
uword iw
|
||||||
txt.print("hello2\n")
|
ubyte xx
|
||||||
txt.column(8)
|
|
||||||
txt.print("hello3\n")
|
xx=0
|
||||||
txt.column(34)
|
|
||||||
txt.print("hello4\n")
|
for ib in 241 to 253 step 2 {
|
||||||
txt.column(1)
|
txt.print_ub(ib)
|
||||||
txt.print("hello5\n")
|
txt.nl()
|
||||||
txt.column(0)
|
xx++
|
||||||
txt.print("hello6\n")
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user