1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ffsti2
3 // REQUIRES: int128
4
5 #include "int_lib.h"
6 #include <stdio.h>
7
8 #ifdef CRT_HAS_128BIT
9
10 // Returns: the index of the least significant 1-bit in a, or
11 // the value zero if a is zero. The least significant bit is index one.
12
13 COMPILER_RT_ABI int __ffsti2(ti_int a);
14
test__ffsti2(ti_int a,int expected)15 int test__ffsti2(ti_int a, int expected)
16 {
17 int x = __ffsti2(a);
18 if (x != expected)
19 {
20 twords at;
21 at.all = a;
22 printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
23 at.s.high, at.s.low, x, expected);
24 }
25 return x != expected;
26 }
27
28 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
29
30 #endif
31
main()32 int main()
33 {
34 #ifdef CRT_HAS_128BIT
35 if (test__ffsti2(0x00000000, 0))
36 return 1;
37 if (test__ffsti2(0x00000001, 1))
38 return 1;
39 if (test__ffsti2(0x00000002, 2))
40 return 1;
41 if (test__ffsti2(0x00000003, 1))
42 return 1;
43 if (test__ffsti2(0x00000004, 3))
44 return 1;
45 if (test__ffsti2(0x00000005, 1))
46 return 1;
47 if (test__ffsti2(0x0000000A, 2))
48 return 1;
49 if (test__ffsti2(0x10000000, 29))
50 return 1;
51 if (test__ffsti2(0x20000000, 30))
52 return 1;
53 if (test__ffsti2(0x60000000, 30))
54 return 1;
55 if (test__ffsti2(0x80000000uLL, 32))
56 return 1;
57 if (test__ffsti2(0x0000050000000000uLL, 41))
58 return 1;
59 if (test__ffsti2(0x0200080000000000uLL, 44))
60 return 1;
61 if (test__ffsti2(0x7200000000000000uLL, 58))
62 return 1;
63 if (test__ffsti2(0x8000000000000000uLL, 64))
64 return 1;
65 if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
66 return 1;
67 if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
68 return 1;
69
70 #else
71 printf("skipped\n");
72 #endif
73 return 0;
74 }
75