1*4684ddb6SLionel Sambuc //===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
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 __muloti3 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: a * b
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc // Effects: sets overflow if a * b overflows
22*4684ddb6SLionel Sambuc
23*4684ddb6SLionel Sambuc ti_int __muloti4(ti_int a, ti_int b, int *overflow);
24*4684ddb6SLionel Sambuc
test__muloti4(ti_int a,ti_int b,ti_int expected,int expected_overflow)25*4684ddb6SLionel Sambuc int test__muloti4(ti_int a, ti_int b, ti_int expected, int expected_overflow)
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc int ov;
28*4684ddb6SLionel Sambuc ti_int x = __muloti4(a, b, &ov);
29*4684ddb6SLionel Sambuc if (ov != expected_overflow) {
30*4684ddb6SLionel Sambuc twords at;
31*4684ddb6SLionel Sambuc at.all = a;
32*4684ddb6SLionel Sambuc twords bt;
33*4684ddb6SLionel Sambuc bt.all = b;
34*4684ddb6SLionel Sambuc twords xt;
35*4684ddb6SLionel Sambuc xt.all = x;
36*4684ddb6SLionel Sambuc twords expectedt;
37*4684ddb6SLionel Sambuc expectedt.all = expected;
38*4684ddb6SLionel Sambuc
39*4684ddb6SLionel Sambuc printf("error in __muloti4: overflow=%d expected=%d\n",
40*4684ddb6SLionel Sambuc ov, expected_overflow);
41*4684ddb6SLionel Sambuc printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
42*4684ddb6SLionel Sambuc "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
43*4684ddb6SLionel Sambuc at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
44*4684ddb6SLionel Sambuc expectedt.s.high, expectedt.s.low);
45*4684ddb6SLionel Sambuc return 1;
46*4684ddb6SLionel Sambuc }
47*4684ddb6SLionel Sambuc else if (!expected_overflow && x != expected)
48*4684ddb6SLionel Sambuc {
49*4684ddb6SLionel Sambuc twords at;
50*4684ddb6SLionel Sambuc at.all = a;
51*4684ddb6SLionel Sambuc twords bt;
52*4684ddb6SLionel Sambuc bt.all = b;
53*4684ddb6SLionel Sambuc twords xt;
54*4684ddb6SLionel Sambuc xt.all = x;
55*4684ddb6SLionel Sambuc twords expectedt;
56*4684ddb6SLionel Sambuc expectedt.all = expected;
57*4684ddb6SLionel Sambuc printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
58*4684ddb6SLionel Sambuc "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
59*4684ddb6SLionel Sambuc at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
60*4684ddb6SLionel Sambuc expectedt.s.high, expectedt.s.low);
61*4684ddb6SLionel Sambuc return 1;
62*4684ddb6SLionel Sambuc }
63*4684ddb6SLionel Sambuc return 0;
64*4684ddb6SLionel Sambuc }
65*4684ddb6SLionel Sambuc
66*4684ddb6SLionel Sambuc #endif
67*4684ddb6SLionel Sambuc
main()68*4684ddb6SLionel Sambuc int main()
69*4684ddb6SLionel Sambuc {
70*4684ddb6SLionel Sambuc #if __x86_64
71*4684ddb6SLionel Sambuc if (test__muloti4(0, 0, 0, 0))
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc if (test__muloti4(0, 1, 0, 0))
74*4684ddb6SLionel Sambuc return 1;
75*4684ddb6SLionel Sambuc if (test__muloti4(1, 0, 0, 0))
76*4684ddb6SLionel Sambuc return 1;
77*4684ddb6SLionel Sambuc if (test__muloti4(0, 10, 0, 0))
78*4684ddb6SLionel Sambuc return 1;
79*4684ddb6SLionel Sambuc if (test__muloti4(10, 0, 0, 0))
80*4684ddb6SLionel Sambuc return 1;
81*4684ddb6SLionel Sambuc if (test__muloti4(0, 81985529216486895LL, 0, 0))
82*4684ddb6SLionel Sambuc return 1;
83*4684ddb6SLionel Sambuc if (test__muloti4(81985529216486895LL, 0, 0, 0))
84*4684ddb6SLionel Sambuc return 1;
85*4684ddb6SLionel Sambuc
86*4684ddb6SLionel Sambuc if (test__muloti4(0, -1, 0, 0))
87*4684ddb6SLionel Sambuc return 1;
88*4684ddb6SLionel Sambuc if (test__muloti4(-1, 0, 0, 0))
89*4684ddb6SLionel Sambuc return 1;
90*4684ddb6SLionel Sambuc if (test__muloti4(0, -10, 0, 0))
91*4684ddb6SLionel Sambuc return 1;
92*4684ddb6SLionel Sambuc if (test__muloti4(-10, 0, 0, 0))
93*4684ddb6SLionel Sambuc return 1;
94*4684ddb6SLionel Sambuc if (test__muloti4(0, -81985529216486895LL, 0, 0))
95*4684ddb6SLionel Sambuc return 1;
96*4684ddb6SLionel Sambuc if (test__muloti4(-81985529216486895LL, 0, 0, 0))
97*4684ddb6SLionel Sambuc return 1;
98*4684ddb6SLionel Sambuc
99*4684ddb6SLionel Sambuc if (test__muloti4(1, 1, 1, 0))
100*4684ddb6SLionel Sambuc return 1;
101*4684ddb6SLionel Sambuc if (test__muloti4(1, 10, 10, 0))
102*4684ddb6SLionel Sambuc return 1;
103*4684ddb6SLionel Sambuc if (test__muloti4(10, 1, 10, 0))
104*4684ddb6SLionel Sambuc return 1;
105*4684ddb6SLionel Sambuc if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
106*4684ddb6SLionel Sambuc return 1;
107*4684ddb6SLionel Sambuc if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0))
108*4684ddb6SLionel Sambuc return 1;
109*4684ddb6SLionel Sambuc
110*4684ddb6SLionel Sambuc if (test__muloti4(1, -1, -1, 0))
111*4684ddb6SLionel Sambuc return 1;
112*4684ddb6SLionel Sambuc if (test__muloti4(1, -10, -10, 0))
113*4684ddb6SLionel Sambuc return 1;
114*4684ddb6SLionel Sambuc if (test__muloti4(-10, 1, -10, 0))
115*4684ddb6SLionel Sambuc return 1;
116*4684ddb6SLionel Sambuc if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0))
117*4684ddb6SLionel Sambuc return 1;
118*4684ddb6SLionel Sambuc if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0))
119*4684ddb6SLionel Sambuc return 1;
120*4684ddb6SLionel Sambuc
121*4684ddb6SLionel Sambuc if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
122*4684ddb6SLionel Sambuc return 1;
123*4684ddb6SLionel Sambuc if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
124*4684ddb6SLionel Sambuc return 1;
125*4684ddb6SLionel Sambuc if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
126*4684ddb6SLionel Sambuc return 1;
127*4684ddb6SLionel Sambuc if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
128*4684ddb6SLionel Sambuc return 1;
129*4684ddb6SLionel Sambuc
130*4684ddb6SLionel Sambuc if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
131*4684ddb6SLionel Sambuc return 1;
132*4684ddb6SLionel Sambuc if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
133*4684ddb6SLionel Sambuc return 1;
134*4684ddb6SLionel Sambuc if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
135*4684ddb6SLionel Sambuc return 1;
136*4684ddb6SLionel Sambuc if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
137*4684ddb6SLionel Sambuc return 1;
138*4684ddb6SLionel Sambuc
139*4684ddb6SLionel Sambuc if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
140*4684ddb6SLionel Sambuc return 1;
141*4684ddb6SLionel Sambuc if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
142*4684ddb6SLionel Sambuc return 1;
143*4684ddb6SLionel Sambuc if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
144*4684ddb6SLionel Sambuc return 1;
145*4684ddb6SLionel Sambuc if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
146*4684ddb6SLionel Sambuc return 1;
147*4684ddb6SLionel Sambuc
148*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
149*4684ddb6SLionel Sambuc make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
150*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL), 0))
151*4684ddb6SLionel Sambuc return 1;
152*4684ddb6SLionel Sambuc
153*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
154*4684ddb6SLionel Sambuc -2,
155*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
156*4684ddb6SLionel Sambuc return 1;
157*4684ddb6SLionel Sambuc if (test__muloti4(-2,
158*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
159*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
160*4684ddb6SLionel Sambuc return 1;
161*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
162*4684ddb6SLionel Sambuc -1,
163*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
164*4684ddb6SLionel Sambuc return 1;
165*4684ddb6SLionel Sambuc if (test__muloti4(-1,
166*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
167*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
168*4684ddb6SLionel Sambuc return 1;
169*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
170*4684ddb6SLionel Sambuc 0,
171*4684ddb6SLionel Sambuc 0, 0))
172*4684ddb6SLionel Sambuc return 1;
173*4684ddb6SLionel Sambuc if (test__muloti4(0,
174*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
175*4684ddb6SLionel Sambuc 0, 0))
176*4684ddb6SLionel Sambuc return 1;
177*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
178*4684ddb6SLionel Sambuc 1,
179*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
180*4684ddb6SLionel Sambuc return 1;
181*4684ddb6SLionel Sambuc if (test__muloti4(1,
182*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
183*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
184*4684ddb6SLionel Sambuc return 1;
185*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
186*4684ddb6SLionel Sambuc 2,
187*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
188*4684ddb6SLionel Sambuc return 1;
189*4684ddb6SLionel Sambuc if (test__muloti4(2,
190*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
191*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
192*4684ddb6SLionel Sambuc return 1;
193*4684ddb6SLionel Sambuc
194*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
195*4684ddb6SLionel Sambuc -2,
196*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
197*4684ddb6SLionel Sambuc return 1;
198*4684ddb6SLionel Sambuc if (test__muloti4(-2,
199*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL),
200*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
201*4684ddb6SLionel Sambuc return 1;
202*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
203*4684ddb6SLionel Sambuc -1,
204*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
205*4684ddb6SLionel Sambuc return 1;
206*4684ddb6SLionel Sambuc if (test__muloti4(-1,
207*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL),
208*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
209*4684ddb6SLionel Sambuc return 1;
210*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
211*4684ddb6SLionel Sambuc 0,
212*4684ddb6SLionel Sambuc 0, 0))
213*4684ddb6SLionel Sambuc return 1;
214*4684ddb6SLionel Sambuc if (test__muloti4(0,
215*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL),
216*4684ddb6SLionel Sambuc 0, 0))
217*4684ddb6SLionel Sambuc return 1;
218*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
219*4684ddb6SLionel Sambuc 1,
220*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
221*4684ddb6SLionel Sambuc return 1;
222*4684ddb6SLionel Sambuc if (test__muloti4(1,
223*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL),
224*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
225*4684ddb6SLionel Sambuc return 1;
226*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
227*4684ddb6SLionel Sambuc 2,
228*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
229*4684ddb6SLionel Sambuc return 1;
230*4684ddb6SLionel Sambuc if (test__muloti4(2,
231*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL),
232*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
233*4684ddb6SLionel Sambuc return 1;
234*4684ddb6SLionel Sambuc
235*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
236*4684ddb6SLionel Sambuc -2,
237*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
238*4684ddb6SLionel Sambuc return 1;
239*4684ddb6SLionel Sambuc if (test__muloti4(-2,
240*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL),
241*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
242*4684ddb6SLionel Sambuc return 1;
243*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
244*4684ddb6SLionel Sambuc -1,
245*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
246*4684ddb6SLionel Sambuc return 1;
247*4684ddb6SLionel Sambuc if (test__muloti4(-1,
248*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL),
249*4684ddb6SLionel Sambuc make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
250*4684ddb6SLionel Sambuc return 1;
251*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
252*4684ddb6SLionel Sambuc 0,
253*4684ddb6SLionel Sambuc 0, 0))
254*4684ddb6SLionel Sambuc return 1;
255*4684ddb6SLionel Sambuc if (test__muloti4(0,
256*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL),
257*4684ddb6SLionel Sambuc 0, 0))
258*4684ddb6SLionel Sambuc return 1;
259*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
260*4684ddb6SLionel Sambuc 1,
261*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
262*4684ddb6SLionel Sambuc return 1;
263*4684ddb6SLionel Sambuc if (test__muloti4(1,
264*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL),
265*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
266*4684ddb6SLionel Sambuc return 1;
267*4684ddb6SLionel Sambuc if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
268*4684ddb6SLionel Sambuc 2,
269*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
270*4684ddb6SLionel Sambuc return 1;
271*4684ddb6SLionel Sambuc if (test__muloti4(2,
272*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000001LL),
273*4684ddb6SLionel Sambuc make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
274*4684ddb6SLionel Sambuc return 1;
275*4684ddb6SLionel Sambuc
276*4684ddb6SLionel Sambuc #else
277*4684ddb6SLionel Sambuc printf("skipped\n");
278*4684ddb6SLionel Sambuc #endif
279*4684ddb6SLionel Sambuc return 0;
280*4684ddb6SLionel Sambuc }
281