2009-08-08 04:30:09 +08:00
|
|
|
/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
|
|
|
|
*
|
2019-01-19 18:56:40 +08:00
|
|
|
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
* See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-08-08 04:30:09 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __mulsc3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
2011-11-16 15:33:00 +08:00
|
|
|
#include "int_math.h"
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* Returns: the product of a + ib and c + id */
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2015-10-07 10:58:07 +08:00
|
|
|
COMPILER_RT_ABI Fcomplex
|
2009-06-27 00:47:03 +08:00
|
|
|
__mulsc3(float __a, float __b, float __c, float __d)
|
|
|
|
{
|
|
|
|
float __ac = __a * __c;
|
|
|
|
float __bd = __b * __d;
|
|
|
|
float __ad = __a * __d;
|
|
|
|
float __bc = __b * __c;
|
2015-10-07 10:58:07 +08:00
|
|
|
Fcomplex z;
|
|
|
|
COMPLEX_REAL(z) = __ac - __bd;
|
|
|
|
COMPLEX_IMAGINARY(z) = __ad + __bc;
|
|
|
|
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
int __recalc = 0;
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(__a) || crt_isinf(__b))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
|
|
|
|
__b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__c))
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(0, __c);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__d))
|
2011-11-16 15:33:06 +08:00
|
|
|
__d = crt_copysignf(0, __d);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(__c) || crt_isinf(__d))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
|
|
|
|
__d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__a))
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(0, __a);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__b))
|
2011-11-16 15:33:06 +08:00
|
|
|
__b = crt_copysignf(0, __b);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
2011-11-16 15:33:00 +08:00
|
|
|
if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
|
|
|
|
crt_isinf(__ad) || crt_isinf(__bc)))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__a))
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(0, __a);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__b))
|
2011-11-16 15:33:06 +08:00
|
|
|
__b = crt_copysignf(0, __b);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__c))
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(0, __c);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__d))
|
2011-11-16 15:33:06 +08:00
|
|
|
__d = crt_copysignf(0, __d);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
|
|
|
if (__recalc)
|
|
|
|
{
|
2015-10-07 10:58:07 +08:00
|
|
|
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
|
|
|
|
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
|
2009-06-27 00:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return z;
|
|
|
|
}
|