Created
June 1, 2020 18:59
-
-
Save crclark96/32887559c45a5e764eb7e1cc141debc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/tmp | |
➜ ./a.out | |
0 | |
1 | |
0 | |
1 | |
0 | |
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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