Optimal for loop on the 68020.
Root Boy Jim
rbj at dsys.ncsl.nist.gov
Fri Jun 9 04:59:46 AEST 1989
? From: Jef Poskanzer <pokey at well.uucp>
? In the referenced message, edler at cmcl2.UUCP (Jan Edler) wrote:
? }However, the compiler shouldn't do either of these when d0 is initialized
? }to a value < 65536.
? Not good enough, since the loop body might modify the index variable.
? If the compiler is smart enough to do a global semantic check for this
? sort of thing, then you can do this optimization; but we've already
? established that cc and gcc aren't that smart.
Hey, aren't most programs *I/O bound* anyway? And you can sometimes
unroll your loops.
I seem to remember Chris Torek stating something about using
main()
{
register short n = 10;
do {
printf("n = %d\n");
} while (--n != -1);
}
On a Sun 3/180 SunOS 3.5 compiled with `cc -S -O' generates:
.data
.text
LL0:
|#PROC# 04
.data1
L18:
.ascii "n = %d\12\0"
LF12 = 4
LS12 = 128
LFF12 = 0
LSS12 = 0
LP12 = 16
.data
.text
.globl _main
_main:
|#PROLOGUE# 0
link a6,#-4
movl d7,sp@
|#PROLOGUE# 1
moveq #10,d7
L16:
movw d7,d0
extl d0
movl d0,sp at -
pea L18
jbsr _printf
addqw #8,sp
dbra d7,L16
movl a6@(-4),d7
unlk a6
rts
and prints "n = 10" thru "n = 0". I even tried initializing n to -5
and adding `n += 2' before the printf. Prints -3 thru 0.
? Jef
? Jef Poskanzer {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
? "A banker is a fellow who lends you his umbrella when the sun is shining and
? wants it back the minute it begins to rain." -- Mark Twain
Root Boy Jim is what I am
Are you what you are or what?
More information about the Comp.unix.wizards
mailing list