Skip to content

Instantly share code, notes, and snippets.

@KrzysztofCiba
Created June 9, 2013 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrzysztofCiba/5744826 to your computer and use it in GitHub Desktop.
Save KrzysztofCiba/5744826 to your computer and use it in GitHub Desktop.
popcntLUT.py
## bit count look up table in range 0..255
__bcLUT = [ 0 ] * 256
for i in range(256):
__bcLUT[i] = ( i & 1 ) + __bcLUT[i/2]
def popcntLUT( arg ):
""" popcnt using look up table """
assert type(arg) in ( int, long )
return sum( [ __bcLUT[ ( arg >> i ) & 255 ]
for i in range( 0, arg.bit_length(), 8 ) ] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment