chiark / gitweb /
timedated: use builtins for integer log and exp
[elogind.git] / src / shared / util.h
index c596d795d3666d14e92741fb6c5bc32d484c1ffa..7752b1e3dff660e265015ecda90b2ce8c39a65a1 100644 (file)
@@ -782,6 +782,12 @@ static inline unsigned u32ctz(uint32_t n) {
 #endif
 }
 
+static inline int log2i(int x) {
+        assert(x > 0);
+
+        return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
+}
+
 static inline bool logind_running(void) {
         return access("/run/systemd/seats/", F_OK) >= 0;
 }