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