xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/ctzti2_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __ctzti2 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot // Returns: the number of trailing 0-bits
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot // Precondition: a != 0
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot COMPILER_RT_ABI si_int __ctzti2(ti_int a);
24*7c3d14c8STreehugger Robot 
test__ctzti2(ti_int a,si_int expected)25*7c3d14c8STreehugger Robot int test__ctzti2(ti_int a, si_int expected)
26*7c3d14c8STreehugger Robot {
27*7c3d14c8STreehugger Robot     si_int x = __ctzti2(a);
28*7c3d14c8STreehugger Robot     if (x != expected)
29*7c3d14c8STreehugger Robot     {
30*7c3d14c8STreehugger Robot         twords at;
31*7c3d14c8STreehugger Robot         at.all = a;
32*7c3d14c8STreehugger Robot         printf("error in __ctzti2(0x%llX%.16llX) = %d, expected %d\n",
33*7c3d14c8STreehugger Robot                at.s.high, at.s.low, x, expected);
34*7c3d14c8STreehugger Robot     }
35*7c3d14c8STreehugger Robot     return x != expected;
36*7c3d14c8STreehugger Robot }
37*7c3d14c8STreehugger Robot 
38*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
39*7c3d14c8STreehugger Robot 
40*7c3d14c8STreehugger Robot #endif
41*7c3d14c8STreehugger Robot 
main()42*7c3d14c8STreehugger Robot int main()
43*7c3d14c8STreehugger Robot {
44*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
45*7c3d14c8STreehugger Robot     if (test__ctzti2(0x00000001, 0))
46*7c3d14c8STreehugger Robot         return 1;
47*7c3d14c8STreehugger Robot     if (test__ctzti2(0x00000002, 1))
48*7c3d14c8STreehugger Robot         return 1;
49*7c3d14c8STreehugger Robot     if (test__ctzti2(0x00000003, 0))
50*7c3d14c8STreehugger Robot         return 1;
51*7c3d14c8STreehugger Robot     if (test__ctzti2(0x00000004, 2))
52*7c3d14c8STreehugger Robot         return 1;
53*7c3d14c8STreehugger Robot     if (test__ctzti2(0x00000005, 0))
54*7c3d14c8STreehugger Robot         return 1;
55*7c3d14c8STreehugger Robot     if (test__ctzti2(0x0000000A, 1))
56*7c3d14c8STreehugger Robot         return 1;
57*7c3d14c8STreehugger Robot     if (test__ctzti2(0x10000000, 28))
58*7c3d14c8STreehugger Robot         return 1;
59*7c3d14c8STreehugger Robot     if (test__ctzti2(0x20000000, 29))
60*7c3d14c8STreehugger Robot         return 1;
61*7c3d14c8STreehugger Robot     if (test__ctzti2(0x60000000, 29))
62*7c3d14c8STreehugger Robot         return 1;
63*7c3d14c8STreehugger Robot     if (test__ctzti2(0x80000000uLL, 31))
64*7c3d14c8STreehugger Robot         return 1;
65*7c3d14c8STreehugger Robot     if (test__ctzti2(0x0000050000000000uLL, 40))
66*7c3d14c8STreehugger Robot         return 1;
67*7c3d14c8STreehugger Robot     if (test__ctzti2(0x0200080000000000uLL, 43))
68*7c3d14c8STreehugger Robot         return 1;
69*7c3d14c8STreehugger Robot     if (test__ctzti2(0x7200000000000000uLL, 57))
70*7c3d14c8STreehugger Robot         return 1;
71*7c3d14c8STreehugger Robot     if (test__ctzti2(0x8000000000000000uLL, 63))
72*7c3d14c8STreehugger Robot         return 1;
73*7c3d14c8STreehugger Robot     if (test__ctzti2(make_ti(0x00000000A0000000LL, 0x0000000000000000LL), 93))
74*7c3d14c8STreehugger Robot         return 1;
75*7c3d14c8STreehugger Robot     if (test__ctzti2(make_ti(0xF000000000000000LL, 0x0000000000000000LL), 124))
76*7c3d14c8STreehugger Robot         return 1;
77*7c3d14c8STreehugger Robot     if (test__ctzti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 127))
78*7c3d14c8STreehugger Robot         return 1;
79*7c3d14c8STreehugger Robot #else
80*7c3d14c8STreehugger Robot     printf("skipped\n");
81*7c3d14c8STreehugger Robot #endif
82*7c3d14c8STreehugger Robot 
83*7c3d14c8STreehugger Robot    return 0;
84*7c3d14c8STreehugger Robot }
85