- Initial checkin of the freebios2 tree
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@784 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
18
src/lib/clog2.c
Normal file
18
src/lib/clog2.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <console/console.h>
|
||||
|
||||
unsigned long log2(unsigned long x)
|
||||
{
|
||||
// assume 8 bits per byte.
|
||||
unsigned long i = 1 << (sizeof(x)*8 - 1);
|
||||
unsigned long pow = sizeof(x) * 8 - 1;
|
||||
|
||||
if (! x) {
|
||||
printk_warning("%s called with invalid parameter of 0\n",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
for(; i > x; i >>= 1, pow--)
|
||||
;
|
||||
|
||||
return pow;
|
||||
}
|
Reference in New Issue
Block a user