blob: 161fd0ce0dd4b60fa02f2b752ff77591c5e5755f [file] [log] [blame]
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00001/* ===-- mulxc3.c - Implement __mulxc3 -------------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __mulxc3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#if !_ARCH_PPC
16
17#include "int_lib.h"
Daniel Dunbar86030242011-11-16 07:33:00 +000018#include "int_math.h"
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000020/* Returns: the product of a + ib and c + id */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
Joerg Sonnenbergerbfbb8bb2014-03-01 15:30:50 +000022COMPILER_RT_ABI long double _Complex
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023__mulxc3(long double __a, long double __b, long double __c, long double __d)
24{
25 long double __ac = __a * __c;
26 long double __bd = __b * __d;
27 long double __ad = __a * __d;
28 long double __bc = __b * __c;
29 long double _Complex z;
30 __real__ z = __ac - __bd;
31 __imag__ z = __ad + __bc;
Daniel Dunbar86030242011-11-16 07:33:00 +000032 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000033 {
34 int __recalc = 0;
Daniel Dunbar86030242011-11-16 07:33:00 +000035 if (crt_isinf(__a) || crt_isinf(__b))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000036 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000037 __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);
38 __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);
Daniel Dunbar86030242011-11-16 07:33:00 +000039 if (crt_isnan(__c))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000040 __c = crt_copysignl(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000041 if (crt_isnan(__d))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000042 __d = crt_copysignl(0, __d);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000043 __recalc = 1;
44 }
Daniel Dunbar86030242011-11-16 07:33:00 +000045 if (crt_isinf(__c) || crt_isinf(__d))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000046 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000047 __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);
48 __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);
Daniel Dunbar86030242011-11-16 07:33:00 +000049 if (crt_isnan(__a))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000050 __a = crt_copysignl(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000051 if (crt_isnan(__b))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000052 __b = crt_copysignl(0, __b);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000053 __recalc = 1;
54 }
Daniel Dunbar86030242011-11-16 07:33:00 +000055 if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
56 crt_isinf(__ad) || crt_isinf(__bc)))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000057 {
Daniel Dunbar86030242011-11-16 07:33:00 +000058 if (crt_isnan(__a))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000059 __a = crt_copysignl(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000060 if (crt_isnan(__b))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000061 __b = crt_copysignl(0, __b);
Daniel Dunbar86030242011-11-16 07:33:00 +000062 if (crt_isnan(__c))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000063 __c = crt_copysignl(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000064 if (crt_isnan(__d))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000065 __d = crt_copysignl(0, __d);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000066 __recalc = 1;
67 }
68 if (__recalc)
69 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000070 __real__ z = CRT_INFINITY * (__a * __c - __b * __d);
71 __imag__ z = CRT_INFINITY * (__a * __d + __b * __c);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000072 }
73 }
74 return z;
75}
76
77#endif