Created
April 7, 2011 05:10
-
-
Save alexbowe/907073 to your computer and use it in GitHub Desktop.
15bit popcount from Hacker's Delight, p. 72
This file contains 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
//Special for 15-bit values on 64bit processors | |
//with fast multiplication | |
//From Hacker's Delight, p. 72 | |
inline uint32_t popcount15(uint32_t x) | |
{ | |
uint64_t y; | |
y = x * 0x0002000400080010; | |
y = y & 0x1111111111111111; | |
y = y * 0x1111111111111111; | |
y = y >> 60; | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment