• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdint.h>
3 
4 
check_popcnt(uint64_t in,uint64_t expected_result,int expected_cc)5 static void check_popcnt(uint64_t in, uint64_t expected_result,
6                          int expected_cc)
7 {
8    uint64_t out = ~expected_result;
9    int cc = ~expected_cc;
10 
11    asm volatile(".insn rre, 0xb9e10000, %[out], %[in]\n\t"
12                 "ipm     %[cc]\n\t"
13                 "srl     %[cc],28\n\t"
14                 : [cc]"=d" (cc), [out]"=d" (out)
15                 : [in]"d" (in)
16                 : "cc");
17    printf("popcnt %16lx -> %16lx %s  cc=%d %s\n",
18           in, out, (out == expected_result ? "   " : "ERR"),
19           cc, (cc == expected_cc ? "   " : "ERR"));
20 }
21 
main()22 int main()
23 {
24    check_popcnt(0, 0, 0);
25    check_popcnt(1, 1, 1);
26    check_popcnt(0x8000000000000000ULL, 0x0100000000000000ULL, 1);
27    check_popcnt(0xffffffffffffffffULL, 0x0808080808080808ULL, 1);
28    check_popcnt(0xff427e3800556bcdULL, 0x0802060300040505ULL, 1);
29    return 0;
30 }
31