[comp.lang.c] How much Optimization should be done?

armin@portia.Stanford.EDU (Ronald Mayer) (06/10/89)

Was Re: Loops on the 68020.
Re: postings which had many different versions of for loops 
    i.e.
>for (i = 0; i < COUNT; i ++);
>for (i = 0; i < COUNT; ++ i);
>for (i = 0; ++ i <= COUNT;);
>for (i = 0; i++ < COUNT;);
>for (i = COUNT; i > 0; i --);
>for (i = COUNT; i > 0; --i);
>for (i = COUNT; --i >= 0;);
>for (i = COUNT; i-- > 0;);
>for (i = COUNT; i--;);
    etc.
[assembly code for various architectures showing different code produced in
 each case]

It seems to me, this kind of loop is a reasonably common structure, and
was impressed with how much work it is to find the best way of doing things
like this.  Would there be any way to guess which of these would be
best for a given architecture and/or compiler, without looking at the
assembly code?  (in your opinion,) Should an optimizer be able to identify
these structures, and produce optimal results?

I also have a somewhat related question.
   If I'm really that concerned about speed, how much could I reasonably
expect to gain by using assembly code instead of a typical (or good)
optimizing compiler on various architectures.

   One of my co-workers at my summer job insisted that today's better
compilers are so good that they write better code then people who write
assebly code.  One of my professors here [who has a lot of experience
in this area] once stated that he usually gets about a 4:1 advantage
using assembly language.  Both were refering to Cray machines,
so I guess the answer may be different for non-vector architectures.

		-Ron Mayer
		armin@portia.stanford.edu

"Programming a Cray in a high-level language is like playing
 a piano with boxing gloves." -- O. Buneman[I think]