[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / divxc3_test.c
blobd5bb385143f9fdc1b72f007e9881e3106b5eadec
1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_divxc3
3 // REQUIRES: x86-target-arch
4 // UNSUPPORTED: powerpc64
5 //===-- divxc3_test.c - Test __divxc3 -------------------------------------===//
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 __divxc3 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 quotient of (a + ib) / (c + id)
29 COMPILER_RT_ABI long double _Complex
30 __divxc3(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__divxc3(long double a, long double b, long double c, long double d)
60 long double _Complex r = __divxc3(a, b, c, d);
61 // printf("test__divxc3(%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) != NaN)
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) != zero)
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) != inf)
103 return 1;
104 break;
105 case non_zero:
106 if (classify(r) != non_zero)
107 return 1;
109 long double _Complex z = (a * c + b * d) / (c * c + d * d)
110 + (b * c - a * d) / (c * c + d * d) * _Complex_I;
111 if (cabs((r - z)/r) > 1.e-6)
112 return 1;
114 break;
115 case inf:
116 if (classify(r) != zero)
117 return 1;
118 break;
119 case NaN:
120 if (classify(r) != NaN)
121 return 1;
122 break;
123 case non_zero_nan:
124 if (classify(r) != NaN)
125 return 1;
126 break;
128 break;
129 case inf:
130 switch (classify(divisor))
132 case zero:
133 if (classify(r) != inf)
134 return 1;
135 break;
136 case non_zero:
137 if (classify(r) != inf)
138 return 1;
139 break;
140 case inf:
141 if (classify(r) != NaN)
142 return 1;
143 break;
144 case NaN:
145 if (classify(r) != NaN)
146 return 1;
147 break;
148 case non_zero_nan:
149 if (classify(r) != NaN)
150 return 1;
151 break;
153 break;
154 case NaN:
155 switch (classify(divisor))
157 case zero:
158 if (classify(r) != NaN)
159 return 1;
160 break;
161 case non_zero:
162 if (classify(r) != NaN)
163 return 1;
164 break;
165 case inf:
166 if (classify(r) != NaN)
167 return 1;
168 break;
169 case NaN:
170 if (classify(r) != NaN)
171 return 1;
172 break;
173 case non_zero_nan:
174 if (classify(r) != NaN)
175 return 1;
176 break;
178 break;
179 case non_zero_nan:
180 switch (classify(divisor))
182 case zero:
183 if (classify(r) != inf)
184 return 1;
185 break;
186 case non_zero:
187 if (classify(r) != NaN)
188 return 1;
189 break;
190 case inf:
191 if (classify(r) != NaN)
192 return 1;
193 break;
194 case NaN:
195 if (classify(r) != NaN)
196 return 1;
197 break;
198 case non_zero_nan:
199 if (classify(r) != NaN)
200 return 1;
201 break;
203 break;
206 return 0;
209 long double x[][2] =
211 { 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},
216 { 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},
221 { 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},
226 { 1.e+6, 1.e+6},
227 {-1.e+6, 1.e+6},
228 {-1.e+6, -1.e+6},
229 { 1.e+6, -1.e+6},
231 {NAN, NAN},
232 {-INFINITY, NAN},
233 {-2, NAN},
234 {-1, NAN},
235 {-0.5, NAN},
236 {-0., NAN},
237 {+0., NAN},
238 {0.5, NAN},
239 {1, NAN},
240 {2, NAN},
241 {INFINITY, NAN},
243 {NAN, -INFINITY},
244 {-INFINITY, -INFINITY},
245 {-2, -INFINITY},
246 {-1, -INFINITY},
247 {-0.5, -INFINITY},
248 {-0., -INFINITY},
249 {+0., -INFINITY},
250 {0.5, -INFINITY},
251 {1, -INFINITY},
252 {2, -INFINITY},
253 {INFINITY, -INFINITY},
255 {NAN, -2},
256 {-INFINITY, -2},
257 {-2, -2},
258 {-1, -2},
259 {-0.5, -2},
260 {-0., -2},
261 {+0., -2},
262 {0.5, -2},
263 {1, -2},
264 {2, -2},
265 {INFINITY, -2},
267 {NAN, -1},
268 {-INFINITY, -1},
269 {-2, -1},
270 {-1, -1},
271 {-0.5, -1},
272 {-0., -1},
273 {+0., -1},
274 {0.5, -1},
275 {1, -1},
276 {2, -1},
277 {INFINITY, -1},
279 {NAN, -0.5},
280 {-INFINITY, -0.5},
281 {-2, -0.5},
282 {-1, -0.5},
283 {-0.5, -0.5},
284 {-0., -0.5},
285 {+0., -0.5},
286 {0.5, -0.5},
287 {1, -0.5},
288 {2, -0.5},
289 {INFINITY, -0.5},
291 {NAN, -0.},
292 {-INFINITY, -0.},
293 {-2, -0.},
294 {-1, -0.},
295 {-0.5, -0.},
296 {-0., -0.},
297 {+0., -0.},
298 {0.5, -0.},
299 {1, -0.},
300 {2, -0.},
301 {INFINITY, -0.},
303 {NAN, 0.},
304 {-INFINITY, 0.},
305 {-2, 0.},
306 {-1, 0.},
307 {-0.5, 0.},
308 {-0., 0.},
309 {+0., 0.},
310 {0.5, 0.},
311 {1, 0.},
312 {2, 0.},
313 {INFINITY, 0.},
315 {NAN, 0.5},
316 {-INFINITY, 0.5},
317 {-2, 0.5},
318 {-1, 0.5},
319 {-0.5, 0.5},
320 {-0., 0.5},
321 {+0., 0.5},
322 {0.5, 0.5},
323 {1, 0.5},
324 {2, 0.5},
325 {INFINITY, 0.5},
327 {NAN, 1},
328 {-INFINITY, 1},
329 {-2, 1},
330 {-1, 1},
331 {-0.5, 1},
332 {-0., 1},
333 {+0., 1},
334 {0.5, 1},
335 {1, 1},
336 {2, 1},
337 {INFINITY, 1},
339 {NAN, 2},
340 {-INFINITY, 2},
341 {-2, 2},
342 {-1, 2},
343 {-0.5, 2},
344 {-0., 2},
345 {+0., 2},
346 {0.5, 2},
347 {1, 2},
348 {2, 2},
349 {INFINITY, 2},
351 {NAN, INFINITY},
352 {-INFINITY, INFINITY},
353 {-2, INFINITY},
354 {-1, INFINITY},
355 {-0.5, INFINITY},
356 {-0., INFINITY},
357 {+0., INFINITY},
358 {0.5, INFINITY},
359 {1, INFINITY},
360 {2, INFINITY},
361 {INFINITY, INFINITY}
365 #endif
367 int main()
369 #if !_ARCH_PPC
370 const unsigned N = sizeof(x) / sizeof(x[0]);
371 unsigned i, j;
372 for (i = 0; i < N; ++i)
374 for (j = 0; j < N; ++j)
376 if (test__divxc3(x[i][0], x[i][1], x[j][0], x[j][1]))
377 return 1;
381 #else
382 printf("skipped\n");
383 #endif
384 return 0;