1b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//===-- clzdi2_test.c - Test __clzdi2 -------------------------------------===//
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 __clzdi2 for the compiler_rt library.
11b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//
12b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//===----------------------------------------------------------------------===//
13b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
14b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar#include "int_lib.h"
15b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar#include <stdio.h>
16b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
17b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar// Returns: the number of leading 0-bits
18b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
19b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar// Precondition: a != 0
20b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
21b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbarsi_int __clzdi2(di_int a);
22b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
23b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbarint test__clzdi2(di_int a, si_int expected)
24b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar{
25b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    si_int x = __clzdi2(a);
26b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (x != expected)
27b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        printf("error in __clzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
28b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    return x != expected;
29b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar}
30b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
31b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbarchar assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
32b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
33b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbarint main()
34b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar{
35b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    const int N = (int)(sizeof(di_int) * CHAR_BIT);
36b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//    if (test__clzdi2(0x00000000, N))  // undefined
37b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//        return 1;
38b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x00000001, N-1))
39b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
40b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x00000002, N-2))
41b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
42b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x00000003, N-2))
43b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
44b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x00000004, N-3))
45b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
46b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x00000005, N-3))
47b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
48b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x0000000A, N-4))
49b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
50b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x1000000A, N/2+3))
51b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
52b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x2000000A, N/2+2))
53b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
54b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x6000000A, N/2+1))
55b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
56b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x8000000AuLL, N/2))
57b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
58b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x000005008000000AuLL, 21))
59b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
60b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x020005008000000AuLL, 6))
61b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
62b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x720005008000000AuLL, 1))
63b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
64b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__clzdi2(0x820005008000000AuLL, 0))
65b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
66b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
67b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar   return 0;
68b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar}
69