FreeBSD/cddl/contrib/opensolaris/lib/libdtrace/common/dt_subr.c
/*
 * dt_popc() is a fast implementation of population count.  The algorithm is
 * from "Hacker's Delight" by Henry Warren, Jr with a 64-bit equivalent added.
 */
dt_popc() is a fast implementation of population count.  The algorithm is
from "Hacker's Delight" by Henry Warren, Jr with a 64-bit equivalent added.
dt_popc () is a fast implementation of population count . The algorithm is from " Hacker ' s Delight " by Henry Warren Jr with a 64 - bit equivalent added .
ulong_t
dt_popc(ulong_t x)
{
#if defined(_ILP32)
	x = x - ((x >> 1) & 0x55555555UL);
	x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
	x = (x + (x >> 4)) & 0x0F0F0F0FUL;
	x = x + (x >> 8);
	x = x + (x >> 16);
	return (x & 0x3F);
#elif defined(_LP64)
	x = x - ((x >> 1) & 0x5555555555555555ULL);
	x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
	x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
	x = x + (x >> 8);
	x = x + (x >> 16);
	x = x + (x >> 32);
	return (x & 0x7F);
#else
#endif
}
ulong_t dt_popc ( ulong_t x ) { #if defined ( _ILP32 ) x = x - ( ( x >> 1 ) & 0x55555555UL ) ; x = ( x & 0x33333333UL ) + ( ( x >> 2 ) & 0x33333333UL ) ; x = ( x + ( x >> 4 ) ) & 0x0F0F0F0FUL ; x = x + ( x >> 8 ) ; x = x + ( x >> 16 ) ; return ( x & 0x3F ) ; #elif defined ( _LP64 ) x = x - ( ( x >> 1 ) & 0x5555555555555555ULL ) ; x = ( x & 0x3333333333333333ULL ) + ( ( x >> 2 ) & 0x3333333333333333ULL ) ; x = ( x + ( x >> 4 ) ) & 0x0F0F0F0F0F0F0F0FULL ; x = x + ( x >> 8 ) ; x = x + ( x >> 16 ) ; x = x + ( x >> 32 ) ; return ( x & 0x7F ) ; #else #endif }
dt_popc() is a fast implementation of population count.
dt_popc () is a fast implementation of population count .
/* This should be a #warning but for now ignore error. Err: "need td_popc() implementation" */