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