1*0b57cec5SDimitry Andric //===-- mulsc3.c - Implement __mulsc3 -------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file implements __mulsc3 for the compiler_rt library.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric #include "int_lib.h"
14*0b57cec5SDimitry Andric #include "int_math.h"
15*0b57cec5SDimitry Andric
16*0b57cec5SDimitry Andric // Returns: the product of a + ib and c + id
17*0b57cec5SDimitry Andric
__mulsc3(float __a,float __b,float __c,float __d)18*0b57cec5SDimitry Andric COMPILER_RT_ABI Fcomplex __mulsc3(float __a, float __b, float __c, float __d) {
19*0b57cec5SDimitry Andric float __ac = __a * __c;
20*0b57cec5SDimitry Andric float __bd = __b * __d;
21*0b57cec5SDimitry Andric float __ad = __a * __d;
22*0b57cec5SDimitry Andric float __bc = __b * __c;
23*0b57cec5SDimitry Andric Fcomplex z;
24*0b57cec5SDimitry Andric COMPLEX_REAL(z) = __ac - __bd;
25*0b57cec5SDimitry Andric COMPLEX_IMAGINARY(z) = __ad + __bc;
26*0b57cec5SDimitry Andric if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
27*0b57cec5SDimitry Andric int __recalc = 0;
28*0b57cec5SDimitry Andric if (crt_isinf(__a) || crt_isinf(__b)) {
29*0b57cec5SDimitry Andric __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
30*0b57cec5SDimitry Andric __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
31*0b57cec5SDimitry Andric if (crt_isnan(__c))
32*0b57cec5SDimitry Andric __c = crt_copysignf(0, __c);
33*0b57cec5SDimitry Andric if (crt_isnan(__d))
34*0b57cec5SDimitry Andric __d = crt_copysignf(0, __d);
35*0b57cec5SDimitry Andric __recalc = 1;
36*0b57cec5SDimitry Andric }
37*0b57cec5SDimitry Andric if (crt_isinf(__c) || crt_isinf(__d)) {
38*0b57cec5SDimitry Andric __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
39*0b57cec5SDimitry Andric __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
40*0b57cec5SDimitry Andric if (crt_isnan(__a))
41*0b57cec5SDimitry Andric __a = crt_copysignf(0, __a);
42*0b57cec5SDimitry Andric if (crt_isnan(__b))
43*0b57cec5SDimitry Andric __b = crt_copysignf(0, __b);
44*0b57cec5SDimitry Andric __recalc = 1;
45*0b57cec5SDimitry Andric }
46*0b57cec5SDimitry Andric if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||
47*0b57cec5SDimitry Andric crt_isinf(__bc))) {
48*0b57cec5SDimitry Andric if (crt_isnan(__a))
49*0b57cec5SDimitry Andric __a = crt_copysignf(0, __a);
50*0b57cec5SDimitry Andric if (crt_isnan(__b))
51*0b57cec5SDimitry Andric __b = crt_copysignf(0, __b);
52*0b57cec5SDimitry Andric if (crt_isnan(__c))
53*0b57cec5SDimitry Andric __c = crt_copysignf(0, __c);
54*0b57cec5SDimitry Andric if (crt_isnan(__d))
55*0b57cec5SDimitry Andric __d = crt_copysignf(0, __d);
56*0b57cec5SDimitry Andric __recalc = 1;
57*0b57cec5SDimitry Andric }
58*0b57cec5SDimitry Andric if (__recalc) {
59*0b57cec5SDimitry Andric COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
60*0b57cec5SDimitry Andric COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
61*0b57cec5SDimitry Andric }
62*0b57cec5SDimitry Andric }
63*0b57cec5SDimitry Andric return z;
64*0b57cec5SDimitry Andric }
65