Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2011 07:21
What would you like to do?
Popcount table generated at compile-time using ct_expand. See
-compile({parse_transform, ct_expand}).
-export([popcount16/1, popcount32/1]).
-define(TABLE(B), ct_expand:term( popcount_table:gen_table(B) )).
-define(TABLE16, ct_expand:term( ?TABLE(16) )).
popcount16(V) -> erlang:element(V+1, ?TABLE16).
popcount32(V) -> popcount16( V band 16#ffff )
+ popcount16( (V bsr 16) band 16#ffff).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment