Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/divsc3.c
35260 views
//===-- divsc3.c - Implement __divsc3 -------------------------------------===//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 __divsc3 for the compiler_rt library.9//10//===----------------------------------------------------------------------===//1112#define SINGLE_PRECISION13#include "fp_lib.h"14#include "int_lib.h"15#include "int_math.h"1617// Returns: the quotient of (a + ib) / (c + id)1819COMPILER_RT_ABI Fcomplex __divsc3(float __a, float __b, float __c, float __d) {20int __ilogbw = 0;21float __logbw =22__compiler_rt_logbf(__compiler_rt_fmaxf(crt_fabsf(__c), crt_fabsf(__d)));23if (crt_isfinite(__logbw)) {24__ilogbw = (int)__logbw;25__c = __compiler_rt_scalbnf(__c, -__ilogbw);26__d = __compiler_rt_scalbnf(__d, -__ilogbw);27}28float __denom = __c * __c + __d * __d;29Fcomplex z;30COMPLEX_REAL(z) =31__compiler_rt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw);32COMPLEX_IMAGINARY(z) =33__compiler_rt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw);34if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {35if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) {36COMPLEX_REAL(z) = crt_copysignf(CRT_INFINITY, __c) * __a;37COMPLEX_IMAGINARY(z) = crt_copysignf(CRT_INFINITY, __c) * __b;38} else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) &&39crt_isfinite(__d)) {40__a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);41__b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);42COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);43COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);44} else if (crt_isinf(__logbw) && __logbw > 0 && crt_isfinite(__a) &&45crt_isfinite(__b)) {46__c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);47__d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);48COMPLEX_REAL(z) = 0 * (__a * __c + __b * __d);49COMPLEX_IMAGINARY(z) = 0 * (__b * __c - __a * __d);50}51}52return z;53}545556