1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_popcountti2
11 // Returns: count of 1 bits
13 COMPILER_RT_ABI
int __popcountti2(ti_int a
);
15 int naive_popcount(ti_int a
)
18 for (; a
; a
= (tu_int
)a
>> 1)
23 int test__popcountti2(ti_int a
)
25 si_int x
= __popcountti2(a
);
26 si_int expected
= naive_popcount(a
);
31 printf("error in __popcountti2(0x%.16llX%.16llX) = %d, expected %d\n",
32 at
.s
.high
, at
.s
.low
, x
, expected
);
37 char assumption_1
[sizeof(ti_int
) == 2*sizeof(di_int
)] = {0};
38 char assumption_2
[sizeof(di_int
)*CHAR_BIT
== 64] = {0};
45 if (test__popcountti2(0))
47 if (test__popcountti2(1))
49 if (test__popcountti2(2))
51 if (test__popcountti2(0xFFFFFFFFFFFFFFFDLL
))
53 if (test__popcountti2(0xFFFFFFFFFFFFFFFELL
))
55 if (test__popcountti2(0xFFFFFFFFFFFFFFFFLL
))
57 if (test__popcountti2(make_ti(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFDLL
)))
59 if (test__popcountti2(make_ti(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFELL
)))
61 if (test__popcountti2(make_ti(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
64 for (i
= 0; i
< 10000; ++i
)
65 if (test__popcountti2(((ti_int
)rand() << 96) | ((ti_int
)rand() << 64) |
66 ((ti_int
)rand() << 32) | rand()))