1 //===-- paritydi2_test.c - Test __paritydi2 -------------------------------===//
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 __paritydi2 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
18 // Returns: 1 if number of bits is odd else returns 0
20 si_int
__paritydi2(di_int a
);
22 int naive_parity(di_int a
)
25 for (; a
; a
= a
& (a
- 1))
30 int test__paritydi2(di_int a
)
32 si_int x
= __paritydi2(a
);
33 si_int expected
= naive_parity(a
);
35 printf("error in __paritydi2(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};
46 for (i
= 0; i
< 10000; ++i
)
47 if (test__paritydi2(((di_int
)rand() << 32) + rand()))