1 //===-- mulsc3.c - Implement __mulsc3 -------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements __mulsc3 for the compiler_rt library.
11 //===----------------------------------------------------------------------===//
16 // Returns: the product of a + ib and c + id
18 COMPILER_RT_ABI Fcomplex
__mulsc3(float __a
, float __b
, float __c
, float __d
) {
19 float __ac
= __a
* __c
;
20 float __bd
= __b
* __d
;
21 float __ad
= __a
* __d
;
22 float __bc
= __b
* __c
;
24 COMPLEX_REAL(z
) = __ac
- __bd
;
25 COMPLEX_IMAGINARY(z
) = __ad
+ __bc
;
26 if (crt_isnan(COMPLEX_REAL(z
)) && crt_isnan(COMPLEX_IMAGINARY(z
))) {
28 if (crt_isinf(__a
) || crt_isinf(__b
)) {
29 __a
= crt_copysignf(crt_isinf(__a
) ? 1 : 0, __a
);
30 __b
= crt_copysignf(crt_isinf(__b
) ? 1 : 0, __b
);
32 __c
= crt_copysignf(0, __c
);
34 __d
= crt_copysignf(0, __d
);
37 if (crt_isinf(__c
) || crt_isinf(__d
)) {
38 __c
= crt_copysignf(crt_isinf(__c
) ? 1 : 0, __c
);
39 __d
= crt_copysignf(crt_isinf(__d
) ? 1 : 0, __d
);
41 __a
= crt_copysignf(0, __a
);
43 __b
= crt_copysignf(0, __b
);
46 if (!__recalc
&& (crt_isinf(__ac
) || crt_isinf(__bd
) || crt_isinf(__ad
) ||
49 __a
= crt_copysignf(0, __a
);
51 __b
= crt_copysignf(0, __b
);
53 __c
= crt_copysignf(0, __c
);
55 __d
= crt_copysignf(0, __d
);
59 COMPLEX_REAL(z
) = CRT_INFINITY
* (__a
* __c
- __b
* __d
);
60 COMPLEX_IMAGINARY(z
) = CRT_INFINITY
* (__a
* __d
+ __b
* __c
);