[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / ffsti2_test.c
blob2f35c884a0a9b5274f8b2c43357a556bf33b5af4
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ffsti2
3 // REQUIRES: int128
4 //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
12 // This file tests __ffsti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
19 #ifdef CRT_HAS_128BIT
21 // Returns: the index of the least significant 1-bit in a, or
22 // the value zero if a is zero. The least significant bit is index one.
24 COMPILER_RT_ABI si_int __ffsti2(ti_int a);
26 int test__ffsti2(ti_int a, si_int expected)
28 si_int x = __ffsti2(a);
29 if (x != expected)
31 twords at;
32 at.all = a;
33 printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
34 at.s.high, at.s.low, x, expected);
36 return x != expected;
39 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
41 #endif
43 int main()
45 #ifdef CRT_HAS_128BIT
46 if (test__ffsti2(0x00000000, 0))
47 return 1;
48 if (test__ffsti2(0x00000001, 1))
49 return 1;
50 if (test__ffsti2(0x00000002, 2))
51 return 1;
52 if (test__ffsti2(0x00000003, 1))
53 return 1;
54 if (test__ffsti2(0x00000004, 3))
55 return 1;
56 if (test__ffsti2(0x00000005, 1))
57 return 1;
58 if (test__ffsti2(0x0000000A, 2))
59 return 1;
60 if (test__ffsti2(0x10000000, 29))
61 return 1;
62 if (test__ffsti2(0x20000000, 30))
63 return 1;
64 if (test__ffsti2(0x60000000, 30))
65 return 1;
66 if (test__ffsti2(0x80000000uLL, 32))
67 return 1;
68 if (test__ffsti2(0x0000050000000000uLL, 41))
69 return 1;
70 if (test__ffsti2(0x0200080000000000uLL, 44))
71 return 1;
72 if (test__ffsti2(0x7200000000000000uLL, 58))
73 return 1;
74 if (test__ffsti2(0x8000000000000000uLL, 64))
75 return 1;
76 if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
77 return 1;
78 if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
79 return 1;
81 #else
82 printf("skipped\n");
83 #endif
84 return 0;