Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!umd5!trantor.umd.edu!louie
From: louie@trantor.umd.edu (Louis A. Mamakos)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Lattice 4.1 register yuck!
Message-ID: <2837@umd5.umd.edu>
Date: 23 Jun 88 01:32:33 GMT
References: <8806212123.AA01328@cory.Berkeley.EDU> <728@applix.UUCP>
Sender: news@umd5.umd.edu
Reply-To: louie@trantor.umd.edu (Louis A. Mamakos)
Organization: University of Maryland, College Park
Lines: 110

In article <728@applix.UUCP> scott@applix.UUCP (Scott Evernden) writes:
>
>As much as I might agree with you, I have yet to encounter
>a compiler that will do this.  Even the best optimizing compilers
>fair no better than Manx and Lattice in this area.  Does anyone
>know different??
>

I've used two compilers which do what you want.  Given this test program:

main(argc, argv)
	int argc; char **argv;
{
	register int i, j, k;

	for(i = 0; i < 20; i++) {
		foo();
	}
	for(j = 0; j < 30; j++) {
		foo();
	}
	for(k = 0; k < 660; k++) {
		foo();
	}
}


The Greenhills 68000 C compiler produces this code:

	SECTION	9
	XDEF	main
main:
	MOVE.L	D2,-(SP)
	MOVE.L	8(SP),D0
	MOVE.L	12(SP),D0
	MOVEQ	#0,D2
.L10:
	JSR	foo
	ADDQ.L	#1,D2
	MOVEQ	#20,D0
	CMP.L	D2,D0
	BGT	.L10
	MOVEQ	#0,D2
.L7:
	JSR	foo
	ADDQ.L	#1,D2
	MOVEQ	#30,D0
	CMP.L	D2,D0
	BGT	.L7
	MOVEQ	#0,D2
.L4:
	JSR	foo
	ADDQ.L	#1,D2
	CMPI.L	#660,D2
	BLT	.L4
	MOVE.L	(SP)+,D2
	RTS	
	SECTION	14
* allocations for main
*	D2	i
*	D2	j
*	D2	k
*	8(SP)	argc
*	12(SP)	argv
	SECTION	9
	SECTION	14
	XREF	foo
* allocations for module
	SECTION	9
	END

Note that it does, in fact, use D2 for all three register variables.

Looking at the output of the GNU C compiler (unfortunately, I only have the
VAX target around at the moment..) we see much the same thing:

#NO_APP
.text
	.align 1
.globl _main
_main:
	.word 0x40
	clrl r6
L4:
	calls $0,_foo
	incl r6
	cmpl r6,$20
	jlss L4
	clrl r6
L8:
	calls $0,_foo
	incl r6
	cmpl r6,$30
	jlss L8
	clrl r6
L12:
	calls $0,_foo
	incl r6
	cmpl r6,$660
	jlss L12
	ret


This uses r6 for all three register variables. 


I'd love to have a GNU C compiler hosted on my Amiga, just need a few more
meg of memory.
Louis A. Mamakos  WA3YMH    Internet: louie@TRANTOR.UMD.EDU
University of Maryland, Computer Science Center - Systems Programming