[coreboot] [commit] r5976 - trunk/src/cpu/amd/car

xdrudis xdrudis at tinet.cat
Thu Oct 21 01:22:00 CEST 2010

On Wed, Oct 20, 2010 at 02:20:12PM -0500, Scott Duplichan wrote:

>    movl $(log2(CONFIG_MMCONF_BUS_NUMBER) << 2), %eax

I have no idea of gas, but  log2(x) for integer x > 0
is the position  of the leftmost 1 in the binary representation
of x (position 0=rightmost). 

int log2(unsigned int x) {
   for(int b=sizeof(unsigned int)-1,b>=0,b--) {
      if (x&(1<<b)) {
         return b;
   return -infinity; //???

Something like (for x<2^32 , tail recursive and imagining gas syntax)

.macro log2size x,sizeofx
  .if x & (1<<(sizeofx-1))
     sizeofx -1
     log2size x,sizeofx-1

.macro log2 x
  .if x
     log2size x,32
     -infinity ???

I'm not claiming this is efficient, but does it need to be ?

More information about the coreboot mailing list