1 //===-- popcountdi2_test.c - Test __popcountdi2 ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __popcountdi2 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
18 // Returns: count of 1 bits
20 si_int
__popcountdi2(di_int a
);
22 int naive_popcount(di_int a
)
25 for (; a
; a
= (du_int
)a
>> 1)
30 int test__popcountdi2(di_int a
)
32 si_int x
= __popcountdi2(a
);
33 si_int expected
= naive_popcount(a
);
35 printf("error in __popcountdi2(0x%llX) = %d, expected %d\n",
40 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
41 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
45 if (test__popcountdi2(0))
47 if (test__popcountdi2(1))
49 if (test__popcountdi2(2))
51 if (test__popcountdi2(0xFFFFFFFFFFFFFFFDLL
))
53 if (test__popcountdi2(0xFFFFFFFFFFFFFFFELL
))
55 if (test__popcountdi2(0xFFFFFFFFFFFFFFFFLL
))
58 for (i
= 0; i
< 10000; ++i
)
59 if (test__popcountdi2(((di_int
)rand() << 32) | rand()))