[coreboot-gerrit] New patch to review for coreboot: 7346834 lib: Add log2 ceiling function

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Tue Jan 14 06:10:25 CET 2014


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4684

-gerrit

commit 734683460d29c21862e2713f40c80bea1995d827
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Mon Jan 13 00:49:49 2014 -0600

    lib: Add log2 ceiling function
    
    Change-Id: Ifb41050e729a0ce314e4d4918e46f82bc7e16bed
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 src/include/lib.h |  1 +
 src/lib/clog2.c   | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/include/lib.h b/src/include/lib.h
index 3a51533..d6901d9 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -27,6 +27,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 c6fe6f6..b908762 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;
+}



More information about the coreboot-gerrit mailing list