1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_multc3
3 //===-- multc3_test.c - Test __multc3 -------------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __multc3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
17 #if _ARCH_PPC || __aarch64__
23 // Returns: the product of a + ib and c + id
25 COMPILER_RT_ABI
long double _Complex
26 __multc3(long double __a
, long double __b
, long double __c
, long double __d
);
28 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
31 classify(long double _Complex x
)
35 if (isinf(creall(x
)) || isinf(cimagl(x
)))
37 if (isnan(creall(x
)) && isnan(cimagl(x
)))
54 int test__multc3(long double a
, long double b
, long double c
, long double d
)
56 long double _Complex r
= __multc3(a
, b
, c
, d
);
57 // printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
58 // a, b, c, d, creall(r), cimagl(r));
59 long double _Complex dividend
;
60 long double _Complex divisor
;
62 __real__ dividend
= a
;
63 __imag__ dividend
= b
;
67 switch (classify(dividend
))
70 switch (classify(divisor
))
73 if (classify(r
) != zero
)
77 if (classify(r
) != zero
)
81 if (classify(r
) != NaN
)
85 if (classify(r
) != NaN
)
89 if (classify(r
) != NaN
)
95 switch (classify(divisor
))
98 if (classify(r
) != zero
)
102 if (classify(r
) != non_zero
)
104 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
108 if (classify(r
) != inf
)
112 if (classify(r
) != NaN
)
116 if (classify(r
) != NaN
)
122 switch (classify(divisor
))
125 if (classify(r
) != NaN
)
129 if (classify(r
) != inf
)
133 if (classify(r
) != inf
)
137 if (classify(r
) != NaN
)
141 if (classify(r
) != inf
)
147 switch (classify(divisor
))
150 if (classify(r
) != NaN
)
154 if (classify(r
) != NaN
)
158 if (classify(r
) != NaN
)
162 if (classify(r
) != NaN
)
166 if (classify(r
) != NaN
)
172 switch (classify(divisor
))
175 if (classify(r
) != NaN
)
179 if (classify(r
) != NaN
)
183 if (classify(r
) != inf
)
187 if (classify(r
) != NaN
)
191 if (classify(r
) != NaN
)
236 {-INFINITY
, -INFINITY
},
245 {INFINITY
, -INFINITY
},
344 {-INFINITY
, INFINITY
},
361 #if _ARCH_PPC || __aarch64__
362 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
364 for (i
= 0; i
< N
; ++i
)
366 for (j
= 0; j
< N
; ++j
)
368 if (test__multc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))