[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;
      }
   }
   //x==0 
   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
  .else
     log2size x,sizeofx-1
  .end
.endm

.macro log2 x
  .if x
     log2size x,32
  .else
     -infinity ???
  .end
.endm

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





More information about the coreboot mailing list