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-next>] [day] [month] [year] [list]
Message-Id: <1482513603-9630-1-git-send-email-mawilcox@linuxonhyperv.com>
Date:   Fri, 23 Dec 2016 09:20:03 -0800
From:   Matthew Wilcox <mawilcox@...uxonhyperv.com>
To:     Yury Norov <yury.norov@...il.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        George Spelvin <linux@...izon.com>,
        Akinobu Mita <akinobu.mita@...il.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Andrew Morton <akpm@...ux-foundation.org>,
        linux-kernel@...r.kernel.org
Cc:     Matthew Wilcox <mawilcox@...rosoft.com>
Subject: [PATCH] find_bit: Micro-optimise find_next_*_bit

From: Matthew Wilcox <mawilcox@...rosoft.com>

This saves 20 bytes on my x86-64 build, mostly due to alignment
considerations ... I think it actually saves about five bytes of
instructions.  There's really two parts to this commit.  First, the
first half of the test: (!nbits || start >= nbits) is trivially a subset
of the second half, since nbits and start are both unsigned.  Second,
while looking at the disassembly, I noticed that GCC was predicting the
branch taken.  Since this is a failure case, it's clearly the less likely
of the two branches, so add an unlikely() to override GCC's heuristics.

Signed-off-by: Matthew Wilcox <mawilcox@...rosoft.com>
---
 lib/find_bit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/find_bit.c b/lib/find_bit.c
index 18072ea9c20e..7d4a681d625f 100644
--- a/lib/find_bit.c
+++ b/lib/find_bit.c
@@ -33,7 +33,7 @@ static unsigned long _find_next_bit(const unsigned long *addr,
 {
 	unsigned long tmp;
 
-	if (!nbits || start >= nbits)
+	if (unlikely(start >= nbits))
 		return nbits;
 
 	tmp = addr[start / BITS_PER_LONG] ^ invert;
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ