llvm-project
69 строк · 2.2 Кб
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
13#if !_ARCH_PPC14
15#include "int_lib.h"16#include "int_math.h"17
18// Returns: the product of a + ib and c + id
19
20COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,21xf_float __d) {22xf_float __ac = __a * __c;23xf_float __bd = __b * __d;24xf_float __ad = __a * __d;25xf_float __bc = __b * __c;26Lcomplex z;27COMPLEX_REAL(z) = __ac - __bd;28COMPLEX_IMAGINARY(z) = __ad + __bc;29if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {30int __recalc = 0;31if (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);34if (crt_isnan(__c))35__c = crt_copysignl(0, __c);36if (crt_isnan(__d))37__d = crt_copysignl(0, __d);38__recalc = 1;39}40if (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);43if (crt_isnan(__a))44__a = crt_copysignl(0, __a);45if (crt_isnan(__b))46__b = crt_copysignl(0, __b);47__recalc = 1;48}49if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||50crt_isinf(__bc))) {51if (crt_isnan(__a))52__a = crt_copysignl(0, __a);53if (crt_isnan(__b))54__b = crt_copysignl(0, __b);55if (crt_isnan(__c))56__c = crt_copysignl(0, __c);57if (crt_isnan(__d))58__d = crt_copysignl(0, __d);59__recalc = 1;60}61if (__recalc) {62COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);63COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);64}65}66return z;67}
68
69#endif70