Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 1 | /* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
| 10 | * This file implements __mulsc3 for the compiler_rt library. |
| 11 | * |
| 12 | * ===----------------------------------------------------------------------=== |
| 13 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 14 | |
| 15 | #include "int_lib.h" |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 16 | #include "int_math.h" |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 17 | |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 18 | /* Returns: the product of a + ib and c + id */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 19 | |
| 20 | float _Complex |
| 21 | __mulsc3(float __a, float __b, float __c, float __d) |
| 22 | { |
| 23 | float __ac = __a * __c; |
| 24 | float __bd = __b * __d; |
| 25 | float __ad = __a * __d; |
| 26 | float __bc = __b * __c; |
| 27 | float _Complex z; |
| 28 | __real__ z = __ac - __bd; |
| 29 | __imag__ z = __ad + __bc; |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 30 | if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 31 | { |
| 32 | int __recalc = 0; |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 33 | if (crt_isinf(__a) || crt_isinf(__b)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 34 | { |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 35 | __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a); |
| 36 | __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 37 | if (crt_isnan(__c)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 38 | __c = crt_copysignf(0, __c); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 39 | if (crt_isnan(__d)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 40 | __d = crt_copysignf(0, __d); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 41 | __recalc = 1; |
| 42 | } |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 43 | if (crt_isinf(__c) || crt_isinf(__d)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 44 | { |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 45 | __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c); |
| 46 | __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 47 | if (crt_isnan(__a)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 48 | __a = crt_copysignf(0, __a); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 49 | if (crt_isnan(__b)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 50 | __b = crt_copysignf(0, __b); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 51 | __recalc = 1; |
| 52 | } |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 53 | if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || |
| 54 | crt_isinf(__ad) || crt_isinf(__bc))) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 55 | { |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 56 | if (crt_isnan(__a)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 57 | __a = crt_copysignf(0, __a); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 58 | if (crt_isnan(__b)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 59 | __b = crt_copysignf(0, __b); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 60 | if (crt_isnan(__c)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 61 | __c = crt_copysignf(0, __c); |
Daniel Dunbar | 8603024 | 2011-11-16 07:33:00 +0000 | [diff] [blame] | 62 | if (crt_isnan(__d)) |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 63 | __d = crt_copysignf(0, __d); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 64 | __recalc = 1; |
| 65 | } |
| 66 | if (__recalc) |
| 67 | { |
Daniel Dunbar | c25c6d1 | 2011-11-16 07:33:06 +0000 | [diff] [blame] | 68 | __real__ z = CRT_INFINITY * (__a * __c - __b * __d); |
| 69 | __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | return z; |
| 73 | } |