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]
Date:	Mon, 2 Jul 2012 13:25:34 -0700
From:	Andrew Hunter <ahh@...gle.com>
To:	linux-kernel@...r.kernel.org
Subject: [PATCH 1/1] core-kernel: use multiply instead of shifts in hash_64


hash_64(val) = val * (a 64-bit constant).  It is "optimized" by
replacing the multiply by a bunch of shifts and adds.  On modern
machines, this is not an optimization; remove it.

Running this hash function in a independent benchmark, it's about three times
as fast (1ns vs 3ns) with a multiply as with a shift on Westmere. It's also
considerably smaller (and since we inline this function often, that matters.)

Signed-off-by: Andrew Hunter <ahh@...gle.com>
Reviewed-by: Paul Turner <pjt@...gle.com>
---
 include/linux/hash.h |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/hash.h b/include/linux/hash.h
index b80506b..daabc3d 100644
--- a/include/linux/hash.h
+++ b/include/linux/hash.h
@@ -34,7 +34,9 @@
 static inline u64 hash_64(u64 val, unsigned int bits)
 {
 	u64 hash = val;
-
+#if BITS_PER_LONG == 64
+	hash *= GOLDEN_RATIO_PRIME_64;
+#else
 	/*  Sigh, gcc can't optimise this alone like it does for 32 bits. */
 	u64 n = hash;
 	n <<= 18;
@@ -49,7 +51,7 @@ static inline u64 hash_64(u64 val, unsigned int bits)
 	hash += n;
 	n <<= 2;
 	hash += n;
-
+#endif
 	/* High bits are more random, so use them. */
 	return hash >> (64 - bits);
 }
-- 
1.7.7.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ