1 // XFAIL: target=aarch64-{{.*}}-windows-{{.*}}
2 // RUN: %clang_builtins %s %librt -o %t && %run %t
3 // REQUIRES: librt_has_multc3
7 #if _ARCH_PPC || __aarch64__
13 // Returns: the product of a + ib and c + id
15 COMPILER_RT_ABI
long double _Complex
16 __multc3(long double __a
, long double __b
, long double __c
, long double __d
);
18 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
21 classify(long double _Complex x
)
25 if (isinf(creall(x
)) || isinf(cimagl(x
)))
27 if (isnan(creall(x
)) && isnan(cimagl(x
)))
44 int test__multc3(long double a
, long double b
, long double c
, long double d
)
46 long double _Complex r
= __multc3(a
, b
, c
, d
);
47 // printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
48 // a, b, c, d, creall(r), cimagl(r));
49 long double _Complex dividend
;
50 long double _Complex divisor
;
52 __real__ dividend
= a
;
53 __imag__ dividend
= b
;
57 switch (classify(dividend
))
60 switch (classify(divisor
))
63 if (classify(r
) != zero
)
67 if (classify(r
) != zero
)
71 if (classify(r
) != NaN
)
75 if (classify(r
) != NaN
)
79 if (classify(r
) != NaN
)
85 switch (classify(divisor
))
88 if (classify(r
) != zero
)
92 if (classify(r
) != non_zero
)
94 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
98 if (classify(r
) != inf
)
102 if (classify(r
) != NaN
)
106 if (classify(r
) != NaN
)
112 switch (classify(divisor
))
115 if (classify(r
) != NaN
)
119 if (classify(r
) != inf
)
123 if (classify(r
) != inf
)
127 if (classify(r
) != NaN
)
131 if (classify(r
) != inf
)
137 switch (classify(divisor
))
140 if (classify(r
) != NaN
)
144 if (classify(r
) != NaN
)
148 if (classify(r
) != NaN
)
152 if (classify(r
) != NaN
)
156 if (classify(r
) != NaN
)
162 switch (classify(divisor
))
165 if (classify(r
) != NaN
)
169 if (classify(r
) != NaN
)
173 if (classify(r
) != inf
)
177 if (classify(r
) != NaN
)
181 if (classify(r
) != NaN
)
226 {-INFINITY
, -INFINITY
},
235 {INFINITY
, -INFINITY
},
334 {-INFINITY
, INFINITY
},
351 #if _ARCH_PPC || __aarch64__
352 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
354 for (i
= 0; i
< N
; ++i
)
356 for (j
= 0; j
< N
; ++j
)
358 if (test__multc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))