X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fhweight.c;h=2c819d6a41a85f4965123aa7c7b109dbcce36ce9;hb=fde57152fc4d04099588c83cdb8beb433b6ad7bd;hp=738ed277380118eca1672e7095023c95ac7340c6;hpb=51aa2da8cf422a06ddfa1ce673f3bfc03f96b86e;p=fio.git diff --git a/lib/hweight.c b/lib/hweight.c index 738ed277..2c819d6a 100644 --- a/lib/hweight.c +++ b/lib/hweight.c @@ -17,3 +17,17 @@ unsigned int hweight32(uint32_t w) res = res + (res >> 8); return (res + (res >> 16)) & 0x000000FF; } + +unsigned int hweight64(uint64_t w) +{ +#if BITS_PER_LONG == 32 + return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); +#else + uint64_t res = w - ((w >> 1) & 0x5555555555555555ULL); + res = (res & 0x3333333333333333ULL) + ((res >> 2) & 0x3333333333333333ULL); + res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0FULL; + res = res + (res >> 8); + res = res + (res >> 16); + return (res + (res >> 32)) & 0x00000000000000FFULL; +#endif +}