Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 1 | /* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------=== |
| 2 | * |
Chandler Carruth | 7a739a0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 6 | * |
| 7 | * ===----------------------------------------------------------------------=== |
| 8 | * |
| 9 | * This file implements __mulsc3 for the compiler_rt library. |
| 10 | * |
| 11 | * ===----------------------------------------------------------------------=== |
| 12 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 13 | |
| 14 | #include "int_lib.h" |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 15 | #include "int_math.h" |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 16 | |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 17 | /* Returns: the product of a + ib and c + id */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 18 | |
Saleem Abdulrasool | 363d735 | 2015-10-07 02:58:07 +0000 | [diff] [blame] | 19 | COMPILER_RT_ABI Fcomplex |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 20 | __mulsc3(float __a, float __b, float __c, float __d) |
| 21 | { |
| 22 | float __ac = __a * __c; |
| 23 | float __bd = __b * __d; |
| 24 | float __ad = __a * __d; |
| 25 | float __bc = __b * __c; |
Saleem Abdulrasool | 363d735 | 2015-10-07 02:58:07 +0000 | [diff] [blame] | 26 | Fcomplex z; |
| 27 | COMPLEX_REAL(z) = __ac - __bd; |
| 28 | COMPLEX_IMAGINARY(z) = __ad + __bc; |
| 29 | if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 30 | { |
| 31 | int __recalc = 0; |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 32 | if (crt_isinf(__a) || crt_isinf(__b)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 33 | { |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 34 | __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a); |
| 35 | __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 36 | if (crt_isnan(__c)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 37 | __c = crt_copysignf(0, __c); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 38 | if (crt_isnan(__d)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 39 | __d = crt_copysignf(0, __d); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 40 | __recalc = 1; |
| 41 | } |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 42 | if (crt_isinf(__c) || crt_isinf(__d)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 43 | { |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 44 | __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c); |
| 45 | __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 46 | if (crt_isnan(__a)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 47 | __a = crt_copysignf(0, __a); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 48 | if (crt_isnan(__b)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 49 | __b = crt_copysignf(0, __b); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 50 | __recalc = 1; |
| 51 | } |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 52 | if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || |
| 53 | crt_isinf(__ad) || crt_isinf(__bc))) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 54 | { |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 55 | if (crt_isnan(__a)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 56 | __a = crt_copysignf(0, __a); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 57 | if (crt_isnan(__b)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 58 | __b = crt_copysignf(0, __b); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 59 | if (crt_isnan(__c)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 60 | __c = crt_copysignf(0, __c); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 61 | if (crt_isnan(__d)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 62 | __d = crt_copysignf(0, __d); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 63 | __recalc = 1; |
| 64 | } |
| 65 | if (__recalc) |
| 66 | { |
Saleem Abdulrasool | 363d735 | 2015-10-07 02:58:07 +0000 | [diff] [blame] | 67 | COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d); |
| 68 | COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | return z; |
| 72 | } |