[coreboot] r852  corebootv3/lib
svn at coreboot.org
svn at coreboot.org
Sun Aug 31 22:28:21 CEST 2008
Author: rminnich
Date: 20080831 22:28:21 +0200 (Sun, 31 Aug 2008)
New Revision: 852
Modified:
corebootv3/lib/clog2.c
Log:
log2 is now log2f (floor) and log2c (ceiling) and users MUST pick one or
the other. It really matters for nonpowerof2 numbers.
This breaks k8 builds; fix is coming.
Signedoffby: Ronald G. Minnich <rminnich at gmail.com>
Ackedby: CarlDaniel Hailfinger <cd.hailfinger.devel.2006 at gmx.net>
Modified: corebootv3/lib/clog2.c
===================================================================
 corebootv3/lib/clog2.c 20080831 02:46:37 UTC (rev 851)
+++ corebootv3/lib/clog2.c 20080831 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