shithub: femtolisp

ref: 738a6ef63e019cfd6262b4418f5aa9d8c7c3a1d9
dir: /popcount.c/

View raw version
#include "platform.h"

uint32_t
__builtin_popcount(uint32_t b)
{
	b = b - ((b>>1)&0x55555555);
	b = ((b>>2)&0x33333333) + (b&0x33333333);
	b = ((b>>4)+b)&0x0f0f0f0f;
	b += (b>>8);
	b += (b>>16);
	return b & 0x3f;
}