summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/lib.h1
-rw-r--r--src/lib/clog2.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/src/include/lib.h b/src/include/lib.h
index 8de49d3508..bfa68e2eae 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -28,6 +28,7 @@
/* Defined in src/lib/clog2.c */
unsigned long log2(unsigned long x);
#endif
+unsigned long log2_ceil(unsigned long x);
/* Defined in src/lib/lzma.c */
unsigned long ulzma(unsigned char *src, unsigned char *dst);
diff --git a/src/lib/clog2.c b/src/lib/clog2.c
index c6fe6f6cc8..b908762917 100644
--- a/src/lib/clog2.c
+++ b/src/lib/clog2.c
@@ -27,3 +27,18 @@ unsigned long log2(unsigned long x)
return pow;
}
+
+unsigned long log2_ceil(unsigned long x)
+{
+ unsigned long pow;
+
+ if (! x)
+ return -1;
+
+ pow = log2(x);
+
+ if (x > (1ULL << pow))
+ pow++;
+
+ return pow;
+}