[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / mulxc3_test.c
blob5937b6c85e0392a90cf2800f961944cac314b707
1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_mulxc3
3 // UNSUPPORTED: powerpc64
4 // REQUIRES: x86-target-arch
5 //===-- mulxc3_test.c - Test __mulxc3 -------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 // This file tests __mulxc3 for the compiler_rt library.
15 //===----------------------------------------------------------------------===//
17 #if !_ARCH_PPC
19 #include "int_lib.h"
20 #include <math.h>
21 #include <complex.h>
22 #include <stdio.h>
24 // UNSUPPORTED: mips
25 // REQUIRES: c99-complex
27 // Returns: the product of a + ib and c + id
29 COMPILER_RT_ABI long double _Complex
30 __mulxc3(long double __a, long double __b, long double __c, long double __d);
32 enum {zero, non_zero, inf, NaN, non_zero_nan};
34 int
35 classify(long double _Complex x)
37 if (x == 0)
38 return zero;
39 if (isinf(creall(x)) || isinf(cimagl(x)))
40 return inf;
41 if (isnan(creall(x)) && isnan(cimagl(x)))
42 return NaN;
43 if (isnan(creall(x)))
45 if (cimagl(x) == 0)
46 return NaN;
47 return non_zero_nan;
49 if (isnan(cimagl(x)))
51 if (creall(x) == 0)
52 return NaN;
53 return non_zero_nan;
55 return non_zero;
58 int test__mulxc3(long double a, long double b, long double c, long double d)
60 long double _Complex r = __mulxc3(a, b, c, d);
61 // printf("test__mulxc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
62 // a, b, c, d, creall(r), cimagl(r));
63 long double _Complex dividend;
64 long double _Complex divisor;
66 __real__ dividend = a;
67 __imag__ dividend = b;
68 __real__ divisor = c;
69 __imag__ divisor = d;
71 switch (classify(dividend))
73 case zero:
74 switch (classify(divisor))
76 case zero:
77 if (classify(r) != zero)
78 return 1;
79 break;
80 case non_zero:
81 if (classify(r) != zero)
82 return 1;
83 break;
84 case inf:
85 if (classify(r) != NaN)
86 return 1;
87 break;
88 case NaN:
89 if (classify(r) != NaN)
90 return 1;
91 break;
92 case non_zero_nan:
93 if (classify(r) != NaN)
94 return 1;
95 break;
97 break;
98 case non_zero:
99 switch (classify(divisor))
101 case zero:
102 if (classify(r) != zero)
103 return 1;
104 break;
105 case non_zero:
106 if (classify(r) != non_zero)
107 return 1;
108 if (r != a * c - b * d + _Complex_I*(a * d + b * c))
109 return 1;
110 break;
111 case inf:
112 if (classify(r) != inf)
113 return 1;
114 break;
115 case NaN:
116 if (classify(r) != NaN)
117 return 1;
118 break;
119 case non_zero_nan:
120 if (classify(r) != NaN)
121 return 1;
122 break;
124 break;
125 case inf:
126 switch (classify(divisor))
128 case zero:
129 if (classify(r) != NaN)
130 return 1;
131 break;
132 case non_zero:
133 if (classify(r) != inf)
134 return 1;
135 break;
136 case inf:
137 if (classify(r) != inf)
138 return 1;
139 break;
140 case NaN:
141 if (classify(r) != NaN)
142 return 1;
143 break;
144 case non_zero_nan:
145 if (classify(r) != inf)
146 return 1;
147 break;
149 break;
150 case NaN:
151 switch (classify(divisor))
153 case zero:
154 if (classify(r) != NaN)
155 return 1;
156 break;
157 case non_zero:
158 if (classify(r) != NaN)
159 return 1;
160 break;
161 case inf:
162 if (classify(r) != NaN)
163 return 1;
164 break;
165 case NaN:
166 if (classify(r) != NaN)
167 return 1;
168 break;
169 case non_zero_nan:
170 if (classify(r) != NaN)
171 return 1;
172 break;
174 break;
175 case non_zero_nan:
176 switch (classify(divisor))
178 case zero:
179 if (classify(r) != NaN)
180 return 1;
181 break;
182 case non_zero:
183 if (classify(r) != NaN)
184 return 1;
185 break;
186 case inf:
187 if (classify(r) != inf)
188 return 1;
189 break;
190 case NaN:
191 if (classify(r) != NaN)
192 return 1;
193 break;
194 case non_zero_nan:
195 if (classify(r) != NaN)
196 return 1;
197 break;
199 break;
202 return 0;
205 long double x[][2] =
207 { 1.e-6, 1.e-6},
208 {-1.e-6, 1.e-6},
209 {-1.e-6, -1.e-6},
210 { 1.e-6, -1.e-6},
212 { 1.e+6, 1.e-6},
213 {-1.e+6, 1.e-6},
214 {-1.e+6, -1.e-6},
215 { 1.e+6, -1.e-6},
217 { 1.e-6, 1.e+6},
218 {-1.e-6, 1.e+6},
219 {-1.e-6, -1.e+6},
220 { 1.e-6, -1.e+6},
222 { 1.e+6, 1.e+6},
223 {-1.e+6, 1.e+6},
224 {-1.e+6, -1.e+6},
225 { 1.e+6, -1.e+6},
227 {NAN, NAN},
228 {-INFINITY, NAN},
229 {-2, NAN},
230 {-1, NAN},
231 {-0.5, NAN},
232 {-0., NAN},
233 {+0., NAN},
234 {0.5, NAN},
235 {1, NAN},
236 {2, NAN},
237 {INFINITY, NAN},
239 {NAN, -INFINITY},
240 {-INFINITY, -INFINITY},
241 {-2, -INFINITY},
242 {-1, -INFINITY},
243 {-0.5, -INFINITY},
244 {-0., -INFINITY},
245 {+0., -INFINITY},
246 {0.5, -INFINITY},
247 {1, -INFINITY},
248 {2, -INFINITY},
249 {INFINITY, -INFINITY},
251 {NAN, -2},
252 {-INFINITY, -2},
253 {-2, -2},
254 {-1, -2},
255 {-0.5, -2},
256 {-0., -2},
257 {+0., -2},
258 {0.5, -2},
259 {1, -2},
260 {2, -2},
261 {INFINITY, -2},
263 {NAN, -1},
264 {-INFINITY, -1},
265 {-2, -1},
266 {-1, -1},
267 {-0.5, -1},
268 {-0., -1},
269 {+0., -1},
270 {0.5, -1},
271 {1, -1},
272 {2, -1},
273 {INFINITY, -1},
275 {NAN, -0.5},
276 {-INFINITY, -0.5},
277 {-2, -0.5},
278 {-1, -0.5},
279 {-0.5, -0.5},
280 {-0., -0.5},
281 {+0., -0.5},
282 {0.5, -0.5},
283 {1, -0.5},
284 {2, -0.5},
285 {INFINITY, -0.5},
287 {NAN, -0.},
288 {-INFINITY, -0.},
289 {-2, -0.},
290 {-1, -0.},
291 {-0.5, -0.},
292 {-0., -0.},
293 {+0., -0.},
294 {0.5, -0.},
295 {1, -0.},
296 {2, -0.},
297 {INFINITY, -0.},
299 {NAN, 0.},
300 {-INFINITY, 0.},
301 {-2, 0.},
302 {-1, 0.},
303 {-0.5, 0.},
304 {-0., 0.},
305 {+0., 0.},
306 {0.5, 0.},
307 {1, 0.},
308 {2, 0.},
309 {INFINITY, 0.},
311 {NAN, 0.5},
312 {-INFINITY, 0.5},
313 {-2, 0.5},
314 {-1, 0.5},
315 {-0.5, 0.5},
316 {-0., 0.5},
317 {+0., 0.5},
318 {0.5, 0.5},
319 {1, 0.5},
320 {2, 0.5},
321 {INFINITY, 0.5},
323 {NAN, 1},
324 {-INFINITY, 1},
325 {-2, 1},
326 {-1, 1},
327 {-0.5, 1},
328 {-0., 1},
329 {+0., 1},
330 {0.5, 1},
331 {1, 1},
332 {2, 1},
333 {INFINITY, 1},
335 {NAN, 2},
336 {-INFINITY, 2},
337 {-2, 2},
338 {-1, 2},
339 {-0.5, 2},
340 {-0., 2},
341 {+0., 2},
342 {0.5, 2},
343 {1, 2},
344 {2, 2},
345 {INFINITY, 2},
347 {NAN, INFINITY},
348 {-INFINITY, INFINITY},
349 {-2, INFINITY},
350 {-1, INFINITY},
351 {-0.5, INFINITY},
352 {-0., INFINITY},
353 {+0., INFINITY},
354 {0.5, INFINITY},
355 {1, INFINITY},
356 {2, INFINITY},
357 {INFINITY, INFINITY}
361 #endif
363 int main()
365 #if !_ARCH_PPC
366 const unsigned N = sizeof(x) / sizeof(x[0]);
367 unsigned i, j;
368 for (i = 0; i < N; ++i)
370 for (j = 0; j < N; ++j)
372 if (test__mulxc3(x[i][0], x[i][1], x[j][0], x[j][1]))
373 return 1;
377 #else
378 printf("skipped\n");
379 #endif
380 return 0;