summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-01 15:26:46 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-01 17:22:32 -0500
commit7d328b544621d4b1bec936dec612947ad8bfb65a (patch)
tree7d772078fb7a51c9a5561eb9ca7f37eb7e68dcb6 /src/shared/util.h
parent51ddf61540976fc7b09ce5ace707b27f3acc3871 (diff)
shared/capability: go frugal on space for caps
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 5312422134..410ce65f14 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -860,7 +860,7 @@ static inline unsigned u32ctz(uint32_t n) {
#endif
}
-static inline int log2i(int x) {
+static inline unsigned log2i(int x) {
assert(x > 0);
return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
@@ -872,6 +872,16 @@ static inline unsigned log2u(unsigned x) {
return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
}
+static inline unsigned log2u64(uint64_t x) {
+ assert(x > 0);
+
+#if __SIZEOF_LONG_LONG__ == 8
+ return 64 - __builtin_clzll(x) - 1;
+#else
+#error "Wut?"
+#endif
+}
+
static inline unsigned log2u_round_up(unsigned x) {
assert(x > 0);