summaryrefslogtreecommitdiffstats
path: root/include/linux/hash.h
diff options
context:
space:
mode:
authorGeorge Spelvin <linux@sciencehorizons.net>2016-05-26 22:11:51 -0400
committerGeorge Spelvin <linux@sciencehorizons.net>2016-05-28 15:48:31 -0400
commit468a9428521e7d00fb21250af363eb94dc1d6861 (patch)
tree75a5e7b73594e643a1f8ca870bcc4fe679bfb610 /include/linux/hash.h
parent2a18da7a9c7886f1c7307f8d3f23f24318583f03 (diff)
<linux/hash.h>: Add support for architecture-specific functions
This is just the infrastructure; there are no users yet. This is modelled on CONFIG_ARCH_RANDOM; a CONFIG_ symbol declares the existence of <asm/hash.h>. That file may define its own versions of various functions, and define HAVE_* symbols (no CONFIG_ prefix!) to suppress the generic ones. Included is a self-test (in lib/test_hash.c) that verifies the basics. It is NOT in general required that the arch-specific functions compute the same thing as the generic, but if a HAVE_* symbol is defined with the value 1, then equality is tested. Signed-off-by: George Spelvin <linux@sciencehorizons.net> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Greg Ungerer <gerg@linux-m68k.org> Cc: Andreas Schwab <schwab@linux-m68k.org> Cc: Philippe De Muyter <phdm@macq.eu> Cc: linux-m68k@lists.linux-m68k.org Cc: Alistair Francis <alistai@xilinx.com> Cc: Michal Simek <michal.simek@xilinx.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: uclinux-h8-devel@lists.sourceforge.jp
Diffstat (limited to 'include/linux/hash.h')
-rw-r--r--include/linux/hash.h27
1 files changed, 24 insertions, 3 deletions
diff --git a/include/linux/hash.h b/include/linux/hash.h
index 613cfde3a1e0..ad6fa21d977b 100644
--- a/include/linux/hash.h
+++ b/include/linux/hash.h
@@ -41,19 +41,40 @@
41#define GOLDEN_RATIO_32 0x61C88647 41#define GOLDEN_RATIO_32 0x61C88647
42#define GOLDEN_RATIO_64 0x61C8864680B583EBull 42#define GOLDEN_RATIO_64 0x61C8864680B583EBull
43 43
44#ifdef CONFIG_HAVE_ARCH_HASH
45/* This header may use the GOLDEN_RATIO_xx constants */
46#include <asm/hash.h>
47#endif
44 48
45static inline u32 __hash_32(u32 val) 49/*
50 * The _generic versions exist only so lib/test_hash.c can compare
51 * the arch-optimized versions with the generic.
52 *
53 * Note that if you change these, any <asm/hash.h> that aren't updated
54 * to match need to have their HAVE_ARCH_* define values updated so the
55 * self-test will not false-positive.
56 */
57#ifndef HAVE_ARCH__HASH_32
58#define __hash_32 __hash_32_generic
59#endif
60static inline u32 __hash_32_generic(u32 val)
46{ 61{
47 return val * GOLDEN_RATIO_32; 62 return val * GOLDEN_RATIO_32;
48} 63}
49 64
50static inline u32 hash_32(u32 val, unsigned int bits) 65#ifndef HAVE_ARCH_HASH_32
66#define hash_32 hash_32_generic
67#endif
68static inline u32 hash_32_generic(u32 val, unsigned int bits)
51{ 69{
52 /* High bits are more random, so use them. */ 70 /* High bits are more random, so use them. */
53 return __hash_32(val) >> (32 - bits); 71 return __hash_32(val) >> (32 - bits);
54} 72}
55 73
56static __always_inline u32 hash_64(u64 val, unsigned int bits) 74#ifndef HAVE_ARCH_HASH_64
75#define hash_64 hash_64_generic
76#endif
77static __always_inline u32 hash_64_generic(u64 val, unsigned int bits)
57{ 78{
58#if BITS_PER_LONG == 64 79#if BITS_PER_LONG == 64
59 /* 64x64-bit multiply is efficient on all 64-bit processors */ 80 /* 64x64-bit multiply is efficient on all 64-bit processors */