🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #10623

Re: Loop instructions

#10623
From: Don CORBITT
Date: Mon, 29 Apr 1991 22:23
47 lines
2155 bytes
>In article <12739@pt.cs.cmu.edu> lindsay@gandalf.cs.cmu.edu (Donald Lindsay) writes:
>>In article <1991Apr16.152438.3445@waikato.ac.nz> 
>>	ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
>>>On the 68000 family, the DBcc loop instructions decrement the 16-bit count
>>>register and stop looping when it reaches -1 (or 65535), not 0.
>>
>>Compiler writers dislike this instruction, but not because of the
>>test semantics. The killer is that the count is 16 bits, on a machine
>>where variables and expressions are naturally 32 bits. This means
>>that the compiler can only use the instruction when it possesses
>>range information. 
>>
>>A sophisticated compiler (with optimization enabled) can often deduce
>>ranges. However, when that machine came out, the instruction was
>>essentially only usable by assembler programmers.

[several readers post workarounds to 16-bittedness of this instruction]

The problem is that you have to do these work-arounds.  The compiler would
like to generate the smallest and fastest code.  If the DBcc instruction
used all 32 bits of the register, the resulting code should be smallest, and
fastest.  Since you need the special case code to test for upper 16 bits
== -1, this code will be larger than required, although it should still be
fastest.

[excuse non-Motorola syntax, it's been too many years]

Today, you need to write something like this:

again:
	// loop body
	DBRA	D0, again
	ADD.L	1, D0
	BRZ	really_done
	SUB.L	1, D0
	BRA	again
really_done:

It would (obviously) much nicer to do:

again:
	// loop body
	DBRA	D0, again

--
Don Corbitt
Microsoft Windows Development
Technical Details
Message-ID: <72087@microsoft.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!microsoft!donc
References: <1991Apr16.152438.3445@waikato.ac.nz> <12739@pt.cs.cmu.edu> <1991Apr21.210031.16749@leland.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!microsoft!donc
From: donc@microsoft.UUCP (Don CORBITT)
Newsgroups: comp.arch
Subject: Re: Loop instructions
Message-ID: <72087@microsoft.UUCP>
Date: 29 Apr 91 22:23:00 GMT
References: <1991Apr16.152438.3445@waikato.ac.nz> <12739@pt.cs.cmu.edu> <1991Apr21.210031.16749@leland.Stanford.EDU>
Reply-To: donc@microsoft.UUCP (Don CORBITT)
Organization: Microsoft Corp., Redmond WA
Lines: 47