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