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 kernel-testers" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html