mulsc3.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===-- mulsc3.c - Implement __mulsc3 -------------------------------------===//
  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 __mulsc3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. #include "int_math.h"
  14. // Returns: the product of a + ib and c + id
  15. COMPILER_RT_ABI Fcomplex __mulsc3(float __a, float __b, float __c, float __d) {
  16. float __ac = __a * __c;
  17. float __bd = __b * __d;
  18. float __ad = __a * __d;
  19. float __bc = __b * __c;
  20. Fcomplex z;
  21. COMPLEX_REAL(z) = __ac - __bd;
  22. COMPLEX_IMAGINARY(z) = __ad + __bc;
  23. if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
  24. int __recalc = 0;
  25. if (crt_isinf(__a) || crt_isinf(__b)) {
  26. __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
  27. __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
  28. if (crt_isnan(__c))
  29. __c = crt_copysignf(0, __c);
  30. if (crt_isnan(__d))
  31. __d = crt_copysignf(0, __d);
  32. __recalc = 1;
  33. }
  34. if (crt_isinf(__c) || crt_isinf(__d)) {
  35. __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
  36. __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
  37. if (crt_isnan(__a))
  38. __a = crt_copysignf(0, __a);
  39. if (crt_isnan(__b))
  40. __b = crt_copysignf(0, __b);
  41. __recalc = 1;
  42. }
  43. if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||
  44. crt_isinf(__bc))) {
  45. if (crt_isnan(__a))
  46. __a = crt_copysignf(0, __a);
  47. if (crt_isnan(__b))
  48. __b = crt_copysignf(0, __b);
  49. if (crt_isnan(__c))
  50. __c = crt_copysignf(0, __c);
  51. if (crt_isnan(__d))
  52. __d = crt_copysignf(0, __d);
  53. __recalc = 1;
  54. }
  55. if (__recalc) {
  56. COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
  57. COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
  58. }
  59. }
  60. return z;
  61. }