#include <lowlevel/types.h>
#include _LL_INC(bitops.h)
+// Find First (least-significant) Set, counting from 0,
+// undefined if no bits set
+
+static inline int ll_ffs(unsigned long val)
+{
+ return __builtin_ctzl(val);
+}
+
+// Find Last (most-significant) Set, counting from 0,
+// undefined if no bits set
+
+static inline int ll_fls(unsigned long val)
+{
+ return (sizeof(unsigned long)*8 - 1) ^ __builtin_clzl(val);
+}
+
+// As above, except on 64-bit values regardless of sizeof(long).
+static inline int ll_ffs64(uint64_t val)
+{
+ return __builtin_ctzll(val);
+}
+
+// Find Last (most-significant) Set, counting from 0,
+// undefined if no bits set
+
+static inline int ll_fls64(unsigned long val)
+{
+ return (sizeof(unsigned long long)*8 - 1) ^ __builtin_clzll(val);
+}
+
static inline int ll_get_order_round_up(unsigned long val)
{
- return val != 1 ? ll_fls(val - 1) + 1 : 0;
+ return val > 1 ? ll_fls(val - 1) + 1 : 0;
}
static inline int ll_get_order_round_down(unsigned long val)