Optimal for loop on the 68020.

there IS no ``average'' SubGenius david at sun.com
Tue Jun 6 13:21:49 AEST 1989


The Sun 680x0 compiler has been able to generate dbcc loops for a long
time.  However, the loop has to be written in a particular form.
Here are some examples compiled with the SunOS 3.5 cc:

1.
	register short s;
	for (s = 127; s != -1; s--) ;

	moveq	#127,d7
LY00001:
	dbra	d7,LY00001

2a.
	register int i;
	for (i = 127; i != -1; i--) ;

	moveq	#127,d6
LY00003:
	subql	#1,d6
	moveq	#-1,d7
	cmpl	d7,d6
	jne	LY00003

(Oops!)

2b.
	register int i;
	i = 127;
	while (--i != -1) ;

	moveq	#127,d6
L20:
	dbra	d6,L20
	clrw	d6
	subql	#1,d6
	jcc	L20

3.
	extern int x;
	register short s;
	s = 127;
	while (x >= 0 && --s != -1) ;

	moveq	#127,d7
L15:
	tstl	_x
	dblt	d7,L15


P.S. Sun users might want to look at the PR_LOOP macros in
<pixrect/pr_impl_util.h>.

-- 
David DiGiacomo, Sun Microsystems, Mt. View, CA  sun!david david at sun.com



More information about the Comp.unix.wizards mailing list