1*7c3d14c8STreehugger Robot //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
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 __ffsti2 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 #ifdef CRT_HAS_128BIT
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robot // Returns: the index of the least significant 1-bit in a, or
20*7c3d14c8STreehugger Robot // the value zero if a is zero. The least significant bit is index one.
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger Robot COMPILER_RT_ABI si_int __ffsti2(ti_int a);
23*7c3d14c8STreehugger Robot
test__ffsti2(ti_int a,si_int expected)24*7c3d14c8STreehugger Robot int test__ffsti2(ti_int a, si_int expected)
25*7c3d14c8STreehugger Robot {
26*7c3d14c8STreehugger Robot si_int x = __ffsti2(a);
27*7c3d14c8STreehugger Robot if (x != expected)
28*7c3d14c8STreehugger Robot {
29*7c3d14c8STreehugger Robot twords at;
30*7c3d14c8STreehugger Robot at.all = a;
31*7c3d14c8STreehugger Robot printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
32*7c3d14c8STreehugger Robot at.s.high, at.s.low, x, expected);
33*7c3d14c8STreehugger Robot }
34*7c3d14c8STreehugger Robot return x != expected;
35*7c3d14c8STreehugger Robot }
36*7c3d14c8STreehugger Robot
37*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
38*7c3d14c8STreehugger Robot
39*7c3d14c8STreehugger Robot #endif
40*7c3d14c8STreehugger Robot
main()41*7c3d14c8STreehugger Robot int main()
42*7c3d14c8STreehugger Robot {
43*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
44*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000000, 0))
45*7c3d14c8STreehugger Robot return 1;
46*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000001, 1))
47*7c3d14c8STreehugger Robot return 1;
48*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000002, 2))
49*7c3d14c8STreehugger Robot return 1;
50*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000003, 1))
51*7c3d14c8STreehugger Robot return 1;
52*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000004, 3))
53*7c3d14c8STreehugger Robot return 1;
54*7c3d14c8STreehugger Robot if (test__ffsti2(0x00000005, 1))
55*7c3d14c8STreehugger Robot return 1;
56*7c3d14c8STreehugger Robot if (test__ffsti2(0x0000000A, 2))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot if (test__ffsti2(0x10000000, 29))
59*7c3d14c8STreehugger Robot return 1;
60*7c3d14c8STreehugger Robot if (test__ffsti2(0x20000000, 30))
61*7c3d14c8STreehugger Robot return 1;
62*7c3d14c8STreehugger Robot if (test__ffsti2(0x60000000, 30))
63*7c3d14c8STreehugger Robot return 1;
64*7c3d14c8STreehugger Robot if (test__ffsti2(0x80000000uLL, 32))
65*7c3d14c8STreehugger Robot return 1;
66*7c3d14c8STreehugger Robot if (test__ffsti2(0x0000050000000000uLL, 41))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot if (test__ffsti2(0x0200080000000000uLL, 44))
69*7c3d14c8STreehugger Robot return 1;
70*7c3d14c8STreehugger Robot if (test__ffsti2(0x7200000000000000uLL, 58))
71*7c3d14c8STreehugger Robot return 1;
72*7c3d14c8STreehugger Robot if (test__ffsti2(0x8000000000000000uLL, 64))
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
75*7c3d14c8STreehugger Robot return 1;
76*7c3d14c8STreehugger Robot if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
77*7c3d14c8STreehugger Robot return 1;
78*7c3d14c8STreehugger Robot
79*7c3d14c8STreehugger Robot #else
80*7c3d14c8STreehugger Robot printf("skipped\n");
81*7c3d14c8STreehugger Robot #endif
82*7c3d14c8STreehugger Robot return 0;
83*7c3d14c8STreehugger Robot }
84