1 // SPDX-License-Identifier: GPL-2.0
3 # include <linux/crush/hash.h>
9 * Robert Jenkins' function for mixing 32-bit values
10 * http://burtleburtle.net/bob/hash/evahash.html
11 * a, b = random bits, c = input and output
13 #define crush_hashmix(a, b, c) do { \
14 a = a-b; a = a-c; a = a^(c>>13); \
15 b = b-c; b = b-a; b = b^(a<<8); \
16 c = c-a; c = c-b; c = c^(b>>13); \
17 a = a-b; a = a-c; a = a^(c>>12); \
18 b = b-c; b = b-a; b = b^(a<<16); \
19 c = c-a; c = c-b; c = c^(b>>5); \
20 a = a-b; a = a-c; a = a^(c>>3); \
21 b = b-c; b = b-a; b = b^(a<<10); \
22 c = c-a; c = c-b; c = c^(b>>15); \
25 #define crush_hash_seed 1315423911
27 static __u32
crush_hash32_rjenkins1(__u32 a
)
29 __u32 hash
= crush_hash_seed
^ a
;
33 crush_hashmix(b
, x
, hash
);
34 crush_hashmix(y
, a
, hash
);
38 static __u32
crush_hash32_rjenkins1_2(__u32 a
, __u32 b
)
40 __u32 hash
= crush_hash_seed
^ a
^ b
;
43 crush_hashmix(a
, b
, hash
);
44 crush_hashmix(x
, a
, hash
);
45 crush_hashmix(b
, y
, hash
);
49 static __u32
crush_hash32_rjenkins1_3(__u32 a
, __u32 b
, __u32 c
)
51 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
;
54 crush_hashmix(a
, b
, hash
);
55 crush_hashmix(c
, x
, hash
);
56 crush_hashmix(y
, a
, hash
);
57 crush_hashmix(b
, x
, hash
);
58 crush_hashmix(y
, c
, hash
);
62 static __u32
crush_hash32_rjenkins1_4(__u32 a
, __u32 b
, __u32 c
, __u32 d
)
64 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
^ d
;
67 crush_hashmix(a
, b
, hash
);
68 crush_hashmix(c
, d
, hash
);
69 crush_hashmix(a
, x
, hash
);
70 crush_hashmix(y
, b
, hash
);
71 crush_hashmix(c
, x
, hash
);
72 crush_hashmix(y
, d
, hash
);
76 static __u32
crush_hash32_rjenkins1_5(__u32 a
, __u32 b
, __u32 c
, __u32 d
,
79 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
^ d
^ e
;
82 crush_hashmix(a
, b
, hash
);
83 crush_hashmix(c
, d
, hash
);
84 crush_hashmix(e
, x
, hash
);
85 crush_hashmix(y
, a
, hash
);
86 crush_hashmix(b
, x
, hash
);
87 crush_hashmix(y
, c
, hash
);
88 crush_hashmix(d
, x
, hash
);
89 crush_hashmix(y
, e
, hash
);
94 __u32
crush_hash32(int type
, __u32 a
)
97 case CRUSH_HASH_RJENKINS1
:
98 return crush_hash32_rjenkins1(a
);
104 __u32
crush_hash32_2(int type
, __u32 a
, __u32 b
)
107 case CRUSH_HASH_RJENKINS1
:
108 return crush_hash32_rjenkins1_2(a
, b
);
114 __u32
crush_hash32_3(int type
, __u32 a
, __u32 b
, __u32 c
)
117 case CRUSH_HASH_RJENKINS1
:
118 return crush_hash32_rjenkins1_3(a
, b
, c
);
124 __u32
crush_hash32_4(int type
, __u32 a
, __u32 b
, __u32 c
, __u32 d
)
127 case CRUSH_HASH_RJENKINS1
:
128 return crush_hash32_rjenkins1_4(a
, b
, c
, d
);
134 __u32
crush_hash32_5(int type
, __u32 a
, __u32 b
, __u32 c
, __u32 d
, __u32 e
)
137 case CRUSH_HASH_RJENKINS1
:
138 return crush_hash32_rjenkins1_5(a
, b
, c
, d
, e
);
144 const char *crush_hash_name(int type
)
147 case CRUSH_HASH_RJENKINS1
: