Path: utzoo!attcan!uunet!husc6!cmcl2!adm!xadmx!rbj@dsys.ncsl.nist.gov From: rbj@dsys.ncsl.nist.gov (Root Boy Jim) Newsgroups: comp.unix.wizards Subject: Optimal for loop on the 68020. Message-ID: <19945@adm.BRL.MIL> Date: 8 Jun 89 18:59:46 GMT Sender: news@adm.BRL.MIL Lines: 70 ? From: Jef Poskanzer ? In the referenced message, edler@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@- 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?