Skip to content

Instantly share code, notes, and snippets.

@sailfish009
Created September 15, 2017 01:32
Show Gist options
  • Save sailfish009/b134a9e38441b05511b3c93b2c3650c5 to your computer and use it in GitHub Desktop.
Save sailfish009/b134a9e38441b05511b3c93b2c3650c5 to your computer and use it in GitHub Desktop.
popcnt for old cpu
int popcnt(unsigned int v)
{
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
return (((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24); // count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment