xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/ctzdi2_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- ctzdi2_test.c - Test __ctzdi2 -------------------------------------===//
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 __ctzdi2 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc 
17*4684ddb6SLionel Sambuc // Returns: the number of trailing 0-bits
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc // Precondition: a != 0
20*4684ddb6SLionel Sambuc 
21*4684ddb6SLionel Sambuc si_int __ctzdi2(di_int a);
22*4684ddb6SLionel Sambuc 
test__ctzdi2(di_int a,si_int expected)23*4684ddb6SLionel Sambuc int test__ctzdi2(di_int a, si_int expected)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc     si_int x = __ctzdi2(a);
26*4684ddb6SLionel Sambuc     if (x != expected)
27*4684ddb6SLionel Sambuc         printf("error in __ctzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
28*4684ddb6SLionel Sambuc     return x != expected;
29*4684ddb6SLionel Sambuc }
30*4684ddb6SLionel Sambuc 
31*4684ddb6SLionel Sambuc char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
32*4684ddb6SLionel Sambuc 
main()33*4684ddb6SLionel Sambuc int main()
34*4684ddb6SLionel Sambuc {
35*4684ddb6SLionel Sambuc //    if (test__ctzdi2(0x00000000, N))  // undefined
36*4684ddb6SLionel Sambuc //        return 1;
37*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x00000001, 0))
38*4684ddb6SLionel Sambuc         return 1;
39*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x00000002, 1))
40*4684ddb6SLionel Sambuc         return 1;
41*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x00000003, 0))
42*4684ddb6SLionel Sambuc         return 1;
43*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x00000004, 2))
44*4684ddb6SLionel Sambuc         return 1;
45*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x00000005, 0))
46*4684ddb6SLionel Sambuc         return 1;
47*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x0000000A, 1))
48*4684ddb6SLionel Sambuc         return 1;
49*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x10000000, 28))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x20000000, 29))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x60000000, 29))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x80000000uLL, 31))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x0000050000000000uLL, 40))
58*4684ddb6SLionel Sambuc         return 1;
59*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x0200080000000000uLL, 43))
60*4684ddb6SLionel Sambuc         return 1;
61*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x7200000000000000uLL, 57))
62*4684ddb6SLionel Sambuc         return 1;
63*4684ddb6SLionel Sambuc     if (test__ctzdi2(0x8000000000000000uLL, 63))
64*4684ddb6SLionel Sambuc         return 1;
65*4684ddb6SLionel Sambuc 
66*4684ddb6SLionel Sambuc    return 0;
67*4684ddb6SLionel Sambuc }
68