[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.2.00.0811171557310.18283@nehalem.linux-foundation.org>
Date: Mon, 17 Nov 2008 16:01:27 -0800 (PST)
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Eric Dumazet <dada1@...mosbay.com>
cc: Ingo Molnar <mingo@...e.hu>, David Miller <davem@...emloft.net>,
rjw@...k.pl, linux-kernel@...r.kernel.org,
kernel-testers@...r.kernel.org, cl@...ux-foundation.org,
efault@....de, a.p.zijlstra@...llo.nl,
Stephen Hemminger <shemminger@...tta.com>
Subject: Re: 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists