X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=lib%2Fhweight.c;h=63ee4eb1228d13ff4b712cb8f1dd8385bf9c1bcb;hb=d6136f3f749cf68c3295c883cea612afd9919100;hp=360556a7803d4dae582b39edec3e91bb78ac7749;hpb=0136611c62e8650e354b95c76dff6d2ce6030eff;p=safe%2Fjmp%2Flinux-2.6 diff --git a/lib/hweight.c b/lib/hweight.c index 360556a..63ee4eb 100644 --- a/lib/hweight.c +++ b/lib/hweight.c @@ -1,6 +1,6 @@ #include +#include #include -#include /** * hweightN - returns the hamming weight of a N-bit word @@ -11,11 +11,18 @@ unsigned int hweight32(unsigned int w) { +#ifdef ARCH_HAS_FAST_MULTIPLIER + w -= (w >> 1) & 0x55555555; + w = (w & 0x33333333) + ((w >> 2) & 0x33333333); + w = (w + (w >> 4)) & 0x0f0f0f0f; + return (w * 0x01010101) >> 24; +#else unsigned int res = w - ((w >> 1) & 0x55555555); res = (res & 0x33333333) + ((res >> 2) & 0x33333333); res = (res + (res >> 4)) & 0x0F0F0F0F; res = res + (res >> 8); return (res + (res >> 16)) & 0x000000FF; +#endif } EXPORT_SYMBOL(hweight32);