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


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

Registered: Jul 2010
Posts: 170
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 23:29
dano

Registered: Jul 2004
Posts: 131
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 02:21
Skate

Registered: Jul 2003
Posts: 470
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 07:55
ChristopherJam

Registered: Aug 2004
Posts: 777
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 08:00
ChristopherJam

Registered: Aug 2004
Posts: 777
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 10:24
Trap

Registered: Jul 2010
Posts: 170
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 11:13
Oswald

Registered: Apr 2002
Posts: 4231
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
E$G/I-IokutO ForcE
Pad/Atlantis
Harry Potthead
Scorpion / A../Conte..
Jak T Rip/DMAgic
iAN CooG/HVSC
Sokrates
bugjam
Tim/Active
ghost/excess
Guests online: 48
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.6)
4 The Shores of Reflec..  (9.6)
5 Comaland 100%  (9.6)
6 We Come in Peace  (9.6)
7 Lunatico  (9.6)
8 Incoherent Nightmare  (9.5)
9 Wonderland XII  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Dawnfall V1.1  (9.5)
2 Synthesis  (9.5)
3 FMX Music Demo  (9.5)
4 Pandemoniac Part 2 o..  (9.5)
5 Daah, Those Acid Pil..  (9.5)
6 Treu Love [reu]  (9.5)
7 Merry Xmas 2017  (9.4)
8 Dawnfall  (9.4)
9 Gubbdata 2017 Invite  (9.3)
10 SidRok  (9.3)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.4)
5 Crest  (9.3)
Top Coders
1 Axis  (9.8)
2 Tom-Cat  (9.8)
3 CRT  (9.8)
4 Graham  (9.8)
5 Crossbow  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.259 sec.