xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/ctzti2_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===//
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 __ctzti2 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 trailing 0-bits
20*4684ddb6SLionel Sambuc 
21*4684ddb6SLionel Sambuc // Precondition: a != 0
22*4684ddb6SLionel Sambuc 
23*4684ddb6SLionel Sambuc si_int __ctzti2(ti_int a);
24*4684ddb6SLionel Sambuc 
test__ctzti2(ti_int a,si_int expected)25*4684ddb6SLionel Sambuc int test__ctzti2(ti_int a, si_int expected)
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc     si_int x = __ctzti2(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 __ctzti2(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     if (test__ctzti2(0x00000001, 0))
46*4684ddb6SLionel Sambuc         return 1;
47*4684ddb6SLionel Sambuc     if (test__ctzti2(0x00000002, 1))
48*4684ddb6SLionel Sambuc         return 1;
49*4684ddb6SLionel Sambuc     if (test__ctzti2(0x00000003, 0))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__ctzti2(0x00000004, 2))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__ctzti2(0x00000005, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__ctzti2(0x0000000A, 1))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc     if (test__ctzti2(0x10000000, 28))
58*4684ddb6SLionel Sambuc         return 1;
59*4684ddb6SLionel Sambuc     if (test__ctzti2(0x20000000, 29))
60*4684ddb6SLionel Sambuc         return 1;
61*4684ddb6SLionel Sambuc     if (test__ctzti2(0x60000000, 29))
62*4684ddb6SLionel Sambuc         return 1;
63*4684ddb6SLionel Sambuc     if (test__ctzti2(0x80000000uLL, 31))
64*4684ddb6SLionel Sambuc         return 1;
65*4684ddb6SLionel Sambuc     if (test__ctzti2(0x0000050000000000uLL, 40))
66*4684ddb6SLionel Sambuc         return 1;
67*4684ddb6SLionel Sambuc     if (test__ctzti2(0x0200080000000000uLL, 43))
68*4684ddb6SLionel Sambuc         return 1;
69*4684ddb6SLionel Sambuc     if (test__ctzti2(0x7200000000000000uLL, 57))
70*4684ddb6SLionel Sambuc         return 1;
71*4684ddb6SLionel Sambuc     if (test__ctzti2(0x8000000000000000uLL, 63))
72*4684ddb6SLionel Sambuc         return 1;
73*4684ddb6SLionel Sambuc     if (test__ctzti2(make_ti(0x00000000A0000000LL, 0x0000000000000000LL), 93))
74*4684ddb6SLionel Sambuc         return 1;
75*4684ddb6SLionel Sambuc     if (test__ctzti2(make_ti(0xF000000000000000LL, 0x0000000000000000LL), 124))
76*4684ddb6SLionel Sambuc         return 1;
77*4684ddb6SLionel Sambuc     if (test__ctzti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 127))
78*4684ddb6SLionel Sambuc         return 1;
79*4684ddb6SLionel Sambuc #else
80*4684ddb6SLionel Sambuc     printf("skipped\n");
81*4684ddb6SLionel Sambuc #endif
82*4684ddb6SLionel Sambuc 
83*4684ddb6SLionel Sambuc    return 0;
84*4684ddb6SLionel Sambuc }
85