On Sun, Jan 13, 2008 at 01:47:58AM +0000, [EMAIL PROTECTED] wrote:
> +++ branches/DATASYMS/coregrind/m_libcbase.c  2008-01-13 01:47:56 UTC (rev 
> 7339)
> @@ -563,13 +563,14 @@
> +Int VG_(log2) ( UInt x ) 
>  {
>     Int i;
>     /* Any more than 32 and we overflow anyway... */
>     for (i = 0; i < 32; i++) {
> +      if ((1U << i) == x) return i;
>     }
inefficient ...

  int pos = -1;
  if (n >= 1<<16) { n >>= 16; pos += 16; }
  if (n >= 1<< 8) { n >>=  8; pos +=  8; }
  if (n >= 1<< 4) { n >>=  4; pos +=  4; }
  if (n >= 1<< 2) { n >>=  2; pos +=  2; }
  return pos + n - ((n + 1) >> 2);

on x86, a single "bsr" will do the trick.

unless you actually *want* this: Returns -1 if x is not a power of two.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Confusion, chaos, panic - my work here is done.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Valgrind-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to