Final set of smp_write_bus -> mptable_write_buses changes.
[coreboot.git] / src / lib / clog2.c
blobc6fe6f6cc87f81ac062f24c5fb07dd3f325dd93d
1 #undef DEBUG_LOG2
3 #ifdef DEBUG_LOG2
4 #include <console/console.h>
5 #endif
7 #include <lib.h>
9 /* Assume 8 bits per byte */
10 #define CHAR_BIT 8
12 unsigned long log2(unsigned long x)
14 // assume 8 bits per byte.
15 unsigned long i = 1ULL << (sizeof(x)* CHAR_BIT - 1ULL);
16 unsigned long pow = sizeof(x) * CHAR_BIT - 1ULL;
18 if (! x) {
19 #ifdef DEBUG_LOG2
20 printk(BIOS_WARNING, "%s called with invalid parameter of 0\n",
21 __func__);
22 #endif
23 return -1;
25 for(; i > x; i >>= 1, pow--)
28 return pow;