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
11COMPILER_RT_ABI int __ctzdi2(di_int a);
12
13int test__ctzdi2(di_int a, int expected)
14{
15 int x = __ctzdi2(a);
16 if (x != expected)
17 printf(format: "error in __ctzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
18 return x != expected;
19}
20
21char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
22
23int main()
24{
25// if (test__ctzdi2(0x00000000, N)) // undefined
26// return 1;
27 if (test__ctzdi2(a: 0x00000001, expected: 0))
28 return 1;
29 if (test__ctzdi2(a: 0x00000002, expected: 1))
30 return 1;
31 if (test__ctzdi2(a: 0x00000003, expected: 0))
32 return 1;
33 if (test__ctzdi2(a: 0x00000004, expected: 2))
34 return 1;
35 if (test__ctzdi2(a: 0x00000005, expected: 0))
36 return 1;
37 if (test__ctzdi2(a: 0x0000000A, expected: 1))
38 return 1;
39 if (test__ctzdi2(a: 0x10000000, expected: 28))
40 return 1;
41 if (test__ctzdi2(a: 0x20000000, expected: 29))
42 return 1;
43 if (test__ctzdi2(a: 0x60000000, expected: 29))
44 return 1;
45 if (test__ctzdi2(a: 0x80000000uLL, expected: 31))
46 return 1;
47 if (test__ctzdi2(a: 0x0000050000000000uLL, expected: 40))
48 return 1;
49 if (test__ctzdi2(a: 0x0200080000000000uLL, expected: 43))
50 return 1;
51 if (test__ctzdi2(a: 0x7200000000000000uLL, expected: 57))
52 return 1;
53 if (test__ctzdi2(a: 0x8000000000000000uLL, expected: 63))
54 return 1;
55
56 return 0;
57}
58

source code of compiler-rt/test/builtins/Unit/ctzdi2_test.c