lkml.org 
[lkml]   [2008]   [Apr]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Alternative implementation of the generic __ffs
On Fri, 18 Apr 2008, Harvey Harrison wrote:

> On Fri, 2008-04-18 at 17:58 -0700, Joe Perches wrote:
> > On Fri, 2008-04-18 at 17:20 -0700, dean gaudet wrote:
> > > any reasonable compiler should figure out the two are the same... but i
> > > really prefer spelling out the lack of dependencies of the computations by
> > > breaking it out per-bit.
> >
> > It seems gcc 4.3 (-Os or -O2) isn't a reasonable compiler.
> >
> > I think this might be best:
> >
> > int ffs32(unsigned int value)
> > {
> > int x;
> >
> > value &= -value;
> > if (!(value & 0x55555555))
> > x = 1;
> > else
> > x = 0;
> > if (!(value & 0x33333333))
> > x |= 2;
> > if (!(value & 0x0f0f0f0f))
> > x |= 4;
> > if (!(value & 0x00ff00ff))
> > x |= 8;
> > if (!(value & 0x0000ffff))
> > x |= 16;
> >
> > return x;
> > }
> >
>
> That produces the shortest assembly for me, also uses the fewest
> registers.

unfortunately it kind of defeats the purpose of the original code... which
is high parallelism / no-dependencies.

have you benchmarked it?

-dean



\
 
 \ /
  Last update: 2008-04-19 03:13    [W:0.077 / U:1.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site