Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Optimization help
2018-01-11 21:25
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.
2018-01-11 22:29
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?
2018-01-12 01:21
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.
2018-01-12 06:55
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
2018-01-12 07:00
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
2018-01-12 09:24
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
2018-01-12 10:13
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
wacek/arise
t0m3000/hf^boom!^ibx
A3/AFL
oziphantom
Impetigo/Crescent
Guests online: 99
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Mutetus  (9.7)
3 Jeroen Tel  (9.7)
4 Linus  (9.6)
5 Stinsen  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.065 sec.