Path: blob/main/core/posix-wasm/src/lib/builtins/muldc3.c
1067 views
//===-- muldc3.c - Implement __muldc3 -------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements __muldc3 for the compiler_rt library.9//10//===----------------------------------------------------------------------===//1112#include "int_lib.h"13#include "int_math.h"1415// Returns: the product of a + ib and c + id1617COMPILER_RT_ABI Dcomplex __muldc3(double __a, double __b, double __c,18double __d) {19double __ac = __a * __c;20double __bd = __b * __d;21double __ad = __a * __d;22double __bc = __b * __c;23Dcomplex z;24COMPLEX_REAL(z) = __ac - __bd;25COMPLEX_IMAGINARY(z) = __ad + __bc;26if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {27int __recalc = 0;28if (crt_isinf(__a) || crt_isinf(__b)) {29__a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);30__b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);31if (crt_isnan(__c))32__c = crt_copysign(0, __c);33if (crt_isnan(__d))34__d = crt_copysign(0, __d);35__recalc = 1;36}37if (crt_isinf(__c) || crt_isinf(__d)) {38__c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);39__d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);40if (crt_isnan(__a))41__a = crt_copysign(0, __a);42if (crt_isnan(__b))43__b = crt_copysign(0, __b);44__recalc = 1;45}46if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||47crt_isinf(__bc))) {48if (crt_isnan(__a))49__a = crt_copysign(0, __a);50if (crt_isnan(__b))51__b = crt_copysign(0, __b);52if (crt_isnan(__c))53__c = crt_copysign(0, __c);54if (crt_isnan(__d))55__d = crt_copysign(0, __d);56__recalc = 1;57}58if (__recalc) {59COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);60COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);61}62}63return z;64}656667