1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_popcountsi2
8 // Returns: count of 1 bits
10 COMPILER_RT_ABI
int __popcountsi2(si_int a
);
12 int naive_popcount(si_int a
)
15 for (; a
; a
= (su_int
)a
>> 1)
20 int test__popcountsi2(si_int a
)
22 si_int x
= __popcountsi2(a
);
23 si_int expected
= naive_popcount(a
);
25 printf("error in __popcountsi2(0x%X) = %d, expected %d\n",
30 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
34 if (test__popcountsi2(0))
36 if (test__popcountsi2(1))
38 if (test__popcountsi2(2))
40 if (test__popcountsi2(0xFFFFFFFD))
42 if (test__popcountsi2(0xFFFFFFFE))
44 if (test__popcountsi2(0xFFFFFFFF))
47 for (i
= 0; i
< 10000; ++i
)
48 if (test__popcountsi2(rand()))