Skip to content

Instantly share code, notes, and snippets.

@alexbowe
Created April 7, 2011 05:10
Show Gist options
  • Save alexbowe/907073 to your computer and use it in GitHub Desktop.
Save alexbowe/907073 to your computer and use it in GitHub Desktop.
15bit popcount from Hacker's Delight, p. 72
//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