Last active
August 24, 2016 06:38
-
-
Save ytakano/72bd7c78c2af94aad88d5582ff725775 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <stdint.h> | |
#define TZCNTQ(DST, SRC) \ | |
do { \ | |
asm ( \ | |
"tzcntq %1, %0;" \ | |
: "=r" (DST) \ | |
: "r" (SRC) \ | |
); \ | |
} while (0) | |
#define LZCNTQ(DST, SRC) \ | |
do { \ | |
asm volatile ( \ | |
"lzcntq %1, %0;" \ | |
: "=r" (DST) \ | |
: "r" (SRC) \ | |
); \ | |
} while (0) | |
uint64_t | |
tzcntq(uint64_t num) | |
{ | |
uint64_t ret; | |
TZCNTQ(ret, num); | |
return ret; | |
} | |
uint64_t | |
lzcntq(uint64_t num) | |
{ | |
uint64_t ret; | |
LZCNTQ(ret, num); | |
return ret; | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
for (int i = 0; i < 64; i++) { | |
uint64_t n = 1; | |
n <<= i; | |
uint64_t cnt; | |
//cnt = __builtin_clzll(n); | |
cnt = lzcntq(n); | |
//LZCNTQ(n, cnt); | |
printf("n = %llx, cnt = %llu\n", n, cnt); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment