chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
shared/capability: go frugal on space for caps
[elogind.git]
/
src
/
shared
/
util.h
diff --git
a/src/shared/util.h
b/src/shared/util.h
index 531242213490161c7572c25311c2d121289710fd..410ce65f14a9d52d20a42bfe701f9f7c1129f6d0 100644
(file)
--- a/
src/shared/util.h
+++ b/
src/shared/util.h
@@
-860,7
+860,7
@@
static inline unsigned u32ctz(uint32_t n) {
#endif
}
#endif
}
-static inline
int
log2i(int x) {
+static inline
unsigned
log2i(int x) {
assert(x > 0);
return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
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;
}
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);
static inline unsigned log2u_round_up(unsigned x) {
assert(x > 0);