Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1739239

[PATCH v3 1/2] xxHash: create arch dependent 32/64-bit xxhash()

From Timofey Titovets <nefelim4ag@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v3 1/2] xxHash: create arch dependent 32/64-bit xxhash()
Date 2017-09-25 21:40 +0200
Message-ID <utHot-2k6-1@gated-at.bofh.it> (permalink)
References <utHot-2k6-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


xxh32() - fast on both 32/64-bit platforms
xxh64() - fast only on 64-bit platform

Create xxhash() which will pickup fastest version
on compile time.

As result depends on cpu word size,
the main proporse of that - in memory hashing.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Linux-kernel <linux-kernel@vger.kernel.org>
Cc: Linux-kvm <kvm@vger.kernel.org>
---
 include/linux/xxhash.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/include/linux/xxhash.h b/include/linux/xxhash.h
index 9e1f42cb57e9..2a04ee5c5219 100644
--- a/include/linux/xxhash.h
+++ b/include/linux/xxhash.h
@@ -107,6 +107,29 @@ uint32_t xxh32(const void *input, size_t length, uint32_t seed);
  */
 uint64_t xxh64(const void *input, size_t length, uint64_t seed);

+/**
+ * xxhash() - calculate wordsize hash of the input with a given seed
+ * @input:  The data to hash.
+ * @length: The length of the data to hash.
+ * @seed:   The seed can be used to alter the result predictably.
+ *
+ * If the hash does not need to be comparable between machines with
+ * different word sizes, this function will call whichever of xxh32()
+ * or xxh64() is faster.
+ *
+ * Return:  wordsize hash of the data.
+ */
+
+static inline unsigned long xxhash(const void *input, size_t length,
+				   uint64_t seed)
+{
+#if BITS_PER_LONG == 64
+	return xxh64(input, length, seed);
+#else
+	return xxh32(input, length, seed);
+#endif
+}
+
 /*-****************************
  * Streaming Hash Functions
  *****************************/
--
2.14.1

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH v3 1/2] xxHash: create arch dependent 32/64-bit xxhash() Timofey Titovets <nefelim4ag@gmail.com> - 2017-09-25 21:40 +0200

csiph-web