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