1*7c3d14c8STreehugger Robot //===-- ctzdi2_test.c - Test __ctzdi2 -------------------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __ctzdi2 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot
17*7c3d14c8STreehugger Robot // Returns: the number of trailing 0-bits
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robot // Precondition: a != 0
20*7c3d14c8STreehugger Robot
21*7c3d14c8STreehugger Robot COMPILER_RT_ABI si_int __ctzdi2(di_int a);
22*7c3d14c8STreehugger Robot
test__ctzdi2(di_int a,si_int expected)23*7c3d14c8STreehugger Robot int test__ctzdi2(di_int a, si_int expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot si_int x = __ctzdi2(a);
26*7c3d14c8STreehugger Robot if (x != expected)
27*7c3d14c8STreehugger Robot printf("error in __ctzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
28*7c3d14c8STreehugger Robot return x != expected;
29*7c3d14c8STreehugger Robot }
30*7c3d14c8STreehugger Robot
31*7c3d14c8STreehugger Robot char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
32*7c3d14c8STreehugger Robot
main()33*7c3d14c8STreehugger Robot int main()
34*7c3d14c8STreehugger Robot {
35*7c3d14c8STreehugger Robot // if (test__ctzdi2(0x00000000, N)) // undefined
36*7c3d14c8STreehugger Robot // return 1;
37*7c3d14c8STreehugger Robot if (test__ctzdi2(0x00000001, 0))
38*7c3d14c8STreehugger Robot return 1;
39*7c3d14c8STreehugger Robot if (test__ctzdi2(0x00000002, 1))
40*7c3d14c8STreehugger Robot return 1;
41*7c3d14c8STreehugger Robot if (test__ctzdi2(0x00000003, 0))
42*7c3d14c8STreehugger Robot return 1;
43*7c3d14c8STreehugger Robot if (test__ctzdi2(0x00000004, 2))
44*7c3d14c8STreehugger Robot return 1;
45*7c3d14c8STreehugger Robot if (test__ctzdi2(0x00000005, 0))
46*7c3d14c8STreehugger Robot return 1;
47*7c3d14c8STreehugger Robot if (test__ctzdi2(0x0000000A, 1))
48*7c3d14c8STreehugger Robot return 1;
49*7c3d14c8STreehugger Robot if (test__ctzdi2(0x10000000, 28))
50*7c3d14c8STreehugger Robot return 1;
51*7c3d14c8STreehugger Robot if (test__ctzdi2(0x20000000, 29))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot if (test__ctzdi2(0x60000000, 29))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot if (test__ctzdi2(0x80000000uLL, 31))
56*7c3d14c8STreehugger Robot return 1;
57*7c3d14c8STreehugger Robot if (test__ctzdi2(0x0000050000000000uLL, 40))
58*7c3d14c8STreehugger Robot return 1;
59*7c3d14c8STreehugger Robot if (test__ctzdi2(0x0200080000000000uLL, 43))
60*7c3d14c8STreehugger Robot return 1;
61*7c3d14c8STreehugger Robot if (test__ctzdi2(0x7200000000000000uLL, 57))
62*7c3d14c8STreehugger Robot return 1;
63*7c3d14c8STreehugger Robot if (test__ctzdi2(0x8000000000000000uLL, 63))
64*7c3d14c8STreehugger Robot return 1;
65*7c3d14c8STreehugger Robot
66*7c3d14c8STreehugger Robot return 0;
67*7c3d14c8STreehugger Robot }
68