1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_paritydi2
3 //===-- paritydi2_test.c - Test __paritydi2 -------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __paritydi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
19 // Returns: 1 if number of bits is odd else returns 0
21 COMPILER_RT_ABI si_int
__paritydi2(di_int a
);
23 int naive_parity(di_int a
)
26 for (; a
; a
= a
& (a
- 1))
31 int test__paritydi2(di_int a
)
33 si_int x
= __paritydi2(a
);
34 si_int expected
= naive_parity(a
);
36 printf("error in __paritydi2(0x%llX) = %d, expected %d\n",
41 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
42 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
47 for (i
= 0; i
< 10000; ++i
)
48 if (test__paritydi2(((di_int
)rand() << 32) + rand()))