Skip to content

Instantly share code, notes, and snippets.

@crclark96

crclark96/pow2.c

Created Jun 1, 2020
Embed
What would you like to do?
/tmp
➜ ./a.out
0
1
0
1
0
1
#include <stdio.h>
int p2(unsigned int n) {
int r;
__asm__( "popcnt %1, %0; "
: "=r" (r)
: "r" (n)
: "%rdi" );
return (r == 1);
}
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));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.