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 -------------------------------------===//
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 //===----------------------------------------------------------------------===//
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
};
35 classify(long double _Complex x
)
39 if (isinf(creall(x
)) || isinf(cimagl(x
)))
41 if (isnan(creall(x
)) && isnan(cimagl(x
)))
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
;
71 switch (classify(dividend
))
74 switch (classify(divisor
))
77 if (classify(r
) != zero
)
81 if (classify(r
) != zero
)
85 if (classify(r
) != NaN
)
89 if (classify(r
) != NaN
)
93 if (classify(r
) != NaN
)
99 switch (classify(divisor
))
102 if (classify(r
) != zero
)
106 if (classify(r
) != non_zero
)
108 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
112 if (classify(r
) != inf
)
116 if (classify(r
) != NaN
)
120 if (classify(r
) != NaN
)
126 switch (classify(divisor
))
129 if (classify(r
) != NaN
)
133 if (classify(r
) != inf
)
137 if (classify(r
) != inf
)
141 if (classify(r
) != NaN
)
145 if (classify(r
) != inf
)
151 switch (classify(divisor
))
154 if (classify(r
) != NaN
)
158 if (classify(r
) != NaN
)
162 if (classify(r
) != NaN
)
166 if (classify(r
) != NaN
)
170 if (classify(r
) != NaN
)
176 switch (classify(divisor
))
179 if (classify(r
) != NaN
)
183 if (classify(r
) != NaN
)
187 if (classify(r
) != inf
)
191 if (classify(r
) != NaN
)
195 if (classify(r
) != NaN
)
240 {-INFINITY
, -INFINITY
},
249 {INFINITY
, -INFINITY
},
348 {-INFINITY
, INFINITY
},
366 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
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]))