[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / popcountdi2_test.c
blob5bec9ce9d1520fee8d4193f72a6610394eadf8e7
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_popcountdi2
3 //===-- popcountdi2_test.c - Test __popcountdi2 ----------------------------===//
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 __popcountdi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
17 #include <stdlib.h>
19 // Returns: count of 1 bits
21 COMPILER_RT_ABI si_int __popcountdi2(di_int a);
23 int naive_popcount(di_int a)
25 int r = 0;
26 for (; a; a = (du_int)a >> 1)
27 r += a & 1;
28 return r;
31 int test__popcountdi2(di_int a)
33 si_int x = __popcountdi2(a);
34 si_int expected = naive_popcount(a);
35 if (x != expected)
36 printf("error in __popcountdi2(0x%llX) = %d, expected %d\n",
37 a, x, expected);
38 return x != expected;
41 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
42 char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0};
44 int main()
46 if (test__popcountdi2(0))
47 return 1;
48 if (test__popcountdi2(1))
49 return 1;
50 if (test__popcountdi2(2))
51 return 1;
52 if (test__popcountdi2(0xFFFFFFFFFFFFFFFDLL))
53 return 1;
54 if (test__popcountdi2(0xFFFFFFFFFFFFFFFELL))
55 return 1;
56 if (test__popcountdi2(0xFFFFFFFFFFFFFFFFLL))
57 return 1;
58 int i;
59 for (i = 0; i < 10000; ++i)
60 if (test__popcountdi2(((di_int)rand() << 32) | rand()))
61 return 1;
63 return 0;