English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 26 November 2020, 17:43   #1
Geijer
Oldtimer
 
Geijer's Avatar
 
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
instead of this

Code:
loop:
        ...
	subq.l  #1,d5
	bge.s   loop
when I want to make sure the loop logic uses as few cycles as possible on ocs/ecs with only chipmem and d5 is normally $64 but can exceed $ffff
Geijer is offline  
Old 26 November 2020, 17:55   #2
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
unroll your loops instead if you can.
jotd is offline  
Old 26 November 2020, 18:57   #3
meynaf
son of 68k
 
meynaf's Avatar
 
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.
meynaf is offline  
Old 26 November 2020, 19:04   #4
Ernst Blofeld
<optimized out>
 
Ernst Blofeld's Avatar
 
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?
Ernst Blofeld is offline  
Old 26 November 2020, 19:07   #5
Ernst Blofeld
<optimized out>
 
Ernst Blofeld's Avatar
 
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
Quote:
Originally Posted by meynaf View Post
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.
If the dbra only touches the lower 16 bits, could he do a swap on D5 for the outer loop?
Ernst Blofeld is offline  
Old 26 November 2020, 19:08   #6
ross
Defendit numerus
 
ross's Avatar
 
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
[actually same as meynaf ]
ross is offline  
Old 26 November 2020, 19:14   #7
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Ernst Blofeld View Post
If the dbra only touches the lower 16 bits, could he do a swap on D5 for the outer loop?
Yes, swap d5 on start of loop and a swap d5 + subq.w #1,d5 at the end. But it is probably slower than a single sub.l.
meynaf is offline  
Old 26 November 2020, 19:27   #8
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Quote:
Originally Posted by jotd View Post
unroll your loops instead if you can.
Unfortunantely already unrolled as much as I want to.


Quote:
Originally Posted by meynaf View Post
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.
Unfortunantely no free registers at all

Quote:
Originally Posted by ross View Post
If you are low on registers:

Code:
    move.l  #$counter-1,dx
.l  ..code..
    dbra    dx,.l
    subi.l  #$10000,dx
    bcc.b   .l
[actually same as meynaf ]
Good idea, thanks to both of you!

Quote:
Originally Posted by Ernst Blofeld View Post
If the dbra only touches the lower 16 bits, could he do a swap on D5 for the outer loop?
Need to count that, thanks.
Geijer is offline  
Old 26 November 2020, 19:33   #9
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,214
Quote:
Originally Posted by Geijer View Post
Am I thinking right if I do this

Code:
loop:
        ...
        dbra    d5,loop
    addq.w  #1,d5
    subq.l  #1,d5
    bge.s   loop
instead of this

Code:
loop:
        ...
    subq.l  #1,d5
    bge.s   loop
when I want to make sure the loop logic uses as few cycles as possible on ocs/ecs with only chipmem and d5 is normally $64 but can exceed $ffff

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.
Thomas Richter is offline  
Old 26 November 2020, 20:09   #10
meynaf
son of 68k
 
meynaf's Avatar
 
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.
meynaf is offline  
Old 26 November 2020, 21:51   #11
Don_Adan
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
Don_Adan is offline  
Old 27 November 2020, 10:50   #12
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Thank you all for your input.
Geijer is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:03.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08276 seconds with 13 queries