26 November 2020, 17:43 | #1 |
Oldtimer
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
|
dbra to handle long counter
Am I thinking right if I do this
Code:
loop: ... dbra d5,loop addq.w #1,d5 subq.l #1,d5 bge.s loop Code:
loop: ... subq.l #1,d5 bge.s loop |
26 November 2020, 17:55 | #2 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
|
unroll your loops instead if you can.
|
26 November 2020, 18:57 | #3 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
If you have a free register - even an address register - you can put $10000 in it and follow your dbra with sub.l rx,d5 / bcc .loop.
|
26 November 2020, 19:04 | #4 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
I'm not an expert, but I believe your code is correct and isn't inefficient. But, to calculate how many cycles different options will take, I think we need to know the proportion of times that D5 exceeds $ffff, because those become big numbers, and therefore it may be worth doing things a different way. We don't know what your loop is doing, but if you need to do it 65 thousand times every now and then, is there a shortcut?
|
26 November 2020, 19:07 | #5 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
26 November 2020, 19:08 | #6 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
If you are low on registers:
Code:
move.l #$counter-1,dx .l ..code.. dbra dx,.l subi.l #$10000,dx bcc.b .l |
26 November 2020, 19:14 | #7 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
26 November 2020, 19:27 | #8 | ||
Oldtimer
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
|
Unfortunantely already unrolled as much as I want to.
Quote:
Quote:
Need to count that, thanks. |
||
26 November 2020, 19:33 | #9 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Quote:
First of all, the two constructions are not equivalent. If d5 is negative but of absolute value <= 32768, the two constructions perform different. Second, this looks like a rather pointless micro-optimization. Instead of counting every cycle, think about how you can possibly change the algorithm so the loop is not required in first place, or whether you can do something else in parallel while the blitter is performing the loop, or whether you can partially unroll the loop such that the full counter value does not exceed 2^16. |
|
26 November 2020, 20:09 | #10 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
It is not necessarily pointless. As the OP said, D5 is usually $64 but sometimes it's bigger.
So he wants to be able to treat that special case without slowing down the normal one. Thinking about it, perhaps it is possible to duplicate the whole routine, making two versions of it. One will use only single dbra, while the other will have the full longword loop. |
26 November 2020, 21:51 | #11 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,958
|
I remember one dbra routine for handling longword counter. It looks next if i remember right.
Code:
swap D5 ; swapped counter loop32 swap D5 ; to word counter loop ... routine here dbra D5,loop swap D5 ; to highword counter dbra D5,loop32 |
27 November 2020, 10:50 | #12 |
Oldtimer
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
|
Thank you all for your input.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
blizzard 1230 MkII plcc counter chip | arizz | support.Hardware | 1 | 12 April 2022 23:29 |
CD Error Rate Counter PCB Demo | xArtx | Hardware pics | 4 | 26 March 2018 11:49 |
Address pointers with Program Counter | Lonewolf10 | Coders. Asm / Hardware | 8 | 27 October 2015 11:40 |
Program Counter with Offset - why? | Jherek Carnelia | Coders. General | 26 | 21 March 2011 10:49 |
Towers (Warning, long shot and long post) | Drake1009 | Looking for a game name ? | 2 | 13 May 2005 00:11 |
|
|