1*7c3d14c8STreehugger Robot //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
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 __mulvti3 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 // Effects: aborts if a * b overflows
22*7c3d14c8STreehugger Robot
23*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __mulvti3(ti_int a, ti_int b);
24*7c3d14c8STreehugger Robot
test__mulvti3(ti_int a,ti_int b,ti_int expected)25*7c3d14c8STreehugger Robot int test__mulvti3(ti_int a, ti_int b, ti_int expected)
26*7c3d14c8STreehugger Robot {
27*7c3d14c8STreehugger Robot ti_int x = __mulvti3(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 __mulvti3: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
39*7c3d14c8STreehugger Robot "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
40*7c3d14c8STreehugger Robot at.s.high, at.s.low, bt.s.high, bt.s.low, 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 #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__mulvti3(0, 0, 0))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot if (test__mulvti3(0, 1, 0))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot if (test__mulvti3(1, 0, 0))
56*7c3d14c8STreehugger Robot return 1;
57*7c3d14c8STreehugger Robot if (test__mulvti3(0, 10, 0))
58*7c3d14c8STreehugger Robot return 1;
59*7c3d14c8STreehugger Robot if (test__mulvti3(10, 0, 0))
60*7c3d14c8STreehugger Robot return 1;
61*7c3d14c8STreehugger Robot if (test__mulvti3(0, 81985529216486895LL, 0))
62*7c3d14c8STreehugger Robot return 1;
63*7c3d14c8STreehugger Robot if (test__mulvti3(81985529216486895LL, 0, 0))
64*7c3d14c8STreehugger Robot return 1;
65*7c3d14c8STreehugger Robot
66*7c3d14c8STreehugger Robot if (test__mulvti3(0, -1, 0))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot if (test__mulvti3(-1, 0, 0))
69*7c3d14c8STreehugger Robot return 1;
70*7c3d14c8STreehugger Robot if (test__mulvti3(0, -10, 0))
71*7c3d14c8STreehugger Robot return 1;
72*7c3d14c8STreehugger Robot if (test__mulvti3(-10, 0, 0))
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot if (test__mulvti3(0, -81985529216486895LL, 0))
75*7c3d14c8STreehugger Robot return 1;
76*7c3d14c8STreehugger Robot if (test__mulvti3(-81985529216486895LL, 0, 0))
77*7c3d14c8STreehugger Robot return 1;
78*7c3d14c8STreehugger Robot
79*7c3d14c8STreehugger Robot if (test__mulvti3(1, 1, 1))
80*7c3d14c8STreehugger Robot return 1;
81*7c3d14c8STreehugger Robot if (test__mulvti3(1, 10, 10))
82*7c3d14c8STreehugger Robot return 1;
83*7c3d14c8STreehugger Robot if (test__mulvti3(10, 1, 10))
84*7c3d14c8STreehugger Robot return 1;
85*7c3d14c8STreehugger Robot if (test__mulvti3(1, 81985529216486895LL, 81985529216486895LL))
86*7c3d14c8STreehugger Robot return 1;
87*7c3d14c8STreehugger Robot if (test__mulvti3(81985529216486895LL, 1, 81985529216486895LL))
88*7c3d14c8STreehugger Robot return 1;
89*7c3d14c8STreehugger Robot
90*7c3d14c8STreehugger Robot if (test__mulvti3(1, -1, -1))
91*7c3d14c8STreehugger Robot return 1;
92*7c3d14c8STreehugger Robot if (test__mulvti3(1, -10, -10))
93*7c3d14c8STreehugger Robot return 1;
94*7c3d14c8STreehugger Robot if (test__mulvti3(-10, 1, -10))
95*7c3d14c8STreehugger Robot return 1;
96*7c3d14c8STreehugger Robot if (test__mulvti3(1, -81985529216486895LL, -81985529216486895LL))
97*7c3d14c8STreehugger Robot return 1;
98*7c3d14c8STreehugger Robot if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
99*7c3d14c8STreehugger Robot return 1;
100*7c3d14c8STreehugger Robot
101*7c3d14c8STreehugger Robot if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL))
102*7c3d14c8STreehugger Robot return 1;
103*7c3d14c8STreehugger Robot if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
104*7c3d14c8STreehugger Robot return 1;
105*7c3d14c8STreehugger Robot if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
106*7c3d14c8STreehugger Robot return 1;
107*7c3d14c8STreehugger Robot if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
108*7c3d14c8STreehugger Robot return 1;
109*7c3d14c8STreehugger Robot
110*7c3d14c8STreehugger Robot if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
111*7c3d14c8STreehugger Robot return 1;
112*7c3d14c8STreehugger Robot if (test__mulvti3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
113*7c3d14c8STreehugger Robot return 1;
114*7c3d14c8STreehugger Robot if (test__mulvti3(4398046511103LL, -2097152LL, -9223372036852678656LL))
115*7c3d14c8STreehugger Robot return 1;
116*7c3d14c8STreehugger Robot if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
117*7c3d14c8STreehugger Robot return 1;
118*7c3d14c8STreehugger Robot
119*7c3d14c8STreehugger Robot if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL))
120*7c3d14c8STreehugger Robot return 1;
121*7c3d14c8STreehugger Robot if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
122*7c3d14c8STreehugger Robot return 1;
123*7c3d14c8STreehugger Robot if (test__mulvti3(2097152LL, -4398046511103LL, -9223372036852678656LL))
124*7c3d14c8STreehugger Robot return 1;
125*7c3d14c8STreehugger Robot if (test__mulvti3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
126*7c3d14c8STreehugger Robot return 1;
127*7c3d14c8STreehugger Robot
128*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
129*7c3d14c8STreehugger Robot make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
130*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL)))
131*7c3d14c8STreehugger Robot return 1;
132*7c3d14c8STreehugger Robot
133*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
134*7c3d14c8STreehugger Robot // -2,
135*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
136*7c3d14c8STreehugger Robot // return 1;
137*7c3d14c8STreehugger Robot // if (test__mulvti3(-2,
138*7c3d14c8STreehugger Robot // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
139*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
140*7c3d14c8STreehugger Robot // return 1;
141*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
142*7c3d14c8STreehugger Robot -1,
143*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
144*7c3d14c8STreehugger Robot return 1;
145*7c3d14c8STreehugger Robot if (test__mulvti3(-1,
146*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
147*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
148*7c3d14c8STreehugger Robot return 1;
149*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
150*7c3d14c8STreehugger Robot 0,
151*7c3d14c8STreehugger Robot 0))
152*7c3d14c8STreehugger Robot return 1;
153*7c3d14c8STreehugger Robot if (test__mulvti3(0,
154*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
155*7c3d14c8STreehugger Robot 0))
156*7c3d14c8STreehugger Robot return 1;
157*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
158*7c3d14c8STreehugger Robot 1,
159*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
160*7c3d14c8STreehugger Robot return 1;
161*7c3d14c8STreehugger Robot if (test__mulvti3(1,
162*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
163*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
164*7c3d14c8STreehugger Robot return 1;
165*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
166*7c3d14c8STreehugger Robot // 2,
167*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
168*7c3d14c8STreehugger Robot // return 1;
169*7c3d14c8STreehugger Robot // if (test__mulvti3(2,
170*7c3d14c8STreehugger Robot // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
171*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
172*7c3d14c8STreehugger Robot // return 1;
173*7c3d14c8STreehugger Robot
174*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
175*7c3d14c8STreehugger Robot // -2,
176*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
177*7c3d14c8STreehugger Robot // return 1;
178*7c3d14c8STreehugger Robot // if (test__mulvti3(-2,
179*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
180*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
181*7c3d14c8STreehugger Robot // return 1;
182*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
183*7c3d14c8STreehugger Robot // -1,
184*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
185*7c3d14c8STreehugger Robot // return 1;
186*7c3d14c8STreehugger Robot // if (test__mulvti3(-1,
187*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
188*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
189*7c3d14c8STreehugger Robot // return 1;
190*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
191*7c3d14c8STreehugger Robot 0,
192*7c3d14c8STreehugger Robot 0))
193*7c3d14c8STreehugger Robot return 1;
194*7c3d14c8STreehugger Robot if (test__mulvti3(0,
195*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000000LL),
196*7c3d14c8STreehugger Robot 0))
197*7c3d14c8STreehugger Robot return 1;
198*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
199*7c3d14c8STreehugger Robot 1,
200*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
201*7c3d14c8STreehugger Robot return 1;
202*7c3d14c8STreehugger Robot if (test__mulvti3(1,
203*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000000LL),
204*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
205*7c3d14c8STreehugger Robot return 1;
206*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
207*7c3d14c8STreehugger Robot // 2,
208*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
209*7c3d14c8STreehugger Robot // return 1;
210*7c3d14c8STreehugger Robot // if (test__mulvti3(2,
211*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
212*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
213*7c3d14c8STreehugger Robot // return 1;
214*7c3d14c8STreehugger Robot
215*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
216*7c3d14c8STreehugger Robot // -2,
217*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
218*7c3d14c8STreehugger Robot // return 1;
219*7c3d14c8STreehugger Robot // if (test__mulvti3(-2,
220*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
221*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
222*7c3d14c8STreehugger Robot // return 1;
223*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
224*7c3d14c8STreehugger Robot -1,
225*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
226*7c3d14c8STreehugger Robot return 1;
227*7c3d14c8STreehugger Robot if (test__mulvti3(-1,
228*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL),
229*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
230*7c3d14c8STreehugger Robot return 1;
231*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
232*7c3d14c8STreehugger Robot 0,
233*7c3d14c8STreehugger Robot 0))
234*7c3d14c8STreehugger Robot return 1;
235*7c3d14c8STreehugger Robot if (test__mulvti3(0,
236*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL),
237*7c3d14c8STreehugger Robot 0))
238*7c3d14c8STreehugger Robot return 1;
239*7c3d14c8STreehugger Robot if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
240*7c3d14c8STreehugger Robot 1,
241*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
242*7c3d14c8STreehugger Robot return 1;
243*7c3d14c8STreehugger Robot if (test__mulvti3(1,
244*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL),
245*7c3d14c8STreehugger Robot make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
246*7c3d14c8STreehugger Robot return 1;
247*7c3d14c8STreehugger Robot // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
248*7c3d14c8STreehugger Robot // 2,
249*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
250*7c3d14c8STreehugger Robot // return 1;
251*7c3d14c8STreehugger Robot // if (test__mulvti3(2,
252*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
253*7c3d14c8STreehugger Robot // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
254*7c3d14c8STreehugger Robot // return 1;
255*7c3d14c8STreehugger Robot
256*7c3d14c8STreehugger Robot #else
257*7c3d14c8STreehugger Robot printf("skipped\n");
258*7c3d14c8STreehugger Robot #endif
259*7c3d14c8STreehugger Robot return 0;
260*7c3d14c8STreehugger Robot }
261