English Amiga Board

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

Thread Tools
Old 05 May 2022, 10:45   #1
Registered User

koobo's Avatar
Join Date: Sep 2019
Location: Finland
Posts: 119
Loops with two instructions

I did some optimizing recently and shrunk a 7 instruction loop into this:

.loop  cmp.l (a2)+,d0
       dbhi  d5,.loop
The array in A2 contains magnitude values as an exponential curve. D0 contains the measurement. The result in D5 is a decibel representation of the magnitude minus one. I thought this was pretty neat.

Any other interesting examples of two instruction loops?
koobo is offline  
Old 14 May 2022, 12:39   #2
Registered User

koobo's Avatar
Join Date: Sep 2019
Location: Finland
Posts: 119
Having fun by myself here, bumped into this when looking at some source:

        move.b  d1,d0
        beq.s   2$
        moveq   #7,d0
        asl.b   #1,d1
        dbcs    d0,1$
Input is a byte in d1, output in d0 is the bit index of the first bit that is set in input.
koobo is offline  
Old 14 May 2022, 13:02   #3

phx's Avatar
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,178
asl.b #1,d1
could be optimized to
add.b d1,d1
(although the assembler would probably do that).

IIRC, these kind of two-byte DBcc loops have an advantage on the 68010, because they are executed from a small cache.

To give an example as well, I'm frequently using it to determine a string length:
        moveq   #-1,d1
.1:     tst.b   (a0)+
        dbeq    d1,.1
        not.w   d1
phx is offline  
Old 14 May 2022, 14:06   #4
Registered User

Join Date: Jun 2016
Location: europe
Posts: 623
The msbitset example above doesn't work if d1 is 0 (returns 0 if no bit is set or bit0 is set). Alternative (returns -1.w if no bit is set):
	moveq	#7,d0
Loop	bclr	d0,d1
	dbne	d0,Loop
edit: btst works too ;P.

Last edited by a/b; 14 May 2022 at 14:13. Reason: btst lives matter
a/b 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
Copper Loops & Horizontal Waits DanielAllsopp Coders. Asm / Hardware 7 03 November 2021 00:47
8svx samples/loops of analogue instruments jotd request.Music 14 12 October 2021 08:12
New Zealand Story - small sample loops causing squeals gary support.Games 1 23 July 2021 15:29
A600+Furia : WB ok, reset loops when opening anything else. Ok with NoFastMem CDTV1991 support.Hardware 19 01 August 2020 17:24
Changing Floppy via Floppy Led Loops Sound smoorke support.WinUAE 0 01 November 2009 17:53

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 11:11.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Page generated in 0.07615 seconds with 15 queries