netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: David Miller <davem@davemloft.net>,
	rick.jones2@hp.com, shemminger@linux-foundation.org,
	netdev@vger.kernel.org
Subject: Re: bridge: faster compare for link local addresses
Date: Tue, 13 Mar 2007 14:38:32 +0100	[thread overview]
Message-ID: <200703131438.32570.dada1@cosmosbay.com> (raw)
In-Reply-To: <p731wjt9r9k.fsf@bingen.suse.de>

On Tuesday 13 March 2007 15:01, Andi Kleen wrote:
> David Miller <davem@davemloft.net> writes:
> > From: Rick Jones <rick.jones2@hp.com>
> > Date: Mon, 12 Mar 2007 17:05:39 -0700
> >
> > > Being paranoid - are there no worries about the alignment of dest?
> >
> > If it's an issue, it's an issue elsewhere too, as the places
> > where Stephen took this idiomatic code from is the code
> > ethernet handling and that runs on every input packet via
> > eth_type_trans().
>
> As a quick note -- when you tell gcc the expected alignment
> by using correct types then moderm gcc should generate fast inline code
> for memcpy/memcmp/etc. by itself. It only falls back to a slow generic
> function when it cannot figure out the alignment or the size.
>
> So I expect just using u32 * instead of char * should have the same
> effect and would be somewhat cleaner and the memcmp could be kept.

For memcpy() yes you can have some optimizations.

But memcmp() has a strong semantic (in libc). memcmp(a, b, 6) should do 6 byte 
compares and conditional branches, regardless of a/b alignment.
Or use the x86 "rep cmpsb" instruction that basically has the same cost.

The trick we use in compare_ether_addr() reduces to one some arithmetic and 
one test.

return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;

I found this line as clean as memcmp(a, b, 6)

(On x86_64, were alignment is not mandatory, we could do :

((*(long *)a ^ *(long*)b) << 16) != 0)

(only if we can always read two extra bytes without faulting, of course :) )


  reply	other threads:[~2007-03-13 13:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-12 23:20 bridge: faster compare for link local addresses Stephen Hemminger
2007-03-12 23:26 ` David Miller
2007-03-13  0:05 ` Rick Jones
2007-03-13  0:10   ` David Miller
2007-03-13 14:01     ` Andi Kleen
2007-03-13 13:38       ` Eric Dumazet [this message]
2007-03-13 19:39         ` David Miller
2007-03-13 20:06           ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200703131438.32570.dada1@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=andi@firstfloor.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=rick.jones2@hp.com \
    --cc=shemminger@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).