Skip to content

Instantly share code, notes, and snippets.

@crclark96
Last active June 8, 2020 11:27
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 crclark96/b447afbceef8ad755fab88986e936035 to your computer and use it in GitHub Desktop.
Save crclark96/b447afbceef8ad755fab88986e936035 to your computer and use it in GitHub Desktop.
/tmp
➜ ./a.out
0
1
2
1
8
1
32
#include <stdio.h>
int p2(unsigned int n) {
int r;
__asm__( "popcnt %1, %0; "
: "=r" (r)
: "r" (n)
: "%rdi" );
return r;
}
int main() {
printf("%d\n",p2(0));
printf("%d\n",p2(2));
printf("%d\n",p2(3));
printf("%d\n",p2(4));
printf("%d\n",p2(255));
printf("%d\n",p2(256));
printf("%d\n",p2(-1));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment