1*7c3d14c8STreehugger Robot /* ===-- mulxc3.c - Implement __mulxc3 -------------------------------------===
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 __mulxc3 for the compiler_rt library.
11*7c3d14c8STreehugger Robot *
12*7c3d14c8STreehugger Robot * ===----------------------------------------------------------------------===
13*7c3d14c8STreehugger Robot */
14*7c3d14c8STreehugger Robot
15*7c3d14c8STreehugger Robot #if !_ARCH_PPC
16*7c3d14c8STreehugger Robot
17*7c3d14c8STreehugger Robot #include "int_lib.h"
18*7c3d14c8STreehugger Robot #include "int_math.h"
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot /* Returns: the product of a + ib and c + id */
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger Robot COMPILER_RT_ABI Lcomplex
__mulxc3(long double __a,long double __b,long double __c,long double __d)23*7c3d14c8STreehugger Robot __mulxc3(long double __a, long double __b, long double __c, long double __d)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot long double __ac = __a * __c;
26*7c3d14c8STreehugger Robot long double __bd = __b * __d;
27*7c3d14c8STreehugger Robot long double __ad = __a * __d;
28*7c3d14c8STreehugger Robot long double __bc = __b * __c;
29*7c3d14c8STreehugger Robot Lcomplex z;
30*7c3d14c8STreehugger Robot COMPLEX_REAL(z) = __ac - __bd;
31*7c3d14c8STreehugger Robot COMPLEX_IMAGINARY(z) = __ad + __bc;
32*7c3d14c8STreehugger Robot if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
33*7c3d14c8STreehugger Robot {
34*7c3d14c8STreehugger Robot int __recalc = 0;
35*7c3d14c8STreehugger Robot if (crt_isinf(__a) || crt_isinf(__b))
36*7c3d14c8STreehugger Robot {
37*7c3d14c8STreehugger Robot __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);
38*7c3d14c8STreehugger Robot __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);
39*7c3d14c8STreehugger Robot if (crt_isnan(__c))
40*7c3d14c8STreehugger Robot __c = crt_copysignl(0, __c);
41*7c3d14c8STreehugger Robot if (crt_isnan(__d))
42*7c3d14c8STreehugger Robot __d = crt_copysignl(0, __d);
43*7c3d14c8STreehugger Robot __recalc = 1;
44*7c3d14c8STreehugger Robot }
45*7c3d14c8STreehugger Robot if (crt_isinf(__c) || crt_isinf(__d))
46*7c3d14c8STreehugger Robot {
47*7c3d14c8STreehugger Robot __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);
48*7c3d14c8STreehugger Robot __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);
49*7c3d14c8STreehugger Robot if (crt_isnan(__a))
50*7c3d14c8STreehugger Robot __a = crt_copysignl(0, __a);
51*7c3d14c8STreehugger Robot if (crt_isnan(__b))
52*7c3d14c8STreehugger Robot __b = crt_copysignl(0, __b);
53*7c3d14c8STreehugger Robot __recalc = 1;
54*7c3d14c8STreehugger Robot }
55*7c3d14c8STreehugger Robot if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
56*7c3d14c8STreehugger Robot crt_isinf(__ad) || crt_isinf(__bc)))
57*7c3d14c8STreehugger Robot {
58*7c3d14c8STreehugger Robot if (crt_isnan(__a))
59*7c3d14c8STreehugger Robot __a = crt_copysignl(0, __a);
60*7c3d14c8STreehugger Robot if (crt_isnan(__b))
61*7c3d14c8STreehugger Robot __b = crt_copysignl(0, __b);
62*7c3d14c8STreehugger Robot if (crt_isnan(__c))
63*7c3d14c8STreehugger Robot __c = crt_copysignl(0, __c);
64*7c3d14c8STreehugger Robot if (crt_isnan(__d))
65*7c3d14c8STreehugger Robot __d = crt_copysignl(0, __d);
66*7c3d14c8STreehugger Robot __recalc = 1;
67*7c3d14c8STreehugger Robot }
68*7c3d14c8STreehugger Robot if (__recalc)
69*7c3d14c8STreehugger Robot {
70*7c3d14c8STreehugger Robot COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
71*7c3d14c8STreehugger Robot COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
72*7c3d14c8STreehugger Robot }
73*7c3d14c8STreehugger Robot }
74*7c3d14c8STreehugger Robot return z;
75*7c3d14c8STreehugger Robot }
76*7c3d14c8STreehugger Robot
77*7c3d14c8STreehugger Robot #endif
78