summaryrefslogtreecommitdiff
path: root/tools/lib/bpf/hashmap.h
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2020-07-22 10:22:02 +0200
committerPeter Zijlstra <peterz@infradead.org>2020-07-22 10:22:02 +0200
commit015dc08918785201199ed3450c22bb8939f09dfe (patch)
tree7ba52e0b1e518fa750aaac0c1da8dd70c3eca1eb /tools/lib/bpf/hashmap.h
parent9d246053a69196c7c27068870e9b4b66ac536f68 (diff)
parentd136122f58458479fd8926020ba2937de61d7f65 (diff)
Merge branch 'sched/urgent'
Diffstat (limited to 'tools/lib/bpf/hashmap.h')
-rw-r--r--tools/lib/bpf/hashmap.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
index df59fd4fc95b..e0af36b0e5d8 100644
--- a/tools/lib/bpf/hashmap.h
+++ b/tools/lib/bpf/hashmap.h
@@ -11,14 +11,18 @@
#include <stdbool.h>
#include <stddef.h>
#include <limits.h>
-#ifndef __WORDSIZE
-#define __WORDSIZE (__SIZEOF_LONG__ * 8)
-#endif
static inline size_t hash_bits(size_t h, int bits)
{
/* shuffle bits and return requested number of upper bits */
- return (h * 11400714819323198485llu) >> (__WORDSIZE - bits);
+#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
+ /* LP64 case */
+ return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
+#elif (__SIZEOF_SIZE_T__ <= __SIZEOF_LONG__)
+ return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits);
+#else
+# error "Unsupported size_t size"
+#endif
}
typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);