mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
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@gmail.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: svn://coreboot.org/repository/coreboot-v3@852 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
47043d7ab3
commit
3b384ce2a2
1 changed files with 23 additions and 4 deletions
27
lib/clog2.c
27
lib/clog2.c
|
@ -45,12 +45,15 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** 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;
|
int log2 = 0;
|
||||||
|
|
||||||
if (n & (n - 1))
|
|
||||||
log2++;
|
|
||||||
if (n >> 16)
|
if (n >> 16)
|
||||||
log2 += 16, n >>= 16;
|
log2 += 16, n >>= 16;
|
||||||
if (n >> 8)
|
if (n >> 8)
|
||||||
|
@ -63,3 +66,19 @@ int log2(unsigned int n)
|
||||||
log2++;
|
log2++;
|
||||||
return 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue