multc3.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //===-- multc3.c - Implement __multc3 -------------------------------------===//
  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 __multc3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #define QUAD_PRECISION
  13. #include "fp_lib.h"
  14. #include "int_lib.h"
  15. #include "int_math.h"
  16. #if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
  17. // Returns: the product of a + ib and c + id
  18. COMPILER_RT_ABI Qcomplex __multc3(fp_t a, fp_t b, fp_t c, fp_t d) {
  19. fp_t ac = a * c;
  20. fp_t bd = b * d;
  21. fp_t ad = a * d;
  22. fp_t bc = b * c;
  23. Qcomplex z;
  24. COMPLEXTF_REAL(z) = ac - bd;
  25. COMPLEXTF_IMAGINARY(z) = ad + bc;
  26. if (crt_isnan(COMPLEXTF_REAL(z)) && crt_isnan(COMPLEXTF_IMAGINARY(z))) {
  27. int recalc = 0;
  28. if (crt_isinf(a) || crt_isinf(b)) {
  29. a = crt_copysigntf(crt_isinf(a) ? 1 : 0, a);
  30. b = crt_copysigntf(crt_isinf(b) ? 1 : 0, b);
  31. if (crt_isnan(c))
  32. c = crt_copysigntf(0, c);
  33. if (crt_isnan(d))
  34. d = crt_copysigntf(0, d);
  35. recalc = 1;
  36. }
  37. if (crt_isinf(c) || crt_isinf(d)) {
  38. c = crt_copysigntf(crt_isinf(c) ? 1 : 0, c);
  39. d = crt_copysigntf(crt_isinf(d) ? 1 : 0, d);
  40. if (crt_isnan(a))
  41. a = crt_copysigntf(0, a);
  42. if (crt_isnan(b))
  43. b = crt_copysigntf(0, b);
  44. recalc = 1;
  45. }
  46. if (!recalc &&
  47. (crt_isinf(ac) || crt_isinf(bd) || crt_isinf(ad) || crt_isinf(bc))) {
  48. if (crt_isnan(a))
  49. a = crt_copysigntf(0, a);
  50. if (crt_isnan(b))
  51. b = crt_copysigntf(0, b);
  52. if (crt_isnan(c))
  53. c = crt_copysigntf(0, c);
  54. if (crt_isnan(d))
  55. d = crt_copysigntf(0, d);
  56. recalc = 1;
  57. }
  58. if (recalc) {
  59. COMPLEXTF_REAL(z) = CRT_INFINITY * (a * c - b * d);
  60. COMPLEXTF_IMAGINARY(z) = CRT_INFINITY * (a * d + b * c);
  61. }
  62. }
  63. return z;
  64. }
  65. #endif