mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
optimized repeat loop for word counts
This commit is contained in:
parent
543efa4299
commit
32d894d6b6
@ -1011,14 +1011,8 @@ internal class AsmGen(private val program: Program,
|
||||
// note: A/Y must have been loaded with the number of iterations!
|
||||
if(constIterations==0)
|
||||
return
|
||||
if(constIterations==null) {
|
||||
out("""
|
||||
cmp #0
|
||||
bne +
|
||||
cpy #0
|
||||
beq $endLabel ; skip loop if zero iters
|
||||
+""")
|
||||
}
|
||||
// no need to explicitly test for 0 iterations as this is done in the count down logic below
|
||||
|
||||
val counterVar = makeLabel("repeatcounter")
|
||||
out("""
|
||||
sta $counterVar
|
||||
@ -1027,7 +1021,7 @@ $repeatLabel lda $counterVar
|
||||
bne +
|
||||
lda $counterVar+1
|
||||
beq $endLabel
|
||||
+ lda $counterVar
|
||||
lda $counterVar
|
||||
bne +
|
||||
dec $counterVar+1
|
||||
+ dec $counterVar
|
||||
|
@ -2,6 +2,37 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
bench()
|
||||
txt.nl()
|
||||
|
||||
uword total
|
||||
ubyte bb
|
||||
uword ww
|
||||
|
||||
for bb in 0 to 255 {
|
||||
total = 0
|
||||
repeat bb
|
||||
total++
|
||||
txt.print_uw(total)
|
||||
txt.spc()
|
||||
txt.spc()
|
||||
}
|
||||
|
||||
txt.nl()
|
||||
txt.nl()
|
||||
|
||||
for ww in 0 to 600 {
|
||||
total = 0
|
||||
repeat ww
|
||||
total++
|
||||
txt.print_uw(total)
|
||||
txt.spc()
|
||||
txt.spc()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
sub iter(uword iterations) -> uword {
|
||||
uword total = 0
|
||||
@ -26,7 +57,7 @@ main {
|
||||
return total
|
||||
}
|
||||
|
||||
sub start() {
|
||||
sub bench() {
|
||||
uword xx1
|
||||
uword xx2
|
||||
uword xx3
|
||||
|
Loading…
Reference in New Issue
Block a user