This source file includes following definitions.
- __hash_32_generic
- hash_32_generic
- hash_64_generic
- hash_ptr
- hash32_ptr
1 #ifndef _LINUX_HASH_H
2 #define _LINUX_HASH_H
3
4
5
6 #include <asm/types.h>
7 #include <linux/compiler.h>
8
9
10
11
12
13
14 #if BITS_PER_LONG == 32
15 #define GOLDEN_RATIO_PRIME GOLDEN_RATIO_32
16 #define hash_long(val, bits) hash_32(val, bits)
17 #elif BITS_PER_LONG == 64
18 #define hash_long(val, bits) hash_64(val, bits)
19 #define GOLDEN_RATIO_PRIME GOLDEN_RATIO_64
20 #else
21 #error Wordsize not 32 or 64
22 #endif
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 #define GOLDEN_RATIO_32 0x61C88647
42 #define GOLDEN_RATIO_64 0x61C8864680B583EBull
43
44 #ifdef CONFIG_HAVE_ARCH_HASH
45
46 #include <asm/hash.h>
47 #endif
48
49
50
51
52
53
54
55
56
57 #ifndef HAVE_ARCH__HASH_32
58 #define __hash_32 __hash_32_generic
59 #endif
60 static inline u32 __hash_32_generic(u32 val)
61 {
62 return val * GOLDEN_RATIO_32;
63 }
64
65 #ifndef HAVE_ARCH_HASH_32
66 #define hash_32 hash_32_generic
67 #endif
68 static inline u32 hash_32_generic(u32 val, unsigned int bits)
69 {
70
71 return __hash_32(val) >> (32 - bits);
72 }
73
74 #ifndef HAVE_ARCH_HASH_64
75 #define hash_64 hash_64_generic
76 #endif
77 static __always_inline u32 hash_64_generic(u64 val, unsigned int bits)
78 {
79 #if BITS_PER_LONG == 64
80
81 return val * GOLDEN_RATIO_64 >> (64 - bits);
82 #else
83
84 return hash_32((u32)val ^ __hash_32(val >> 32), bits);
85 #endif
86 }
87
88 static inline u32 hash_ptr(const void *ptr, unsigned int bits)
89 {
90 return hash_long((unsigned long)ptr, bits);
91 }
92
93
94 static inline u32 hash32_ptr(const void *ptr)
95 {
96 unsigned long val = (unsigned long)ptr;
97
98 #if BITS_PER_LONG == 64
99 val ^= (val >> 32);
100 #endif
101 return (u32)val;
102 }
103
104 #endif