[lkml]   [2001]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: * 4 converted to << 2 for networking code
Mike Harrold <> writes:


My feeling is that it shouldn't matter if you use <<2 or *4 even if the
compiler optimises - one would hope that the compiler would optimise to
the fastest in both directions.

I agree this should be left to the compiler. The programmer should write *4
when multiplying by 4 and <<2 when shifting left by 2. In the case that
sparked this (converting counts of 32 bit units to counts of octets),
multiplication is the proper conversion operation.

(If performance is truly critical AND profiling shows that writing <<2 instead
of *4 makes a significant difference, doing the shift might be called for. I
hardly believe that's the case here, and the fact that the code has to run on
several architectures and be compiled by various compilers makes it less likely
that this change is a clearcut win.)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:28    [W:0.044 / U:1.856 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site