netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "steffen.klassert@secunet.com" <steffen.klassert@secunet.com>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH] xfrm: branchless addr4_match() on 64-bit
Date: Sat, 25 Mar 2017 19:37:12 +0300	[thread overview]
Message-ID: <20170325163712.GA4950@avx2> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DCFFB93A8@AcuExch.aculab.com>

On Fri, Mar 24, 2017 at 05:16:44PM +0000, David Laight wrote:
> From: Alexey Dobriyan
> > Sent: 23 March 2017 23:33
> > Current addr4_match() code has special test for /0 prefixes because of
> > standard required undefined behaviour. However, it is possible to omit
> > it on 64-bit because shifting can be done in a 64-bit register and then
> > truncated to the expected value (which is 0 mask).
> > 
> > Implicit truncation by htonl() fits nicely into R32-within-R64 model
> > on x86-64.
> ...
> >  static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)
> >  {
> > +#ifdef CONFIG_64BIT
> > +	/* L in UL is not a typo. */
> > +	return !((a1 ^ a2) & htonl(~0UL << (32 - prefixlen)));
> > +#else
> >  	/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
> >  	if (prefixlen == 0)
> >  		return true;
> >  	return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
> > +#endif
> 
> Can't this just be written:
> 
>   	if (sizeof (long) == 4 && prefixlen == 0)

Indeed.

>   		return true;
> 	return !((a1 ^ a2) & htonl(0xFFFFFFFFUL << (32 - prefixlen)));

0xFFFFFFFFUL is really long movabs, ~0UL is better.

  reply	other threads:[~2017-03-25 16:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23 23:32 [PATCH] xfrm: branchless addr4_match() on 64-bit Alexey Dobriyan
2017-03-24 17:16 ` David Laight
2017-03-25 16:37   ` Alexey Dobriyan [this message]
2017-03-25 16:41     ` [PATCH v2] " Alexey Dobriyan
2017-03-27 10:37       ` Steffen Klassert
2017-03-27 13:11         ` Alexey Dobriyan

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=20170325163712.GA4950@avx2 \
    --to=adobriyan@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /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).