- Initial checkin of the freebios2 tree
[coreboot.git] / src / lib / clog2.c
1 #include <console/console.h>
2
3 unsigned long log2(unsigned long x)
4 {
5         // assume 8 bits per byte.
6         unsigned long i = 1 << (sizeof(x)*8 - 1);
7         unsigned long pow = sizeof(x) * 8 - 1;
8
9         if (! x) {
10                 printk_warning("%s called with invalid parameter of 0\n",
11                         __FUNCTION__);
12                 return -1;
13         }
14         for(; i > x; i >>= 1, pow--)
15                 ;
16
17         return pow;
18 }