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