1*4684ddb6SLionel Sambuc //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __ffsti2 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #if __x86_64
15*4684ddb6SLionel Sambuc
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc
19*4684ddb6SLionel Sambuc // Returns: the index of the least significant 1-bit in a, or
20*4684ddb6SLionel Sambuc // the value zero if a is zero. The least significant bit is index one.
21*4684ddb6SLionel Sambuc
22*4684ddb6SLionel Sambuc si_int __ffsti2(ti_int a);
23*4684ddb6SLionel Sambuc
test__ffsti2(ti_int a,si_int expected)24*4684ddb6SLionel Sambuc int test__ffsti2(ti_int a, si_int expected)
25*4684ddb6SLionel Sambuc {
26*4684ddb6SLionel Sambuc si_int x = __ffsti2(a);
27*4684ddb6SLionel Sambuc if (x != expected)
28*4684ddb6SLionel Sambuc {
29*4684ddb6SLionel Sambuc twords at;
30*4684ddb6SLionel Sambuc at.all = a;
31*4684ddb6SLionel Sambuc printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
32*4684ddb6SLionel Sambuc at.s.high, at.s.low, x, expected);
33*4684ddb6SLionel Sambuc }
34*4684ddb6SLionel Sambuc return x != expected;
35*4684ddb6SLionel Sambuc }
36*4684ddb6SLionel Sambuc
37*4684ddb6SLionel Sambuc char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
38*4684ddb6SLionel Sambuc
39*4684ddb6SLionel Sambuc #endif
40*4684ddb6SLionel Sambuc
main()41*4684ddb6SLionel Sambuc int main()
42*4684ddb6SLionel Sambuc {
43*4684ddb6SLionel Sambuc #if __x86_64
44*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000000, 0))
45*4684ddb6SLionel Sambuc return 1;
46*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000001, 1))
47*4684ddb6SLionel Sambuc return 1;
48*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000002, 2))
49*4684ddb6SLionel Sambuc return 1;
50*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000003, 1))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000004, 3))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc if (test__ffsti2(0x00000005, 1))
55*4684ddb6SLionel Sambuc return 1;
56*4684ddb6SLionel Sambuc if (test__ffsti2(0x0000000A, 2))
57*4684ddb6SLionel Sambuc return 1;
58*4684ddb6SLionel Sambuc if (test__ffsti2(0x10000000, 29))
59*4684ddb6SLionel Sambuc return 1;
60*4684ddb6SLionel Sambuc if (test__ffsti2(0x20000000, 30))
61*4684ddb6SLionel Sambuc return 1;
62*4684ddb6SLionel Sambuc if (test__ffsti2(0x60000000, 30))
63*4684ddb6SLionel Sambuc return 1;
64*4684ddb6SLionel Sambuc if (test__ffsti2(0x80000000uLL, 32))
65*4684ddb6SLionel Sambuc return 1;
66*4684ddb6SLionel Sambuc if (test__ffsti2(0x0000050000000000uLL, 41))
67*4684ddb6SLionel Sambuc return 1;
68*4684ddb6SLionel Sambuc if (test__ffsti2(0x0200080000000000uLL, 44))
69*4684ddb6SLionel Sambuc return 1;
70*4684ddb6SLionel Sambuc if (test__ffsti2(0x7200000000000000uLL, 58))
71*4684ddb6SLionel Sambuc return 1;
72*4684ddb6SLionel Sambuc if (test__ffsti2(0x8000000000000000uLL, 64))
73*4684ddb6SLionel Sambuc return 1;
74*4684ddb6SLionel Sambuc if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
75*4684ddb6SLionel Sambuc return 1;
76*4684ddb6SLionel Sambuc if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
77*4684ddb6SLionel Sambuc return 1;
78*4684ddb6SLionel Sambuc
79*4684ddb6SLionel Sambuc #else
80*4684ddb6SLionel Sambuc printf("skipped\n");
81*4684ddb6SLionel Sambuc #endif
82*4684ddb6SLionel Sambuc return 0;
83*4684ddb6SLionel Sambuc }
84