1 //===-- popcountsi2_test.c - Test __popcountsi2 ---------------------------===//
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 __popcountsi2 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
18 // Returns: count of 1 bits
20 si_int
__popcountsi2(si_int a
);
22 int naive_popcount(si_int a
)
25 for (; a
; a
= (su_int
)a
>> 1)
30 int test__popcountsi2(si_int a
)
32 si_int x
= __popcountsi2(a
);
33 si_int expected
= naive_popcount(a
);
35 printf("error in __popcountsi2(0x%X) = %d, expected %d\n",
40 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
44 if (test__popcountsi2(0))
46 if (test__popcountsi2(1))
48 if (test__popcountsi2(2))
50 if (test__popcountsi2(0xFFFFFFFD))
52 if (test__popcountsi2(0xFFFFFFFE))
54 if (test__popcountsi2(0xFFFFFFFF))
57 for (i
= 0; i
< 10000; ++i
)
58 if (test__popcountsi2(rand()))