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>] [day] [month] [year] [list]
Date:   Tue, 25 Aug 2020 14:53:07 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "'linux-sctp@...r.kernel.org'" <linux-sctp@...r.kernel.org>,
        Eric Biggers <ebiggers@...nel.org>,
        'Marcelo Ricardo Leitner' <marcelo.leitner@...il.com>,
        'Catalin Marinas' <catalin.marinas@....com>,
        "'kent.overstreet@...il.com'" <kent.overstreet@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "'Neil Horman'" <nhorman@...driver.com>
Subject: [PATCH 02/13] lib/generic-radix-tree: Optimise out ilog2(variable).

ilog2() is relatively expensive (especially without bit-scan instructions).
Replace the comparisons 'ilog2(x) >= y' with '(x >> y) != 0'.

Signed-off-by: David Laight <david.laight@...lab.com>
---
 lib/generic-radix-tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c
index 5695fe547f9d..d5e97b51308d 100644
--- a/lib/generic-radix-tree.c
+++ b/lib/generic-radix-tree.c
@@ -57,7 +57,7 @@ void *__genradix_ptr(struct __genradix *radix, size_t offset)
 	struct genradix_node *n = genradix_root_to_node(r);
 	unsigned level		= genradix_root_to_depth(r);
 
-	if (ilog2(offset) >= genradix_depth_shift(level))
+	if (offset >> genradix_depth_shift(level))
 		return NULL;
 
 	while (1) {
@@ -115,7 +115,7 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset,
 		n	= genradix_root_to_node(r);
 		level	= genradix_root_to_depth(r);
 
-		if (n && ilog2(offset) < genradix_depth_shift(level))
+		if (n && !(offset >> genradix_depth_shift(level)))
 			break;
 
 		new_node = genradix_alloc_node(gfp_mask);
@@ -171,7 +171,7 @@ void *__genradix_iter_peek(struct genradix_iter *iter,
 	n	= genradix_root_to_node(r);
 	level	= genradix_root_to_depth(r);
 
-	if (ilog2(iter->offset) >= genradix_depth_shift(level))
+	if (iter->offset >> genradix_depth_shift(level))
 		return NULL;
 
 	while (level) {
-- 
2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists