Re: * 4 converted to << 2 for networking code

=?iso-8859-1?Q?Jakob_=D8stergaard?= (jakob@unthought.net)
Wed, 10 Jan 2001 16:11:46 +0100


On Wed, Jan 10, 2001 at 06:03:22PM +0100, antirez wrote:
> On Wed, Jan 10, 2001 at 09:54:04AM -0500, Brian Gerst wrote:
> > This patch isn't really necessary, because GCC will automatically
> > convert multiplications and divisions by powers of two to use shifts.
>
> Sure, but since many << 2 already exists in the net kernel code
> I feel it's better to use just a format, and it seems more appropriate
> to write << 2, just to reflect what we want.
> Also some piece of kernel code may be used with compilers that does not
> optimize power of two.

On most processors <<2 is slower than *4. It's outright stupid to
write <<2 when we mean *4 in order to optimize for one out of a
gazillion supported architectures - even more so when the compiler
for the one CPU where <<2 is faster, will actually generate a shift
instead of a multiply as a part of the standard optimization.

One question for the GCC people: Will gcc change <<2 to *4 on other
architectures ? If so, then my case is not quite as strong of course.

-- 
................................................................
:   jakob@unthought.net   : And I see the elder races,         :
:.........................: putrid forms of man                :
:   Jakob Østergaard      : See him rise and claim the earth,  :
:        OZ9ABN           : his downfall is at hand.           :
:.........................:............{Konkhra}...............:
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/