1*b9829059Sjoerg //===-- clzti2_test.c - Test __clzti2 -------------------------------------===//
2*b9829059Sjoerg //
3*b9829059Sjoerg // The LLVM Compiler Infrastructure
4*b9829059Sjoerg //
5*b9829059Sjoerg // This file is dual licensed under the MIT and the University of Illinois Open
6*b9829059Sjoerg // Source Licenses. See LICENSE.TXT for details.
7*b9829059Sjoerg //
8*b9829059Sjoerg //===----------------------------------------------------------------------===//
9*b9829059Sjoerg //
10*b9829059Sjoerg // This file tests __clzti2 for the compiler_rt library.
11*b9829059Sjoerg //
12*b9829059Sjoerg //===----------------------------------------------------------------------===//
13*b9829059Sjoerg
14*b9829059Sjoerg #if __x86_64
15*b9829059Sjoerg
16*b9829059Sjoerg #include "int_lib.h"
17*b9829059Sjoerg #include <stdio.h>
18*b9829059Sjoerg
19*b9829059Sjoerg // Returns: the number of leading 0-bits
20*b9829059Sjoerg
21*b9829059Sjoerg // Precondition: a != 0
22*b9829059Sjoerg
23*b9829059Sjoerg si_int __clzti2(ti_int a);
24*b9829059Sjoerg
test__clzti2(ti_int a,si_int expected)25*b9829059Sjoerg int test__clzti2(ti_int a, si_int expected)
26*b9829059Sjoerg {
27*b9829059Sjoerg si_int x = __clzti2(a);
28*b9829059Sjoerg if (x != expected)
29*b9829059Sjoerg {
30*b9829059Sjoerg twords at;
31*b9829059Sjoerg at.all = a;
32*b9829059Sjoerg printf("error in __clzti2(0x%llX%.16llX) = %d, expected %d\n",
33*b9829059Sjoerg at.s.high, at.s.low, x, expected);
34*b9829059Sjoerg }
35*b9829059Sjoerg return x != expected;
36*b9829059Sjoerg }
37*b9829059Sjoerg
38*b9829059Sjoerg char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
39*b9829059Sjoerg
40*b9829059Sjoerg #endif
41*b9829059Sjoerg
main()42*b9829059Sjoerg int main()
43*b9829059Sjoerg {
44*b9829059Sjoerg #if __x86_64
45*b9829059Sjoerg const int N = (int)(sizeof(ti_int) * CHAR_BIT);
46*b9829059Sjoerg
47*b9829059Sjoerg if (test__clzti2(0x00000001, N-1))
48*b9829059Sjoerg return 1;
49*b9829059Sjoerg if (test__clzti2(0x00000002, N-2))
50*b9829059Sjoerg return 1;
51*b9829059Sjoerg if (test__clzti2(0x00000003, N-2))
52*b9829059Sjoerg return 1;
53*b9829059Sjoerg if (test__clzti2(0x00000004, N-3))
54*b9829059Sjoerg return 1;
55*b9829059Sjoerg if (test__clzti2(0x00000005, N-3))
56*b9829059Sjoerg return 1;
57*b9829059Sjoerg if (test__clzti2(0x0000000A, N-4))
58*b9829059Sjoerg return 1;
59*b9829059Sjoerg if (test__clzti2(0x1000000A, N*3/4+3))
60*b9829059Sjoerg return 1;
61*b9829059Sjoerg if (test__clzti2(0x2000000A, N*3/4+2))
62*b9829059Sjoerg return 1;
63*b9829059Sjoerg if (test__clzti2(0x6000000A, N*3/4+1))
64*b9829059Sjoerg return 1;
65*b9829059Sjoerg if (test__clzti2(0x8000000AuLL, N*3/4))
66*b9829059Sjoerg return 1;
67*b9829059Sjoerg if (test__clzti2(0x000005008000000AuLL, 85))
68*b9829059Sjoerg return 1;
69*b9829059Sjoerg if (test__clzti2(0x020005008000000AuLL, 70))
70*b9829059Sjoerg return 1;
71*b9829059Sjoerg if (test__clzti2(0x720005008000000AuLL, 65))
72*b9829059Sjoerg return 1;
73*b9829059Sjoerg if (test__clzti2(0x820005008000000AuLL, 64))
74*b9829059Sjoerg return 1;
75*b9829059Sjoerg
76*b9829059Sjoerg if (test__clzti2(make_ti(0x0000000080000000LL, 0x8000000800000000LL), 32))
77*b9829059Sjoerg return 1;
78*b9829059Sjoerg if (test__clzti2(make_ti(0x0000000100000000LL, 0x8000000800000000LL), 31))
79*b9829059Sjoerg return 1;
80*b9829059Sjoerg if (test__clzti2(make_ti(0x1000000100000000LL, 0x8000000800000000LL), 3))
81*b9829059Sjoerg return 1;
82*b9829059Sjoerg if (test__clzti2(make_ti(0x7000000100000000LL, 0x8000000800000000LL), 1))
83*b9829059Sjoerg return 1;
84*b9829059Sjoerg if (test__clzti2(make_ti(0x8000000100000000LL, 0x8000000800000000LL), 0))
85*b9829059Sjoerg return 1;
86*b9829059Sjoerg #else
87*b9829059Sjoerg printf("skipped\n");
88*b9829059Sjoerg #endif
89*b9829059Sjoerg return 0;
90*b9829059Sjoerg }
91