[ros-dev] ping Alex regarding log2() for scheduler

Mark Junker mjscod at gmx.de
Wed Mar 23 23:35:56 CET 2005


Royce Mitchell III schrieb:

> I managed to shave off another comparison in favor of a shift:

What about using a 64k table?

static
BYTE HighestBits[65536] = {
 0x00, 0x01, 0x02, 0x02, ... // and so on
};

// returns 0xFF when no bits set in dwValue
BYTE highest_bit(DWORD dwValue)
{
  BYTE ret;
  if (i > 0xffff) {
    ret = HighestBits[(int) (dwValue >> 16)];
  } else {
    ret = HighestBits[(int) dwValue];
  }
  return ret - 1;
}

Regards,
Mark



More information about the Ros-dev mailing list