lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 22 Nov 2011 18:47:55 +0300
From:	Alexey Dobriyan <adobriyan@...il.com>
To:	Eric Dumazet <eric.dumazet@...il.com>
Cc:	David Laight <David.Laight@...LAB.COM>, davem@...emloft.net,
	netdev@...r.kernel.org
Subject: Re: [PATCH] xfrm: optimize ipv4 selector matching

On Tue, Nov 22, 2011 at 04:10:52PM +0100, Eric Dumazet wrote:
> Le mardi 22 novembre 2011 à 17:59 +0300, Alexey Dobriyan a écrit :
> > On Tue, Nov 22, 2011 at 02:50:59PM -0000, David Laight wrote:
> > >  
> > > > +static inline int addr4_match(const __be32 a1, const __be32 
> > > > a2, const u8 prefixlen)
> > > > +{
> > > > +	/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
> > > > +	if (prefixlen == 0) {
> > > > +		/* Matching constants result in smaller assembly. */
> > > > +		return 0xFFFFFFFFu;
> > > > +	}
> > > > +	return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
> > > > +}
> > > > +
> > > 
> > > It would probably be clearer to 'return 1' when prefixlen is zero.
> > 
> > "return 1" results in bigger code.
> > This function used only in boolean context, so exact return value doesn't matter.
> 
> 
> Thats too ugly, sorry.
> 
> Also, using "const" attributes on integral types (not pointers) make
> code less clear.

No. it doesn't.
It signals to programmer that functions doesn't change its arguments.

> Caller doesnt care if the implementation wants to
> change a1 or a2 or prefixlen.

const is never about caller.
Millions of const qualifiers were injected already, so who cares.

> Please use :
> 
> +static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)
> +{
> +       /* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
> +       if (prefixlen == 0)
> +               return true;
> +       return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
> +}

hmm, bool results in smaller code for -Os, so I'll resend.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ