1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ffsdi2
3 
4 #include "int_lib.h"
5 #include <stdio.h>
6 
7 // Returns: the index of the least significant 1-bit in a, or
8 // the value zero if a is zero. The least significant bit is index one.
9 
10 COMPILER_RT_ABI int __ffsdi2(di_int a);
11 
test__ffsdi2(di_int a,int expected)12 int test__ffsdi2(di_int a, int expected)
13 {
14     int x = __ffsdi2(a);
15     if (x != expected)
16         printf("error in __ffsdi2(0x%llX) = %d, expected %d\n", a, x, expected);
17     return x != expected;
18 }
19 
20 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
21 
main()22 int main()
23 {
24     if (test__ffsdi2(0x00000000, 0))
25         return 1;
26     if (test__ffsdi2(0x00000001, 1))
27         return 1;
28     if (test__ffsdi2(0x00000002, 2))
29         return 1;
30     if (test__ffsdi2(0x00000003, 1))
31         return 1;
32     if (test__ffsdi2(0x00000004, 3))
33         return 1;
34     if (test__ffsdi2(0x00000005, 1))
35         return 1;
36     if (test__ffsdi2(0x0000000A, 2))
37         return 1;
38     if (test__ffsdi2(0x10000000, 29))
39         return 1;
40     if (test__ffsdi2(0x20000000, 30))
41         return 1;
42     if (test__ffsdi2(0x60000000, 30))
43         return 1;
44     if (test__ffsdi2(0x80000000uLL, 32))
45         return 1;
46     if (test__ffsdi2(0x0000050000000000uLL, 41))
47         return 1;
48     if (test__ffsdi2(0x0200080000000000uLL, 44))
49         return 1;
50     if (test__ffsdi2(0x7200000000000000uLL, 58))
51         return 1;
52     if (test__ffsdi2(0x8000000000000000uLL, 64))
53         return 1;
54 
55    return 0;
56 }
57