Related articles |
---|
programmer optimizations? afsal@genius.tisl.soft.net (Afsal C. Majeed) (1994-12-28) |
Re: programmer optimizations? davidm@Rational.COM (1994-12-31) |
Re: programmer optimizations? fjh@munta.cs.mu.OZ.AU (1995-01-01) |
Re: programmer optimizations? jhowat@lucifer.cs.waikato.ac.nz (1995-01-02) |
Re: programmer optimizations? jbuck@Synopsys.COM (1995-01-02) |
Re: programmer optimizations? eru@tele.nokia.fi (Erkki Ruohtula) (1995-01-11) |
Re: programmer optimizations? conway@munta.cs.mu.OZ.AU (1995-01-05) |
Re: programmer optimizations? bill@amber.ssd.csd.harris.com (1995-01-05) |
Re: programmer optimizations? kerch@albion.camb.inmet.com (1995-01-12) |
Re: programmer optimizations? monnier@di.epfl.ch (Stefan Monnier) (1995-01-21) |
Re: programmer optimizations? synaptx!carambole!daveg@uunet.uu.net (Dave Gillespie) (1995-01-11) |
Re: programmer optimizations? det@sw.stratus.com (David Toland) (1995-01-11) |
Re: programmer optimizations? cdg@nullstone.com (1995-01-23) |
Re: programmer optimizations? hbaker@netcom.com (1995-01-27) |
[6 later articles] |
Newsgroups: | comp.compilers |
From: | bill@amber.ssd.csd.harris.com (Bill Leonard) |
Keywords: | optimize |
Organization: | Harris Computer Systems, Ft. Lauderdale FL |
References: | 94-12-145 |
Date: | Thu, 5 Jan 1995 16:54:47 GMT |
"Afsal C. Majeed" <afsal@genius.tisl.soft.net> writes:
> We are having small debate here as to the use of some of the
> code optimizations by the programmer himself.
>
> e.g.
> replacing (n / 4)
> by (n >> 2)
>
> replacing if ((i < 0) || (j < 0) || (k < 0))
> by if ((i | j | k) < 0)
>
> as you can well imagine, the list is endless
>
> Since this produces somewhat non portable code, the view is that
> such optimizations should be discouraged.
Moderator writes:
> [One reason that such optimizations are discouraged is that they're often
> wrong. Turning n/4 into n>>2 is only correct if n is unsigned.
Not only are such optimizations often wrong, they often are not optimal!
For instance, I remember a machine I worked on not too long ago in which
shift was exceptionally slow, whereas integer divide was pretty fair.
Turns out that dividing by small powers of 2 (e.g., 4) was better done by
shifting, but larger powers of 2 were not.
The best advice is to express the operation you actually want performed,
and let the compiler do the optimizing. Unfortunately, some programmers
write "n / 4" when what they actually meant was "shift n right by 2", and
vice versa. This can often result in sub-optimal code because the compiler
must maintain the semantics of the language, regardless of what you
*meant*, and because the compiler has less knowledge about the data than
the programmer (sometimes).
--
Bill Leonard
Harris Computer Systems Corporation
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309
Bill.Leonard@mail.hcsc.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.