70 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements __mulxc3 for the compiler_rt library.10//11//===----------------------------------------------------------------------===//12 13#if !_ARCH_PPC14 15#include "int_lib.h"16#include "int_math.h"17 18// Returns: the product of a + ib and c + id19 20COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,21 xf_float __d) {22 xf_float __ac = __a * __c;23 xf_float __bd = __b * __d;24 xf_float __ad = __a * __d;25 xf_float __bc = __b * __c;26 Lcomplex z;27 COMPLEX_REAL(z) = __ac - __bd;28 COMPLEX_IMAGINARY(z) = __ad + __bc;29 if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {30 int __recalc = 0;31 if (crt_isinf(__a) || crt_isinf(__b)) {32 __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);33 __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);34 if (crt_isnan(__c))35 __c = crt_copysignl(0, __c);36 if (crt_isnan(__d))37 __d = crt_copysignl(0, __d);38 __recalc = 1;39 }40 if (crt_isinf(__c) || crt_isinf(__d)) {41 __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);42 __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);43 if (crt_isnan(__a))44 __a = crt_copysignl(0, __a);45 if (crt_isnan(__b))46 __b = crt_copysignl(0, __b);47 __recalc = 1;48 }49 if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||50 crt_isinf(__bc))) {51 if (crt_isnan(__a))52 __a = crt_copysignl(0, __a);53 if (crt_isnan(__b))54 __b = crt_copysignl(0, __b);55 if (crt_isnan(__c))56 __c = crt_copysignl(0, __c);57 if (crt_isnan(__d))58 __d = crt_copysignl(0, __d);59 __recalc = 1;60 }61 if (__recalc) {62 COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);63 COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);64 }65 }66 return z;67}68 69#endif70