mirror of
https://github.com/irmen/prog8.git
synced 2025-01-14 01:29:55 +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!
|
// note: A/Y must have been loaded with the number of iterations!
|
||||||
if(constIterations==0)
|
if(constIterations==0)
|
||||||
return
|
return
|
||||||
if(constIterations==null) {
|
// no need to explicitly test for 0 iterations as this is done in the count down logic below
|
||||||
out("""
|
|
||||||
cmp #0
|
|
||||||
bne +
|
|
||||||
cpy #0
|
|
||||||
beq $endLabel ; skip loop if zero iters
|
|
||||||
+""")
|
|
||||||
}
|
|
||||||
val counterVar = makeLabel("repeatcounter")
|
val counterVar = makeLabel("repeatcounter")
|
||||||
out("""
|
out("""
|
||||||
sta $counterVar
|
sta $counterVar
|
||||||
@ -1027,7 +1021,7 @@ $repeatLabel lda $counterVar
|
|||||||
bne +
|
bne +
|
||||||
lda $counterVar+1
|
lda $counterVar+1
|
||||||
beq $endLabel
|
beq $endLabel
|
||||||
+ lda $counterVar
|
lda $counterVar
|
||||||
bne +
|
bne +
|
||||||
dec $counterVar+1
|
dec $counterVar+1
|
||||||
+ dec $counterVar
|
+ dec $counterVar
|
||||||
|
@ -2,6 +2,37 @@
|
|||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
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 {
|
sub iter(uword iterations) -> uword {
|
||||||
uword total = 0
|
uword total = 0
|
||||||
@ -26,7 +57,7 @@ main {
|
|||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start() {
|
sub bench() {
|
||||||
uword xx1
|
uword xx1
|
||||||
uword xx2
|
uword xx2
|
||||||
uword xx3
|
uword xx3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user