1*4684ddb6SLionel Sambuc //===-- clzti2_test.c - Test __clzti2 -------------------------------------===//
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 __clzti2 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 number of leading 0-bits
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc // Precondition: a != 0
22*4684ddb6SLionel Sambuc
23*4684ddb6SLionel Sambuc si_int __clzti2(ti_int a);
24*4684ddb6SLionel Sambuc
test__clzti2(ti_int a,si_int expected)25*4684ddb6SLionel Sambuc int test__clzti2(ti_int a, si_int expected)
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc si_int x = __clzti2(a);
28*4684ddb6SLionel Sambuc if (x != expected)
29*4684ddb6SLionel Sambuc {
30*4684ddb6SLionel Sambuc twords at;
31*4684ddb6SLionel Sambuc at.all = a;
32*4684ddb6SLionel Sambuc printf("error in __clzti2(0x%llX%.16llX) = %d, expected %d\n",
33*4684ddb6SLionel Sambuc at.s.high, at.s.low, x, expected);
34*4684ddb6SLionel Sambuc }
35*4684ddb6SLionel Sambuc return x != expected;
36*4684ddb6SLionel Sambuc }
37*4684ddb6SLionel Sambuc
38*4684ddb6SLionel Sambuc char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
39*4684ddb6SLionel Sambuc
40*4684ddb6SLionel Sambuc #endif
41*4684ddb6SLionel Sambuc
main()42*4684ddb6SLionel Sambuc int main()
43*4684ddb6SLionel Sambuc {
44*4684ddb6SLionel Sambuc #if __x86_64
45*4684ddb6SLionel Sambuc const int N = (int)(sizeof(ti_int) * CHAR_BIT);
46*4684ddb6SLionel Sambuc
47*4684ddb6SLionel Sambuc if (test__clzti2(0x00000001, N-1))
48*4684ddb6SLionel Sambuc return 1;
49*4684ddb6SLionel Sambuc if (test__clzti2(0x00000002, N-2))
50*4684ddb6SLionel Sambuc return 1;
51*4684ddb6SLionel Sambuc if (test__clzti2(0x00000003, N-2))
52*4684ddb6SLionel Sambuc return 1;
53*4684ddb6SLionel Sambuc if (test__clzti2(0x00000004, N-3))
54*4684ddb6SLionel Sambuc return 1;
55*4684ddb6SLionel Sambuc if (test__clzti2(0x00000005, N-3))
56*4684ddb6SLionel Sambuc return 1;
57*4684ddb6SLionel Sambuc if (test__clzti2(0x0000000A, N-4))
58*4684ddb6SLionel Sambuc return 1;
59*4684ddb6SLionel Sambuc if (test__clzti2(0x1000000A, N*3/4+3))
60*4684ddb6SLionel Sambuc return 1;
61*4684ddb6SLionel Sambuc if (test__clzti2(0x2000000A, N*3/4+2))
62*4684ddb6SLionel Sambuc return 1;
63*4684ddb6SLionel Sambuc if (test__clzti2(0x6000000A, N*3/4+1))
64*4684ddb6SLionel Sambuc return 1;
65*4684ddb6SLionel Sambuc if (test__clzti2(0x8000000AuLL, N*3/4))
66*4684ddb6SLionel Sambuc return 1;
67*4684ddb6SLionel Sambuc if (test__clzti2(0x000005008000000AuLL, 85))
68*4684ddb6SLionel Sambuc return 1;
69*4684ddb6SLionel Sambuc if (test__clzti2(0x020005008000000AuLL, 70))
70*4684ddb6SLionel Sambuc return 1;
71*4684ddb6SLionel Sambuc if (test__clzti2(0x720005008000000AuLL, 65))
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc if (test__clzti2(0x820005008000000AuLL, 64))
74*4684ddb6SLionel Sambuc return 1;
75*4684ddb6SLionel Sambuc
76*4684ddb6SLionel Sambuc if (test__clzti2(make_ti(0x0000000080000000LL, 0x8000000800000000LL), 32))
77*4684ddb6SLionel Sambuc return 1;
78*4684ddb6SLionel Sambuc if (test__clzti2(make_ti(0x0000000100000000LL, 0x8000000800000000LL), 31))
79*4684ddb6SLionel Sambuc return 1;
80*4684ddb6SLionel Sambuc if (test__clzti2(make_ti(0x1000000100000000LL, 0x8000000800000000LL), 3))
81*4684ddb6SLionel Sambuc return 1;
82*4684ddb6SLionel Sambuc if (test__clzti2(make_ti(0x7000000100000000LL, 0x8000000800000000LL), 1))
83*4684ddb6SLionel Sambuc return 1;
84*4684ddb6SLionel Sambuc if (test__clzti2(make_ti(0x8000000100000000LL, 0x8000000800000000LL), 0))
85*4684ddb6SLionel Sambuc return 1;
86*4684ddb6SLionel Sambuc #else
87*4684ddb6SLionel Sambuc printf("skipped\n");
88*4684ddb6SLionel Sambuc #endif
89*4684ddb6SLionel Sambuc return 0;
90*4684ddb6SLionel Sambuc }
91