Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Optimization help
2018-01-11 21:25
Trap

Registered: Jul 2010
Posts: 222
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: 226
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: 490
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: 1370
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: 1370
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: 222
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: 5017
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
iAN CooG/HVSC
megasoftargentina
zscs
DeMOSic/HF^MS^BCC^LSD
hedning/G★P
Mason/Unicess
kbs/Pht/Lxt
CA$H/TRiAD
JackAsser/Booze Design
Didi/Laxity
sailor/Triad
Airwolf/F4CG
DKT/Samar
theK/ATL
The Syndrom/TIA/Pret..
Guests online: 67
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

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