mulxc3.c 2.4 KB

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