| |
Trap
Registered: Jul 2010 Posts: 223 |
Optimization help
I wonder if this can be done in a more cycle-efficient way. Imagine an unrolled loop like this:
sta (zp_Something),y
adc #DeltaA
tax
tya
adc #DeltaY
tay
txa
Since DeltaA and DeltaY can be any value, it's not a simple matter of just adding one. The challenge is obviously to add to Y. Because it is unrolled, changing the ZP indexed STA to an absolute is not an option because it would require some level of self-modifying code and any saved cycles would most likely be lost in the modifying part of the code. |
|
| |
Dano
Registered: Jul 2004 Posts: 234 |
Would it be possible to offload the adc stuff to a prepare loop beforehand? so you load the values from zp in time with the values calculated earlier? |
| |
Skate
Registered: Jul 2003 Posts: 494 |
First thing comes to my mind to get rid of tax and save 2 cycles:
sta (zp_Something),y
sbx #255-DeltaA
tya
adc #DeltaY
tay
txa
you need a "tax" or something like "lax startValue" instead of "lda startValue" at the beginning. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Use a set of zero page pointers offset from each other by deltaY.
Then you only need to update Y every numpointers iterations.
; init code
lda zp0
ldx zp0+1
clc
adc deltaY
sta zp1
bcc :+
clc
inx
: stx zp1+1
adc deltaY
sta zp2
bcc :+
clc
inx
: stx zp2+1
adc deltaY
sta zp3
bcc :+
clc
inx
: stx zp3+1
...
; unrolled loop
sta (zp0),y
sbx #255-DeltaA
txa
sta (zp1),y
sbx #255-DeltaA
txa
sta (zp2),y
sbx #255-DeltaA
txa
sta (zp3),y
sbx #255-DeltaA
tya
adc #DeltaY*4
tay
txa
;etc
|
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Also, if you start out with Y being the low byte of your start address, then your pointer set can just have 0,deltaY,deltaY*2 etc in the low bytes, and there will be no carry to compute for the later offsets.
; init code
ldy zp0 ; to use in loop
lda#0
sta zp0
ldx zp0+1
lda deltaY
sta zp1
stx zp1+1
asl
sta zp2
stx zp2+1
adc deltaY
sta zp3
stx zp3+1
|
| |
Trap
Registered: Jul 2010 Posts: 223 |
Some really great ideas here. Thanks. I did look at sbx in fact, but I couldn't get my head around a good way to use it.
Also the table lookup with DeltaY is great. I'll try to work out a combination of these.
You guys are so clever. Thank you! <3
/Trap |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
sta (zp0),y
adc #DeltaA
sta (zp1),y
adc #DeltaA
sta (zp2),y
adc #DeltaA
tax
sta (zp3),y
tya
adc #DeltaY*4
tay
txa
adc #DeltaA |