1*7c3d14c8STreehugger Robot //===-- multc3_test.c - Test __multc3 -------------------------------------===//
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 __multc3 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot #include <stdio.h>
15*7c3d14c8STreehugger Robot
16*7c3d14c8STreehugger Robot #if _ARCH_PPC || __aarch64__
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot #include "int_lib.h"
19*7c3d14c8STreehugger Robot #include <math.h>
20*7c3d14c8STreehugger Robot #include <complex.h>
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger Robot // Returns: the product of a + ib and c + id
23*7c3d14c8STreehugger Robot
24*7c3d14c8STreehugger Robot COMPILER_RT_ABI long double _Complex
25*7c3d14c8STreehugger Robot __multc3(long double __a, long double __b, long double __c, long double __d);
26*7c3d14c8STreehugger Robot
27*7c3d14c8STreehugger Robot enum {zero, non_zero, inf, NaN, non_zero_nan};
28*7c3d14c8STreehugger Robot
29*7c3d14c8STreehugger Robot int
classify(long double _Complex x)30*7c3d14c8STreehugger Robot classify(long double _Complex x)
31*7c3d14c8STreehugger Robot {
32*7c3d14c8STreehugger Robot if (x == 0)
33*7c3d14c8STreehugger Robot return zero;
34*7c3d14c8STreehugger Robot if (isinf(creall(x)) || isinf(cimagl(x)))
35*7c3d14c8STreehugger Robot return inf;
36*7c3d14c8STreehugger Robot if (isnan(creall(x)) && isnan(cimagl(x)))
37*7c3d14c8STreehugger Robot return NaN;
38*7c3d14c8STreehugger Robot if (isnan(creall(x)))
39*7c3d14c8STreehugger Robot {
40*7c3d14c8STreehugger Robot if (cimagl(x) == 0)
41*7c3d14c8STreehugger Robot return NaN;
42*7c3d14c8STreehugger Robot return non_zero_nan;
43*7c3d14c8STreehugger Robot }
44*7c3d14c8STreehugger Robot if (isnan(cimagl(x)))
45*7c3d14c8STreehugger Robot {
46*7c3d14c8STreehugger Robot if (creall(x) == 0)
47*7c3d14c8STreehugger Robot return NaN;
48*7c3d14c8STreehugger Robot return non_zero_nan;
49*7c3d14c8STreehugger Robot }
50*7c3d14c8STreehugger Robot return non_zero;
51*7c3d14c8STreehugger Robot }
52*7c3d14c8STreehugger Robot
test__multc3(long double a,long double b,long double c,long double d)53*7c3d14c8STreehugger Robot int test__multc3(long double a, long double b, long double c, long double d)
54*7c3d14c8STreehugger Robot {
55*7c3d14c8STreehugger Robot long double _Complex r = __multc3(a, b, c, d);
56*7c3d14c8STreehugger Robot // printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
57*7c3d14c8STreehugger Robot // a, b, c, d, creall(r), cimagl(r));
58*7c3d14c8STreehugger Robot long double _Complex dividend;
59*7c3d14c8STreehugger Robot long double _Complex divisor;
60*7c3d14c8STreehugger Robot
61*7c3d14c8STreehugger Robot __real__ dividend = a;
62*7c3d14c8STreehugger Robot __imag__ dividend = b;
63*7c3d14c8STreehugger Robot __real__ divisor = c;
64*7c3d14c8STreehugger Robot __imag__ divisor = d;
65*7c3d14c8STreehugger Robot
66*7c3d14c8STreehugger Robot switch (classify(dividend))
67*7c3d14c8STreehugger Robot {
68*7c3d14c8STreehugger Robot case zero:
69*7c3d14c8STreehugger Robot switch (classify(divisor))
70*7c3d14c8STreehugger Robot {
71*7c3d14c8STreehugger Robot case zero:
72*7c3d14c8STreehugger Robot if (classify(r) != zero)
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot break;
75*7c3d14c8STreehugger Robot case non_zero:
76*7c3d14c8STreehugger Robot if (classify(r) != zero)
77*7c3d14c8STreehugger Robot return 1;
78*7c3d14c8STreehugger Robot break;
79*7c3d14c8STreehugger Robot case inf:
80*7c3d14c8STreehugger Robot if (classify(r) != NaN)
81*7c3d14c8STreehugger Robot return 1;
82*7c3d14c8STreehugger Robot break;
83*7c3d14c8STreehugger Robot case NaN:
84*7c3d14c8STreehugger Robot if (classify(r) != NaN)
85*7c3d14c8STreehugger Robot return 1;
86*7c3d14c8STreehugger Robot break;
87*7c3d14c8STreehugger Robot case non_zero_nan:
88*7c3d14c8STreehugger Robot if (classify(r) != NaN)
89*7c3d14c8STreehugger Robot return 1;
90*7c3d14c8STreehugger Robot break;
91*7c3d14c8STreehugger Robot }
92*7c3d14c8STreehugger Robot break;
93*7c3d14c8STreehugger Robot case non_zero:
94*7c3d14c8STreehugger Robot switch (classify(divisor))
95*7c3d14c8STreehugger Robot {
96*7c3d14c8STreehugger Robot case zero:
97*7c3d14c8STreehugger Robot if (classify(r) != zero)
98*7c3d14c8STreehugger Robot return 1;
99*7c3d14c8STreehugger Robot break;
100*7c3d14c8STreehugger Robot case non_zero:
101*7c3d14c8STreehugger Robot if (classify(r) != non_zero)
102*7c3d14c8STreehugger Robot return 1;
103*7c3d14c8STreehugger Robot if (r != a * c - b * d + _Complex_I*(a * d + b * c))
104*7c3d14c8STreehugger Robot return 1;
105*7c3d14c8STreehugger Robot break;
106*7c3d14c8STreehugger Robot case inf:
107*7c3d14c8STreehugger Robot if (classify(r) != inf)
108*7c3d14c8STreehugger Robot return 1;
109*7c3d14c8STreehugger Robot break;
110*7c3d14c8STreehugger Robot case NaN:
111*7c3d14c8STreehugger Robot if (classify(r) != NaN)
112*7c3d14c8STreehugger Robot return 1;
113*7c3d14c8STreehugger Robot break;
114*7c3d14c8STreehugger Robot case non_zero_nan:
115*7c3d14c8STreehugger Robot if (classify(r) != NaN)
116*7c3d14c8STreehugger Robot return 1;
117*7c3d14c8STreehugger Robot break;
118*7c3d14c8STreehugger Robot }
119*7c3d14c8STreehugger Robot break;
120*7c3d14c8STreehugger Robot case inf:
121*7c3d14c8STreehugger Robot switch (classify(divisor))
122*7c3d14c8STreehugger Robot {
123*7c3d14c8STreehugger Robot case zero:
124*7c3d14c8STreehugger Robot if (classify(r) != NaN)
125*7c3d14c8STreehugger Robot return 1;
126*7c3d14c8STreehugger Robot break;
127*7c3d14c8STreehugger Robot case non_zero:
128*7c3d14c8STreehugger Robot if (classify(r) != inf)
129*7c3d14c8STreehugger Robot return 1;
130*7c3d14c8STreehugger Robot break;
131*7c3d14c8STreehugger Robot case inf:
132*7c3d14c8STreehugger Robot if (classify(r) != inf)
133*7c3d14c8STreehugger Robot return 1;
134*7c3d14c8STreehugger Robot break;
135*7c3d14c8STreehugger Robot case NaN:
136*7c3d14c8STreehugger Robot if (classify(r) != NaN)
137*7c3d14c8STreehugger Robot return 1;
138*7c3d14c8STreehugger Robot break;
139*7c3d14c8STreehugger Robot case non_zero_nan:
140*7c3d14c8STreehugger Robot if (classify(r) != inf)
141*7c3d14c8STreehugger Robot return 1;
142*7c3d14c8STreehugger Robot break;
143*7c3d14c8STreehugger Robot }
144*7c3d14c8STreehugger Robot break;
145*7c3d14c8STreehugger Robot case NaN:
146*7c3d14c8STreehugger Robot switch (classify(divisor))
147*7c3d14c8STreehugger Robot {
148*7c3d14c8STreehugger Robot case zero:
149*7c3d14c8STreehugger Robot if (classify(r) != NaN)
150*7c3d14c8STreehugger Robot return 1;
151*7c3d14c8STreehugger Robot break;
152*7c3d14c8STreehugger Robot case non_zero:
153*7c3d14c8STreehugger Robot if (classify(r) != NaN)
154*7c3d14c8STreehugger Robot return 1;
155*7c3d14c8STreehugger Robot break;
156*7c3d14c8STreehugger Robot case inf:
157*7c3d14c8STreehugger Robot if (classify(r) != NaN)
158*7c3d14c8STreehugger Robot return 1;
159*7c3d14c8STreehugger Robot break;
160*7c3d14c8STreehugger Robot case NaN:
161*7c3d14c8STreehugger Robot if (classify(r) != NaN)
162*7c3d14c8STreehugger Robot return 1;
163*7c3d14c8STreehugger Robot break;
164*7c3d14c8STreehugger Robot case non_zero_nan:
165*7c3d14c8STreehugger Robot if (classify(r) != NaN)
166*7c3d14c8STreehugger Robot return 1;
167*7c3d14c8STreehugger Robot break;
168*7c3d14c8STreehugger Robot }
169*7c3d14c8STreehugger Robot break;
170*7c3d14c8STreehugger Robot case non_zero_nan:
171*7c3d14c8STreehugger Robot switch (classify(divisor))
172*7c3d14c8STreehugger Robot {
173*7c3d14c8STreehugger Robot case zero:
174*7c3d14c8STreehugger Robot if (classify(r) != NaN)
175*7c3d14c8STreehugger Robot return 1;
176*7c3d14c8STreehugger Robot break;
177*7c3d14c8STreehugger Robot case non_zero:
178*7c3d14c8STreehugger Robot if (classify(r) != NaN)
179*7c3d14c8STreehugger Robot return 1;
180*7c3d14c8STreehugger Robot break;
181*7c3d14c8STreehugger Robot case inf:
182*7c3d14c8STreehugger Robot if (classify(r) != inf)
183*7c3d14c8STreehugger Robot return 1;
184*7c3d14c8STreehugger Robot break;
185*7c3d14c8STreehugger Robot case NaN:
186*7c3d14c8STreehugger Robot if (classify(r) != NaN)
187*7c3d14c8STreehugger Robot return 1;
188*7c3d14c8STreehugger Robot break;
189*7c3d14c8STreehugger Robot case non_zero_nan:
190*7c3d14c8STreehugger Robot if (classify(r) != NaN)
191*7c3d14c8STreehugger Robot return 1;
192*7c3d14c8STreehugger Robot break;
193*7c3d14c8STreehugger Robot }
194*7c3d14c8STreehugger Robot break;
195*7c3d14c8STreehugger Robot }
196*7c3d14c8STreehugger Robot
197*7c3d14c8STreehugger Robot return 0;
198*7c3d14c8STreehugger Robot }
199*7c3d14c8STreehugger Robot
200*7c3d14c8STreehugger Robot long double x[][2] =
201*7c3d14c8STreehugger Robot {
202*7c3d14c8STreehugger Robot { 1.e-6, 1.e-6},
203*7c3d14c8STreehugger Robot {-1.e-6, 1.e-6},
204*7c3d14c8STreehugger Robot {-1.e-6, -1.e-6},
205*7c3d14c8STreehugger Robot { 1.e-6, -1.e-6},
206*7c3d14c8STreehugger Robot
207*7c3d14c8STreehugger Robot { 1.e+6, 1.e-6},
208*7c3d14c8STreehugger Robot {-1.e+6, 1.e-6},
209*7c3d14c8STreehugger Robot {-1.e+6, -1.e-6},
210*7c3d14c8STreehugger Robot { 1.e+6, -1.e-6},
211*7c3d14c8STreehugger Robot
212*7c3d14c8STreehugger Robot { 1.e-6, 1.e+6},
213*7c3d14c8STreehugger Robot {-1.e-6, 1.e+6},
214*7c3d14c8STreehugger Robot {-1.e-6, -1.e+6},
215*7c3d14c8STreehugger Robot { 1.e-6, -1.e+6},
216*7c3d14c8STreehugger Robot
217*7c3d14c8STreehugger Robot { 1.e+6, 1.e+6},
218*7c3d14c8STreehugger Robot {-1.e+6, 1.e+6},
219*7c3d14c8STreehugger Robot {-1.e+6, -1.e+6},
220*7c3d14c8STreehugger Robot { 1.e+6, -1.e+6},
221*7c3d14c8STreehugger Robot
222*7c3d14c8STreehugger Robot {NAN, NAN},
223*7c3d14c8STreehugger Robot {-INFINITY, NAN},
224*7c3d14c8STreehugger Robot {-2, NAN},
225*7c3d14c8STreehugger Robot {-1, NAN},
226*7c3d14c8STreehugger Robot {-0.5, NAN},
227*7c3d14c8STreehugger Robot {-0., NAN},
228*7c3d14c8STreehugger Robot {+0., NAN},
229*7c3d14c8STreehugger Robot {0.5, NAN},
230*7c3d14c8STreehugger Robot {1, NAN},
231*7c3d14c8STreehugger Robot {2, NAN},
232*7c3d14c8STreehugger Robot {INFINITY, NAN},
233*7c3d14c8STreehugger Robot
234*7c3d14c8STreehugger Robot {NAN, -INFINITY},
235*7c3d14c8STreehugger Robot {-INFINITY, -INFINITY},
236*7c3d14c8STreehugger Robot {-2, -INFINITY},
237*7c3d14c8STreehugger Robot {-1, -INFINITY},
238*7c3d14c8STreehugger Robot {-0.5, -INFINITY},
239*7c3d14c8STreehugger Robot {-0., -INFINITY},
240*7c3d14c8STreehugger Robot {+0., -INFINITY},
241*7c3d14c8STreehugger Robot {0.5, -INFINITY},
242*7c3d14c8STreehugger Robot {1, -INFINITY},
243*7c3d14c8STreehugger Robot {2, -INFINITY},
244*7c3d14c8STreehugger Robot {INFINITY, -INFINITY},
245*7c3d14c8STreehugger Robot
246*7c3d14c8STreehugger Robot {NAN, -2},
247*7c3d14c8STreehugger Robot {-INFINITY, -2},
248*7c3d14c8STreehugger Robot {-2, -2},
249*7c3d14c8STreehugger Robot {-1, -2},
250*7c3d14c8STreehugger Robot {-0.5, -2},
251*7c3d14c8STreehugger Robot {-0., -2},
252*7c3d14c8STreehugger Robot {+0., -2},
253*7c3d14c8STreehugger Robot {0.5, -2},
254*7c3d14c8STreehugger Robot {1, -2},
255*7c3d14c8STreehugger Robot {2, -2},
256*7c3d14c8STreehugger Robot {INFINITY, -2},
257*7c3d14c8STreehugger Robot
258*7c3d14c8STreehugger Robot {NAN, -1},
259*7c3d14c8STreehugger Robot {-INFINITY, -1},
260*7c3d14c8STreehugger Robot {-2, -1},
261*7c3d14c8STreehugger Robot {-1, -1},
262*7c3d14c8STreehugger Robot {-0.5, -1},
263*7c3d14c8STreehugger Robot {-0., -1},
264*7c3d14c8STreehugger Robot {+0., -1},
265*7c3d14c8STreehugger Robot {0.5, -1},
266*7c3d14c8STreehugger Robot {1, -1},
267*7c3d14c8STreehugger Robot {2, -1},
268*7c3d14c8STreehugger Robot {INFINITY, -1},
269*7c3d14c8STreehugger Robot
270*7c3d14c8STreehugger Robot {NAN, -0.5},
271*7c3d14c8STreehugger Robot {-INFINITY, -0.5},
272*7c3d14c8STreehugger Robot {-2, -0.5},
273*7c3d14c8STreehugger Robot {-1, -0.5},
274*7c3d14c8STreehugger Robot {-0.5, -0.5},
275*7c3d14c8STreehugger Robot {-0., -0.5},
276*7c3d14c8STreehugger Robot {+0., -0.5},
277*7c3d14c8STreehugger Robot {0.5, -0.5},
278*7c3d14c8STreehugger Robot {1, -0.5},
279*7c3d14c8STreehugger Robot {2, -0.5},
280*7c3d14c8STreehugger Robot {INFINITY, -0.5},
281*7c3d14c8STreehugger Robot
282*7c3d14c8STreehugger Robot {NAN, -0.},
283*7c3d14c8STreehugger Robot {-INFINITY, -0.},
284*7c3d14c8STreehugger Robot {-2, -0.},
285*7c3d14c8STreehugger Robot {-1, -0.},
286*7c3d14c8STreehugger Robot {-0.5, -0.},
287*7c3d14c8STreehugger Robot {-0., -0.},
288*7c3d14c8STreehugger Robot {+0., -0.},
289*7c3d14c8STreehugger Robot {0.5, -0.},
290*7c3d14c8STreehugger Robot {1, -0.},
291*7c3d14c8STreehugger Robot {2, -0.},
292*7c3d14c8STreehugger Robot {INFINITY, -0.},
293*7c3d14c8STreehugger Robot
294*7c3d14c8STreehugger Robot {NAN, 0.},
295*7c3d14c8STreehugger Robot {-INFINITY, 0.},
296*7c3d14c8STreehugger Robot {-2, 0.},
297*7c3d14c8STreehugger Robot {-1, 0.},
298*7c3d14c8STreehugger Robot {-0.5, 0.},
299*7c3d14c8STreehugger Robot {-0., 0.},
300*7c3d14c8STreehugger Robot {+0., 0.},
301*7c3d14c8STreehugger Robot {0.5, 0.},
302*7c3d14c8STreehugger Robot {1, 0.},
303*7c3d14c8STreehugger Robot {2, 0.},
304*7c3d14c8STreehugger Robot {INFINITY, 0.},
305*7c3d14c8STreehugger Robot
306*7c3d14c8STreehugger Robot {NAN, 0.5},
307*7c3d14c8STreehugger Robot {-INFINITY, 0.5},
308*7c3d14c8STreehugger Robot {-2, 0.5},
309*7c3d14c8STreehugger Robot {-1, 0.5},
310*7c3d14c8STreehugger Robot {-0.5, 0.5},
311*7c3d14c8STreehugger Robot {-0., 0.5},
312*7c3d14c8STreehugger Robot {+0., 0.5},
313*7c3d14c8STreehugger Robot {0.5, 0.5},
314*7c3d14c8STreehugger Robot {1, 0.5},
315*7c3d14c8STreehugger Robot {2, 0.5},
316*7c3d14c8STreehugger Robot {INFINITY, 0.5},
317*7c3d14c8STreehugger Robot
318*7c3d14c8STreehugger Robot {NAN, 1},
319*7c3d14c8STreehugger Robot {-INFINITY, 1},
320*7c3d14c8STreehugger Robot {-2, 1},
321*7c3d14c8STreehugger Robot {-1, 1},
322*7c3d14c8STreehugger Robot {-0.5, 1},
323*7c3d14c8STreehugger Robot {-0., 1},
324*7c3d14c8STreehugger Robot {+0., 1},
325*7c3d14c8STreehugger Robot {0.5, 1},
326*7c3d14c8STreehugger Robot {1, 1},
327*7c3d14c8STreehugger Robot {2, 1},
328*7c3d14c8STreehugger Robot {INFINITY, 1},
329*7c3d14c8STreehugger Robot
330*7c3d14c8STreehugger Robot {NAN, 2},
331*7c3d14c8STreehugger Robot {-INFINITY, 2},
332*7c3d14c8STreehugger Robot {-2, 2},
333*7c3d14c8STreehugger Robot {-1, 2},
334*7c3d14c8STreehugger Robot {-0.5, 2},
335*7c3d14c8STreehugger Robot {-0., 2},
336*7c3d14c8STreehugger Robot {+0., 2},
337*7c3d14c8STreehugger Robot {0.5, 2},
338*7c3d14c8STreehugger Robot {1, 2},
339*7c3d14c8STreehugger Robot {2, 2},
340*7c3d14c8STreehugger Robot {INFINITY, 2},
341*7c3d14c8STreehugger Robot
342*7c3d14c8STreehugger Robot {NAN, INFINITY},
343*7c3d14c8STreehugger Robot {-INFINITY, INFINITY},
344*7c3d14c8STreehugger Robot {-2, INFINITY},
345*7c3d14c8STreehugger Robot {-1, INFINITY},
346*7c3d14c8STreehugger Robot {-0.5, INFINITY},
347*7c3d14c8STreehugger Robot {-0., INFINITY},
348*7c3d14c8STreehugger Robot {+0., INFINITY},
349*7c3d14c8STreehugger Robot {0.5, INFINITY},
350*7c3d14c8STreehugger Robot {1, INFINITY},
351*7c3d14c8STreehugger Robot {2, INFINITY},
352*7c3d14c8STreehugger Robot {INFINITY, INFINITY}
353*7c3d14c8STreehugger Robot
354*7c3d14c8STreehugger Robot };
355*7c3d14c8STreehugger Robot
356*7c3d14c8STreehugger Robot #endif
357*7c3d14c8STreehugger Robot
main()358*7c3d14c8STreehugger Robot int main()
359*7c3d14c8STreehugger Robot {
360*7c3d14c8STreehugger Robot #if _ARCH_PPC || __aarch64__
361*7c3d14c8STreehugger Robot const unsigned N = sizeof(x) / sizeof(x[0]);
362*7c3d14c8STreehugger Robot unsigned i, j;
363*7c3d14c8STreehugger Robot for (i = 0; i < N; ++i)
364*7c3d14c8STreehugger Robot {
365*7c3d14c8STreehugger Robot for (j = 0; j < N; ++j)
366*7c3d14c8STreehugger Robot {
367*7c3d14c8STreehugger Robot if (test__multc3(x[i][0], x[i][1], x[j][0], x[j][1]))
368*7c3d14c8STreehugger Robot return 1;
369*7c3d14c8STreehugger Robot }
370*7c3d14c8STreehugger Robot }
371*7c3d14c8STreehugger Robot #else
372*7c3d14c8STreehugger Robot printf("skipped\n");
373*7c3d14c8STreehugger Robot #endif
374*7c3d14c8STreehugger Robot return 0;
375*7c3d14c8STreehugger Robot }
376