mulxc3.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===-- mulxc3.c - Implement __mulxc3 -------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements __mulxc3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #if !_ARCH_PPC
  13. #include "int_lib.h"
  14. #include "int_math.h"
  15. // Returns: the product of a + ib and c + id
  16. COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,
  17. xf_float __d) {
  18. xf_float __ac = __a * __c;
  19. xf_float __bd = __b * __d;
  20. xf_float __ad = __a * __d;
  21. xf_float __bc = __b * __c;
  22. Lcomplex z;
  23. COMPLEX_REAL(z) = __ac - __bd;
  24. COMPLEX_IMAGINARY(z) = __ad + __bc;
  25. if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
  26. int __recalc = 0;
  27. if (crt_isinf(__a) || crt_isinf(__b)) {
  28. __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);
  29. __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);
  30. if (crt_isnan(__c))
  31. __c = crt_copysignl(0, __c);
  32. if (crt_isnan(__d))
  33. __d = crt_copysignl(0, __d);
  34. __recalc = 1;
  35. }
  36. if (crt_isinf(__c) || crt_isinf(__d)) {
  37. __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);
  38. __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);
  39. if (crt_isnan(__a))
  40. __a = crt_copysignl(0, __a);
  41. if (crt_isnan(__b))
  42. __b = crt_copysignl(0, __b);
  43. __recalc = 1;
  44. }
  45. if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||
  46. crt_isinf(__bc))) {
  47. if (crt_isnan(__a))
  48. __a = crt_copysignl(0, __a);
  49. if (crt_isnan(__b))
  50. __b = crt_copysignl(0, __b);
  51. if (crt_isnan(__c))
  52. __c = crt_copysignl(0, __c);
  53. if (crt_isnan(__d))
  54. __d = crt_copysignl(0, __d);
  55. __recalc = 1;
  56. }
  57. if (__recalc) {
  58. COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
  59. COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
  60. }
  61. }
  62. return z;
  63. }
  64. #endif