Path: utzoo!utgpu!attcan!uunet!sugar!karl
From: karl@sugar.uu.net (Karl Lehenbauer)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Dividing by a power of two (Re: Aztec compiler ineffeciencies)
Message-ID: <3033@sugar.uu.net>
Date: 29 Nov 88 23:49:16 GMT
References: <8811281919.AA17977@postgres.Berkeley.EDU>
Organization: Sugar Land Unix - Houston, TX
Lines: 17

In article <8811281919.AA17977@postgres.Berkeley.EDU>, dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) writes:
> 	You might say "It is the compiler's job to optimize!", to which I would
> respond: "Which do you think the compiler can optimize better, a shift, or
> a divide?".  Got it?  No matter how good compilers get, certain constructs
> are more apt to optimization than others due to fewer assumptions having to
> be made about them, so the 'good' programmer *always* optimizes his code.

The thing is, though, that divide makes the algorithm work for all the cases
where it's not power of two, so if I write a general solution for "n" bits
I have a general algorithm, and if I set "n" to some power of two, I have
helped the compiler to optimize because I know it knows how to optimize
divides by powers of two -- if it did, which it doesn't.  I'm using unsigned 
ints, by the way.
-- 
-- "We've been following your progress with considerable interest, not to say
-- contempt."  -- Zaphod Beeblebrox IV
-- uunet!sugar!karl, Unix BBS (713) 438-5018