blob: 3ea8473aad5c3dd708605c132387ef49fe35c9ef [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- paritysi2_test.c - Test __paritysi2 -------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant5b791f62010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __paritysi2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15#include <stdio.h>
16#include <stdlib.h>
17
18// Returns: 1 if number of bits is odd else returns 0
19
20si_int __paritysi2(si_int a);
21
22int naive_parity(si_int a)
23{
24 int r = 0;
25 for (; a; a = a & (a - 1))
26 r = ~r;
27 return r & 1;
28}
29
30int test__paritysi2(si_int a)
31{
32 si_int x = __paritysi2(a);
33 si_int expected = naive_parity(a);
34 if (x != expected)
35 printf("error in __paritysi2(0x%X) = %d, expected %d\n",
36 a, x, expected);
37 return x != expected;
38}
39
40char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0};
41
42int main()
43{
44 int i;
45 for (i = 0; i < 10000; ++i)
46 if (test__paritysi2(rand()))
47 return 1;
48
49 return 0;
50}