summaryrefslogtreecommitdiff
path: root/src/lib/clog2.c
diff options
context:
space:
mode:
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>2014-01-13 00:49:49 -0600
committerAlexandru Gagniuc <mr.nuke.me@gmail.com>2014-01-14 14:14:46 +0100
commit594ef813266053a7d6777b91be7724ee5b62ff7a (patch)
tree2790c7f6b53d09cd81fcdf1fb0694ed188ef656e /src/lib/clog2.c
parent3dd0e72d3b9ad5fb6593db6c81c9ad712711e330 (diff)
downloadcoreboot-594ef813266053a7d6777b91be7724ee5b62ff7a.tar.xz
lib: Add log2 ceiling function
Change-Id: Ifb41050e729a0ce314e4d4918e46f82bc7e16bed Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-on: http://review.coreboot.org/4684 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/lib/clog2.c')
-rw-r--r--src/lib/clog2.c15
1 files changed, 15 insertions, 0 deletions
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;
+}