summaryrefslogtreecommitdiffstats
path: root/cmd/zpool/zpool_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/zpool/zpool_util.c')
-rw-r--r--cmd/zpool/zpool_util.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/zpool/zpool_util.c b/cmd/zpool/zpool_util.c
index 43abfa23b..c26c0eb39 100644
--- a/cmd/zpool/zpool_util.c
+++ b/cmd/zpool/zpool_util.c
@@ -111,3 +111,29 @@ isnumber(char *str)
return (1);
}
+
+/*
+ * Find highest one bit set.
+ * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
+ */
+int
+highbit64(uint64_t i)
+{
+ if (i == 0)
+ return (0);
+
+ return (NBBY * sizeof (uint64_t) - __builtin_clzll(i));
+}
+
+/*
+ * Find lowest one bit set.
+ * Returns bit number + 1 of lowest bit that is set, otherwise returns 0.
+ */
+int
+lowbit64(uint64_t i)
+{
+ if (i == 0)
+ return (0);
+
+ return (__builtin_ffsll(i));
+}