[systemd-devel] [PATCH 20/26] util: add log2u, log2u_round_up
Michal Schmidt
mschmidt at redhat.com
Thu Oct 16 00:50:58 PDT 2014
two's logarithms for unsigned.
---
src/shared/util.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/shared/util.h b/src/shared/util.h
index 21a90a4..dfb4341 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -829,6 +829,21 @@ static inline int log2i(int x) {
return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
}
+static inline unsigned log2u(unsigned x) {
+ assert(x > 0);
+
+ return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
+}
+
+static inline unsigned log2u_round_up(unsigned x) {
+ assert(x > 0);
+
+ if (x == 1)
+ return 0;
+
+ return log2u(x - 1) + 1;
+}
+
static inline bool logind_running(void) {
return access("/run/systemd/seats/", F_OK) >= 0;
}
--
2.1.0
More information about the systemd-devel
mailing list