Last active
June 24, 2019 17:44
-
-
Save izanbf1803/d00b071f674a297858c411bf62a4095a to your computer and use it in GitHub Desktop.
Fast popcount method.
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
typedef unsigned int uint; | |
uint popcount_short[0xffff]; | |
void popcount_setup() | |
{ | |
popcount_short[0] = 0; | |
for (uint mask = 1; mask < 0xffff; ++mask) { | |
popcount_short[mask] = (mask&1) + popcount_short[mask>>1]; | |
} | |
} | |
inline uint popcount(uint x) | |
{ | |
return popcount_short[x&0xffff] + popcount_short[x>>16&0xffff]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment