Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Popcount table generated at compile-time using ct_expand. See https://gist.github.com/901235
-module(popcount).
-compile({parse_transform, ct_expand}).
-compile({popcount_table}).
-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