Created
September 15, 2017 01:32
-
-
Save sailfish009/b134a9e38441b05511b3c93b2c3650c5 to your computer and use it in GitHub Desktop.
popcnt for old cpu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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