xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/lshrti3_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- lshrti3_test.c - Test __lshrti3 -----------------------------------===//
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 __lshrti3 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: logical a >> b
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot // Precondition:  0 <= b < bits_in_dword
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __lshrti3(ti_int a, si_int b);
24*7c3d14c8STreehugger Robot 
test__lshrti3(ti_int a,si_int b,ti_int expected)25*7c3d14c8STreehugger Robot int test__lshrti3(ti_int a, si_int b, ti_int expected)
26*7c3d14c8STreehugger Robot {
27*7c3d14c8STreehugger Robot     ti_int x = __lshrti3(a, b);
28*7c3d14c8STreehugger Robot     if (x != expected)
29*7c3d14c8STreehugger Robot     {
30*7c3d14c8STreehugger Robot         twords at;
31*7c3d14c8STreehugger Robot         at.all = a;
32*7c3d14c8STreehugger Robot         twords xt;
33*7c3d14c8STreehugger Robot         xt.all = x;
34*7c3d14c8STreehugger Robot         twords expectedt;
35*7c3d14c8STreehugger Robot         expectedt.all = expected;
36*7c3d14c8STreehugger Robot         printf("error in __lshrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
37*7c3d14c8STreehugger Robot                " expected 0x%llX%.16llX\n",
38*7c3d14c8STreehugger Robot                 at.s.high, at.s.low, b, xt.s.high, xt.s.low,
39*7c3d14c8STreehugger Robot                 expectedt.s.high, expectedt.s.low);
40*7c3d14c8STreehugger Robot     }
41*7c3d14c8STreehugger Robot     return x != expected;
42*7c3d14c8STreehugger Robot }
43*7c3d14c8STreehugger Robot 
44*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
45*7c3d14c8STreehugger Robot 
46*7c3d14c8STreehugger Robot #endif
47*7c3d14c8STreehugger Robot 
main()48*7c3d14c8STreehugger Robot int main()
49*7c3d14c8STreehugger Robot {
50*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
51*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 0,
52*7c3d14c8STreehugger Robot                       make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL)))
53*7c3d14c8STreehugger Robot         return 1;
54*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 1,
55*7c3d14c8STreehugger Robot                       make_ti(0x7F6E5D4C3B2A190ALL, 0xFF6E5D4C3B2A190ALL)))
56*7c3d14c8STreehugger Robot         return 1;
57*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 2,
58*7c3d14c8STreehugger Robot                       make_ti(0x3FB72EA61D950C85LL, 0x7FB72EA61D950C85LL)))
59*7c3d14c8STreehugger Robot         return 1;
60*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 3,
61*7c3d14c8STreehugger Robot                       make_ti(0x1FDB97530ECA8642LL, 0xBFDB97530ECA8642LL)))
62*7c3d14c8STreehugger Robot         return 1;
63*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 4,
64*7c3d14c8STreehugger Robot                       make_ti(0x0FEDCBA987654321LL, 0x5FEDCBA987654321LL)))
65*7c3d14c8STreehugger Robot         return 1;
66*7c3d14c8STreehugger Robot 
67*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 28,
68*7c3d14c8STreehugger Robot                       make_ti(0x0000000FEDCBA987LL, 0x6543215FEDCBA987LL)))
69*7c3d14c8STreehugger Robot         return 1;
70*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 29,
71*7c3d14c8STreehugger Robot                       make_ti(0x00000007F6E5D4C3LL, 0xB2A190AFF6E5D4C3LL)))
72*7c3d14c8STreehugger Robot         return 1;
73*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 30,
74*7c3d14c8STreehugger Robot                       make_ti(0x00000003FB72EA61LL, 0xD950C857FB72EA61LL)))
75*7c3d14c8STreehugger Robot         return 1;
76*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 31,
77*7c3d14c8STreehugger Robot                       make_ti(0x00000001FDB97530LL, 0xECA8642BFDB97530LL)))
78*7c3d14c8STreehugger Robot         return 1;
79*7c3d14c8STreehugger Robot 
80*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 32,
81*7c3d14c8STreehugger Robot                       make_ti(0x00000000FEDCBA98LL, 0x76543215FEDCBA98LL)))
82*7c3d14c8STreehugger Robot         return 1;
83*7c3d14c8STreehugger Robot 
84*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 33,
85*7c3d14c8STreehugger Robot                       make_ti(0x000000007F6E5D4CLL, 0x3B2A190AFF6E5D4CLL)))
86*7c3d14c8STreehugger Robot         return 1;
87*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 34,
88*7c3d14c8STreehugger Robot                       make_ti(0x000000003FB72EA6LL, 0x1D950C857FB72EA6LL)))
89*7c3d14c8STreehugger Robot         return 1;
90*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 35,
91*7c3d14c8STreehugger Robot                       make_ti(0x000000001FDB9753LL, 0x0ECA8642BFDB9753LL)))
92*7c3d14c8STreehugger Robot         return 1;
93*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 36,
94*7c3d14c8STreehugger Robot                       make_ti(0x000000000FEDCBA9LL, 0x876543215FEDCBA9LL)))
95*7c3d14c8STreehugger Robot         return 1;
96*7c3d14c8STreehugger Robot 
97*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 60,
98*7c3d14c8STreehugger Robot                       make_ti(0x000000000000000FLL, 0xEDCBA9876543215FLL)))
99*7c3d14c8STreehugger Robot         return 1;
100*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 61,
101*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000007LL, 0xF6E5D4C3B2A190AFLL)))
102*7c3d14c8STreehugger Robot         return 1;
103*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 62,
104*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000003LL, 0xFB72EA61D950C857LL)))
105*7c3d14c8STreehugger Robot         return 1;
106*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 63,
107*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000001LL, 0xFDB97530ECA8642BLL)))
108*7c3d14c8STreehugger Robot         return 1;
109*7c3d14c8STreehugger Robot 
110*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 64,
111*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0xFEDCBA9876543215LL)))
112*7c3d14c8STreehugger Robot         return 1;
113*7c3d14c8STreehugger Robot 
114*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 65,
115*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x7F6E5D4C3B2A190ALL)))
116*7c3d14c8STreehugger Robot         return 1;
117*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 66,
118*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x3FB72EA61D950C85LL)))
119*7c3d14c8STreehugger Robot         return 1;
120*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 67,
121*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x1FDB97530ECA8642LL)))
122*7c3d14c8STreehugger Robot         return 1;
123*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 68,
124*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0FEDCBA987654321LL)))
125*7c3d14c8STreehugger Robot         return 1;
126*7c3d14c8STreehugger Robot 
127*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 92,
128*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000FEDCBA987LL)))
129*7c3d14c8STreehugger Robot         return 1;
130*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 93,
131*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x00000007F6E5D4C3LL)))
132*7c3d14c8STreehugger Robot         return 1;
133*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 94,
134*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x00000003FB72EA61LL)))
135*7c3d14c8STreehugger Robot         return 1;
136*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 95,
137*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x00000001FDB97530LL)))
138*7c3d14c8STreehugger Robot         return 1;
139*7c3d14c8STreehugger Robot 
140*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 96,
141*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x00000000FEDCBA98LL)))
142*7c3d14c8STreehugger Robot         return 1;
143*7c3d14c8STreehugger Robot 
144*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 97,
145*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x000000007F6E5D4CLL)))
146*7c3d14c8STreehugger Robot         return 1;
147*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 98,
148*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x000000003FB72EA6LL)))
149*7c3d14c8STreehugger Robot         return 1;
150*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 99,
151*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x000000001FDB9753LL)))
152*7c3d14c8STreehugger Robot         return 1;
153*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 100,
154*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x000000000FEDCBA9LL)))
155*7c3d14c8STreehugger Robot         return 1;
156*7c3d14c8STreehugger Robot 
157*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 124,
158*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x000000000000000FLL)))
159*7c3d14c8STreehugger Robot         return 1;
160*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 125,
161*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000007LL)))
162*7c3d14c8STreehugger Robot         return 1;
163*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 126,
164*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000003LL)))
165*7c3d14c8STreehugger Robot         return 1;
166*7c3d14c8STreehugger Robot     if (test__lshrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 127,
167*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000001LL)))
168*7c3d14c8STreehugger Robot         return 1;
169*7c3d14c8STreehugger Robot #else
170*7c3d14c8STreehugger Robot     printf("skipped\n");
171*7c3d14c8STreehugger Robot #endif
172*7c3d14c8STreehugger Robot     return 0;
173*7c3d14c8STreehugger Robot }
174