1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_popcountdi2
8 // Returns: count of 1 bits
10 COMPILER_RT_ABI
int __popcountdi2(di_int a
);
12 int naive_popcount(di_int a
)
15 for (; a
; a
= (du_int
)a
>> 1)
20 int test__popcountdi2(di_int a
)
22 int x
= __popcountdi2(a
);
23 int expected
= naive_popcount(a
);
25 printf("error in __popcountdi2(0x%llX) = %d, expected %d\n",
30 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
31 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
35 if (test__popcountdi2(0))
37 if (test__popcountdi2(1))
39 if (test__popcountdi2(2))
41 if (test__popcountdi2(0xFFFFFFFFFFFFFFFDLL
))
43 if (test__popcountdi2(0xFFFFFFFFFFFFFFFELL
))
45 if (test__popcountdi2(0xFFFFFFFFFFFFFFFFLL
))
48 for (i
= 0; i
< 10000; ++i
)
49 if (test__popcountdi2(((di_int
)rand() << 32) | rand()))