lkml.org 
[lkml]   [2008]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: eth_type_trans(): Re: [Bug #11308] tbench regression on each kernel release from 2.6.22 -> 2.6.28


On Tue, 18 Nov 2008, Eric Dumazet wrote:
> > *
> > * Compare two ethernet addresses, returns 0 if equal
> > */
> > static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
> > {
> > const u16 *a = (const u16 *) addr1;
> > const u16 *b = (const u16 *) addr2;
> >
> > BUILD_BUG_ON(ETH_ALEN != 6);
> > return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;

Btw, at least on some Intel CPU's, it would be faster to do this as a
32-bit xor and a 16-bit xor. And if we can know that there is always 2
bytes at the end (because of how the thing was allocated), it's faster
still to do it as a 64-bit xor and a mask.

And that's true even if the addresses are only 2-byte aligned.

The code that gcc generates for "memcmp()" for a constant-size small data
thing is sadly crap. It always generates a "rep cmpsb", even if the size
is something really trivial like 4 bytes, and even if you compare for
exact equality rather than a smaller/greater-than. Gaah.

Linus


\
 
 \ /
  Last update: 2008-11-18 01:05    [W:0.102 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site