[coreboot] r852 - coreboot-v3/lib

svn at coreboot.org svn at coreboot.org
Sun Aug 31 22:28:21 CEST 2008


Author: rminnich
Date: 2008-08-31 22:28:21 +0200 (Sun, 31 Aug 2008)
New Revision: 852

Modified:
   coreboot-v3/lib/clog2.c
Log:
log2 is now log2f (floor) and log2c (ceiling) and users MUST pick one or 
the other. It really matters for non-power-of-2 numbers. 

This breaks k8 builds; fix is coming. 
Signed-off-by: Ronald G. Minnich <rminnich at gmail.com>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>


Modified: coreboot-v3/lib/clog2.c
===================================================================
--- coreboot-v3/lib/clog2.c	2008-08-31 02:46:37 UTC (rev 851)
+++ coreboot-v3/lib/clog2.c	2008-08-31 20:28:21 UTC (rev 852)
@@ -45,12 +45,15 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-int log2(unsigned int n)
+/**
+ * return the truncated log2 of the number. 
+ * @param n number to take the log of
+ * @return log2 of the smallest integer that is a power of of 2 
+ * and that is <= to the parameter. E.g. log2f(72) is 6. 
+ */ 
+int log2f(unsigned int n)
 {
 	int log2 = 0;
-
-	if (n & (n - 1))
-		log2++;
 	if (n >> 16)
 		log2 += 16, n >>= 16;
 	if (n >> 8)
@@ -63,3 +66,19 @@
 		log2++;
 	return log2;
 }
+
+/**
+ * return the log2 of the number in integer form, rounded up as needed. 
+ * @param n number to take the log of
+ * @return log2 of the smallest integer that is a power of 2
+ * that is >= to the parameter. E.g. log2(72) is 7. 
+ */ 
+int log2c(unsigned int n)
+{
+	int log2 = 0;
+
+	if (n & (n - 1))
+		log2++;
+	return log2 + log2f(n);
+}
+





More information about the coreboot mailing list