[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / paritysi2_test.c
blobb59335ddce82616084579e54a2af77bf5e0e380c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_paritysi2
3 //===-- paritysi2_test.c - Test __paritysi2 -------------------------------===//
4 //
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
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __paritysi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
17 #include <stdlib.h>
19 // Returns: 1 if number of bits is odd else returns 0
21 COMPILER_RT_ABI si_int __paritysi2(si_int a);
23 int naive_parity(si_int a)
25 int r = 0;
26 for (; a; a = a & (a - 1))
27 r = ~r;
28 return r & 1;
31 int test__paritysi2(si_int a)
33 si_int x = __paritysi2(a);
34 si_int expected = naive_parity(a);
35 if (x != expected)
36 printf("error in __paritysi2(0x%X) = %d, expected %d\n",
37 a, x, expected);
38 return x != expected;
41 char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0};
43 int main()
45 int i;
46 for (i = 0; i < 10000; ++i)
47 if (test__paritysi2(rand()))
48 return 1;
50 return 0;