1*7c3d14c8STreehugger Robot /* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
2*7c3d14c8STreehugger Robot *
3*7c3d14c8STreehugger Robot * The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot *
5*7c3d14c8STreehugger Robot * This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot * Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot *
8*7c3d14c8STreehugger Robot * ===----------------------------------------------------------------------===
9*7c3d14c8STreehugger Robot *
10*7c3d14c8STreehugger Robot * This file implements __mulsc3 for the compiler_rt library.
11*7c3d14c8STreehugger Robot *
12*7c3d14c8STreehugger Robot * ===----------------------------------------------------------------------===
13*7c3d14c8STreehugger Robot */
14*7c3d14c8STreehugger Robot
15*7c3d14c8STreehugger Robot #include "int_lib.h"
16*7c3d14c8STreehugger Robot #include "int_math.h"
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot /* Returns: the product of a + ib and c + id */
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot COMPILER_RT_ABI Fcomplex
__mulsc3(float __a,float __b,float __c,float __d)21*7c3d14c8STreehugger Robot __mulsc3(float __a, float __b, float __c, float __d)
22*7c3d14c8STreehugger Robot {
23*7c3d14c8STreehugger Robot float __ac = __a * __c;
24*7c3d14c8STreehugger Robot float __bd = __b * __d;
25*7c3d14c8STreehugger Robot float __ad = __a * __d;
26*7c3d14c8STreehugger Robot float __bc = __b * __c;
27*7c3d14c8STreehugger Robot Fcomplex z;
28*7c3d14c8STreehugger Robot COMPLEX_REAL(z) = __ac - __bd;
29*7c3d14c8STreehugger Robot COMPLEX_IMAGINARY(z) = __ad + __bc;
30*7c3d14c8STreehugger Robot if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
31*7c3d14c8STreehugger Robot {
32*7c3d14c8STreehugger Robot int __recalc = 0;
33*7c3d14c8STreehugger Robot if (crt_isinf(__a) || crt_isinf(__b))
34*7c3d14c8STreehugger Robot {
35*7c3d14c8STreehugger Robot __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
36*7c3d14c8STreehugger Robot __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
37*7c3d14c8STreehugger Robot if (crt_isnan(__c))
38*7c3d14c8STreehugger Robot __c = crt_copysignf(0, __c);
39*7c3d14c8STreehugger Robot if (crt_isnan(__d))
40*7c3d14c8STreehugger Robot __d = crt_copysignf(0, __d);
41*7c3d14c8STreehugger Robot __recalc = 1;
42*7c3d14c8STreehugger Robot }
43*7c3d14c8STreehugger Robot if (crt_isinf(__c) || crt_isinf(__d))
44*7c3d14c8STreehugger Robot {
45*7c3d14c8STreehugger Robot __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
46*7c3d14c8STreehugger Robot __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
47*7c3d14c8STreehugger Robot if (crt_isnan(__a))
48*7c3d14c8STreehugger Robot __a = crt_copysignf(0, __a);
49*7c3d14c8STreehugger Robot if (crt_isnan(__b))
50*7c3d14c8STreehugger Robot __b = crt_copysignf(0, __b);
51*7c3d14c8STreehugger Robot __recalc = 1;
52*7c3d14c8STreehugger Robot }
53*7c3d14c8STreehugger Robot if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
54*7c3d14c8STreehugger Robot crt_isinf(__ad) || crt_isinf(__bc)))
55*7c3d14c8STreehugger Robot {
56*7c3d14c8STreehugger Robot if (crt_isnan(__a))
57*7c3d14c8STreehugger Robot __a = crt_copysignf(0, __a);
58*7c3d14c8STreehugger Robot if (crt_isnan(__b))
59*7c3d14c8STreehugger Robot __b = crt_copysignf(0, __b);
60*7c3d14c8STreehugger Robot if (crt_isnan(__c))
61*7c3d14c8STreehugger Robot __c = crt_copysignf(0, __c);
62*7c3d14c8STreehugger Robot if (crt_isnan(__d))
63*7c3d14c8STreehugger Robot __d = crt_copysignf(0, __d);
64*7c3d14c8STreehugger Robot __recalc = 1;
65*7c3d14c8STreehugger Robot }
66*7c3d14c8STreehugger Robot if (__recalc)
67*7c3d14c8STreehugger Robot {
68*7c3d14c8STreehugger Robot COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
69*7c3d14c8STreehugger Robot COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
70*7c3d14c8STreehugger Robot }
71*7c3d14c8STreehugger Robot }
72*7c3d14c8STreehugger Robot return z;
73*7c3d14c8STreehugger Robot }
74