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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Thu, 2 Jun 2016 18:37:55 +0100
From:	Al Viro <viro@...IV.linux.org.uk>
To:	Rui Teng <rui.teng@...ux.vnet.ibm.com>
Cc:	"Serge E. Hallyn" <serge@...lyn.com>, serge.hallyn@...onical.com,
	james.l.morris@...cle.com, linux-security-module@...r.kernel.org,
	linux-kernel@...r.kernel.org, Andy Lutomirski <luto@...capital.net>
Subject: Re: [PATCH] security: Use || instead of | for boolean expressions

On Fri, Jun 03, 2016 at 12:53:07AM +0800, Rui Teng wrote:

> Of cause, it is only a sample on x86, but even if the generated code is
> not the same, the logical will be better than bitwise.
> Because (a || b || c) means (a != 0 || b != 0 || c != 0), once a != 0,
> the whole expression will be true(short-circuit evaluation).
> and (a | b | c) means calculate the bitwise first and check the result
> in the end. And since the args are all integer, there is no need to
> avoid any short-circuit.

Not obvious at all.  Comparison of the cost of two OR plus one conditional
branch vs. that of "short-circuited" variant is almost certainly going to be
in favour of compiler using bitwise operations anyway.  At the very least
you'll need to examine the first value, so even in the fastest case it's
test + branch taken.  The rest is going to be worse and the whole thing is
going to be not fun for the pipeline either, not to mention higher icache
footprint, etc.

So I would be quite surprised if cc(1) would use short-circuit there,
whichever form you use in the source.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ