lkml.org 
[lkml]   [2006]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
DateFri, 27 Jan 2006 13:55:22 +0900
SubjectRe: [PATCH 8/12] generic hweight{32,16,8}()
From(Akinobu Mita)
On Thu, Jan 26, 2006 at 12:42:09PM +0530, Balbir Singh wrote:

> > +static inline unsigned int hweight32(unsigned int w)
> > +{
> > + unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
> > + res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
> > + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
> > + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
> > + return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
> > +}
> > +
>
> This can be replaced with
>
> register int res=w;
> res=res-((res>>1)&0x55555555);
> res=(res&0x33333333)+((res>>2)&0x33333333);
> res=(res+(res>>4))&0x0f0f0f0f;
> res=res+(res>>8);
> return (res+(res>>16)) & 0xff;

Probably you are right.
Unfortunately, it is difficult for me to prove that sane equivalence.

Anyway those hweight*() functions are copied from include/linux/bitops.h:
generic_hweight*(). So you can optimize these functions.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-01-27 05:58    [from the cache]
©2003-2010