llvm-project
70 строк · 2.0 Кб
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
13#define QUAD_PRECISION14#include "fp_lib.h"15#include "int_lib.h"16#include "int_math.h"17
18#if defined(CRT_HAS_F128)19
20// Returns: the product of a + ib and c + id
21
22COMPILER_RT_ABI Qcomplex __multc3(fp_t a, fp_t b, fp_t c, fp_t d) {23fp_t ac = a * c;24fp_t bd = b * d;25fp_t ad = a * d;26fp_t bc = b * c;27Qcomplex z;28COMPLEXTF_REAL(z) = ac - bd;29COMPLEXTF_IMAGINARY(z) = ad + bc;30if (crt_isnan(COMPLEXTF_REAL(z)) && crt_isnan(COMPLEXTF_IMAGINARY(z))) {31int recalc = 0;32if (crt_isinf(a) || crt_isinf(b)) {33a = crt_copysigntf(crt_isinf(a) ? 1 : 0, a);34b = crt_copysigntf(crt_isinf(b) ? 1 : 0, b);35if (crt_isnan(c))36c = crt_copysigntf(0, c);37if (crt_isnan(d))38d = crt_copysigntf(0, d);39recalc = 1;40}41if (crt_isinf(c) || crt_isinf(d)) {42c = crt_copysigntf(crt_isinf(c) ? 1 : 0, c);43d = crt_copysigntf(crt_isinf(d) ? 1 : 0, d);44if (crt_isnan(a))45a = crt_copysigntf(0, a);46if (crt_isnan(b))47b = crt_copysigntf(0, b);48recalc = 1;49}50if (!recalc &&51(crt_isinf(ac) || crt_isinf(bd) || crt_isinf(ad) || crt_isinf(bc))) {52if (crt_isnan(a))53a = crt_copysigntf(0, a);54if (crt_isnan(b))55b = crt_copysigntf(0, b);56if (crt_isnan(c))57c = crt_copysigntf(0, c);58if (crt_isnan(d))59d = crt_copysigntf(0, d);60recalc = 1;61}62if (recalc) {63COMPLEXTF_REAL(z) = CRT_INFINITY * (a * c - b * d);64COMPLEXTF_IMAGINARY(z) = CRT_INFINITY * (a * d + b * c);65}66}67return z;68}
69
70#endif71