From 3b384ce2a2bb6236a15ece2a20c830911dfeb29f Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sun, 31 Aug 2008 20:28:21 +0000 Subject: [PATCH] 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 Acked-by: Carl-Daniel Hailfinger git-svn-id: svn://coreboot.org/repository/coreboot-v3@852 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- lib/clog2.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/clog2.c b/lib/clog2.c index 37e3843638..39c916e297 100644 --- a/lib/clog2.c +++ b/lib/clog2.c @@ -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 @@ int log2(unsigned int n) 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); +} +