1 1.1 joerg /* ===-- multc3.c - Implement __multc3 -------------------------------------=== 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 __multc3 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 joerg COMPILER_RT_ABI long double _Complex 21 1.1 joerg __multc3(long double a, long double b, long double c, long double d) 22 1.1 joerg { 23 1.1 joerg long double ac = a * c; 24 1.1 joerg long double bd = b * d; 25 1.1 joerg long double ad = a * d; 26 1.1 joerg long double bc = b * c; 27 1.1 joerg long double _Complex z; 28 1.1 joerg __real__ z = ac - bd; 29 1.1 joerg __imag__ z = ad + bc; 30 1.1 joerg if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { 31 1.1 joerg int recalc = 0; 32 1.1 joerg if (crt_isinf(a) || crt_isinf(b)) { 33 1.1 joerg a = crt_copysignl(crt_isinf(a) ? 1 : 0, a); 34 1.1 joerg b = crt_copysignl(crt_isinf(b) ? 1 : 0, b); 35 1.1 joerg if (crt_isnan(c)) 36 1.1 joerg c = crt_copysignl(0, c); 37 1.1 joerg if (crt_isnan(d)) 38 1.1 joerg d = crt_copysignl(0, d); 39 1.1 joerg recalc = 1; 40 1.1 joerg } 41 1.1 joerg if (crt_isinf(c) || crt_isinf(d)) { 42 1.1 joerg c = crt_copysignl(crt_isinf(c) ? 1 : 0, c); 43 1.1 joerg d = crt_copysignl(crt_isinf(d) ? 1 : 0, d); 44 1.1 joerg if (crt_isnan(a)) 45 1.1 joerg a = crt_copysignl(0, a); 46 1.1 joerg if (crt_isnan(b)) 47 1.1 joerg b = crt_copysignl(0, b); 48 1.1 joerg recalc = 1; 49 1.1 joerg } 50 1.1 joerg if (!recalc && (crt_isinf(ac) || crt_isinf(bd) || 51 1.1 joerg crt_isinf(ad) || crt_isinf(bc))) { 52 1.1 joerg if (crt_isnan(a)) 53 1.1 joerg a = crt_copysignl(0, a); 54 1.1 joerg if (crt_isnan(b)) 55 1.1 joerg b = crt_copysignl(0, b); 56 1.1 joerg if (crt_isnan(c)) 57 1.1 joerg c = crt_copysignl(0, c); 58 1.1 joerg if (crt_isnan(d)) 59 1.1 joerg d = crt_copysignl(0, d); 60 1.1 joerg recalc = 1; 61 1.1 joerg } 62 1.1 joerg if (recalc) { 63 1.1 joerg __real__ z = CRT_INFINITY * (a * c - b * d); 64 1.1 joerg __imag__ z = CRT_INFINITY * (a * d + b * c); 65 1.1 joerg } 66 1.1 joerg } 67 1.1 joerg return z; 68 1.1 joerg } 69