1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_mulxc3
3 // UNSUPPORTED: target=powerpc64{{.*}}
4 // REQUIRES: x86-target-arch
5 // UNSUPPORTED: target=mips{{.*}}
6 // REQUIRES: c99-complex
16 // Returns: the product of a + ib and c + id
18 COMPILER_RT_ABI
long double _Complex
19 __mulxc3(long double __a
, long double __b
, long double __c
, long double __d
);
21 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
24 classify(long double _Complex x
)
28 if (isinf(creall(x
)) || isinf(cimagl(x
)))
30 if (isnan(creall(x
)) && isnan(cimagl(x
)))
47 int test__mulxc3(long double a
, long double b
, long double c
, long double d
)
49 long double _Complex r
= __mulxc3(a
, b
, c
, d
);
50 // printf("test__mulxc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
51 // a, b, c, d, creall(r), cimagl(r));
52 long double _Complex dividend
;
53 long double _Complex divisor
;
55 __real__ dividend
= a
;
56 __imag__ dividend
= b
;
60 switch (classify(dividend
))
63 switch (classify(divisor
))
66 if (classify(r
) != zero
)
70 if (classify(r
) != zero
)
74 if (classify(r
) != NaN
)
78 if (classify(r
) != NaN
)
82 if (classify(r
) != NaN
)
88 switch (classify(divisor
))
91 if (classify(r
) != zero
)
95 if (classify(r
) != non_zero
)
97 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
101 if (classify(r
) != inf
)
105 if (classify(r
) != NaN
)
109 if (classify(r
) != NaN
)
115 switch (classify(divisor
))
118 if (classify(r
) != NaN
)
122 if (classify(r
) != inf
)
126 if (classify(r
) != inf
)
130 if (classify(r
) != NaN
)
134 if (classify(r
) != inf
)
140 switch (classify(divisor
))
143 if (classify(r
) != NaN
)
147 if (classify(r
) != NaN
)
151 if (classify(r
) != NaN
)
155 if (classify(r
) != NaN
)
159 if (classify(r
) != NaN
)
165 switch (classify(divisor
))
168 if (classify(r
) != NaN
)
172 if (classify(r
) != NaN
)
176 if (classify(r
) != inf
)
180 if (classify(r
) != NaN
)
184 if (classify(r
) != NaN
)
229 {-INFINITY
, -INFINITY
},
238 {INFINITY
, -INFINITY
},
337 {-INFINITY
, INFINITY
},
355 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
357 for (i
= 0; i
< N
; ++i
)
359 for (j
= 0; j
< N
; ++j
)
361 if (test__mulxc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))