1b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//===-- ctzdi2_test.c - Test __ctzdi2 -------------------------------------===//
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 __ctzdi2 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 trailing 0-bits
18b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
19b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar// Precondition: a != 0
20b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
21cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga NainarCOMPILER_RT_ABI si_int __ctzdi2(di_int a);
22b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
23b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbarint test__ctzdi2(di_int a, si_int expected)
24b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar{
25b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    si_int x = __ctzdi2(a);
26b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (x != expected)
27b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        printf("error in __ctzdi2(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//    if (test__ctzdi2(0x00000000, N))  // undefined
36b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar//        return 1;
37b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x00000001, 0))
38b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
39b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x00000002, 1))
40b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
41b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x00000003, 0))
42b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
43b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x00000004, 2))
44b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
45b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x00000005, 0))
46b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
47b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x0000000A, 1))
48b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
49b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x10000000, 28))
50b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
51b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x20000000, 29))
52b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
53b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x60000000, 29))
54b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
55b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x80000000uLL, 31))
56b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
57b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x0000050000000000uLL, 40))
58b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
59b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x0200080000000000uLL, 43))
60b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
61b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x7200000000000000uLL, 57))
62b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
63b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (test__ctzdi2(0x8000000000000000uLL, 63))
64b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar        return 1;
65b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
66b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar   return 0;
67b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar}
68