coreboot-kgpe-d16/src/lib/clog2.c
Stefan Reinauer c02b4fc9db printk_foo -> printk(BIOS_FOO, ...)
Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5266 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2010-03-22 11:42:32 +00:00

29 lines
589 B
C

#undef DEBUG_LOG2
#ifdef DEBUG_LOG2
#include <console/console.h>
#endif
#include <lib.h>
/* Assume 8 bits per byte */
#define CHAR_BIT 8
unsigned long log2(unsigned long x)
{
// assume 8 bits per byte.
unsigned long i = 1ULL << (sizeof(x)* CHAR_BIT - 1ULL);
unsigned long pow = sizeof(x) * CHAR_BIT - 1ULL;
if (! x) {
#ifdef DEBUG_LOG2
printk(BIOS_WARNING, "%s called with invalid parameter of 0\n",
__func__);
#endif
return -1;
}
for(; i > x; i >>= 1, pow--)
;
return pow;
}