1 1.1.1.9 mrg /* Copyright (C) 1989-2024 Free Software Foundation, Inc. 2 1.1 mrg 3 1.1 mrg This file is part of GCC. 4 1.1 mrg 5 1.1 mrg GCC is free software; you can redistribute it and/or modify it under 6 1.1 mrg the terms of the GNU General Public License as published by the Free 7 1.1 mrg Software Foundation; either version 3, or (at your option) any later 8 1.1 mrg version. 9 1.1 mrg 10 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 11 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 1.1 mrg for more details. 14 1.1 mrg 15 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 16 1.1 mrg permissions described in the GCC Runtime Library Exception, version 17 1.1 mrg 3.1, as published by the Free Software Foundation. 18 1.1 mrg 19 1.1 mrg You should have received a copy of the GNU General Public License and 20 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 21 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 22 1.1 mrg <http://www.gnu.org/licenses/>. */ 23 1.1 mrg 24 1.1 mrg /* This is a temporary specialization of code from libgcc/libgcc2.c. */ 25 1.1 mrg 26 1.1.1.5 mrg #include "soft-fp.h" 27 1.1.1.5 mrg #include "quad-float128.h" 28 1.1 mrg 29 1.1.1.9 mrg /* Use the correct built-in function based on whether TFmode is _Float128 or 30 1.1.1.9 mrg long double. See quad-float128.h for more details. */ 31 1.1.1.9 mrg #ifndef __LONG_DOUBLE_IEEE128__ 32 1.1.1.5 mrg #define COPYSIGN(x,y) __builtin_copysignf128 (x, y) 33 1.1.1.5 mrg #define INFINITY __builtin_inff128 () 34 1.1.1.9 mrg 35 1.1.1.9 mrg #else 36 1.1.1.9 mrg #define COPYSIGN(x,y) __builtin_copysignl (x, y) 37 1.1.1.9 mrg #define INFINITY __builtin_infl () 38 1.1.1.9 mrg #endif 39 1.1.1.9 mrg 40 1.1 mrg #define isnan __builtin_isnan 41 1.1 mrg #define isinf __builtin_isinf 42 1.1 mrg 43 1.1.1.5 mrg #if defined(FLOAT128_HW_INSNS) && !defined(__mulkc3) 44 1.1.1.5 mrg #define __mulkc3 __mulkc3_sw 45 1.1.1.5 mrg #endif 46 1.1.1.5 mrg 47 1.1.1.5 mrg TCtype 48 1.1.1.5 mrg __mulkc3 (TFtype a, TFtype b, TFtype c, TFtype d) 49 1.1 mrg { 50 1.1.1.5 mrg TFtype ac, bd, ad, bc, x, y; 51 1.1.1.5 mrg TCtype res; 52 1.1 mrg 53 1.1 mrg ac = a * c; 54 1.1 mrg bd = b * d; 55 1.1 mrg ad = a * d; 56 1.1 mrg bc = b * c; 57 1.1 mrg 58 1.1 mrg x = ac - bd; 59 1.1 mrg y = ad + bc; 60 1.1 mrg 61 1.1 mrg if (isnan (x) && isnan (y)) 62 1.1 mrg { 63 1.1 mrg /* Recover infinities that computed as NaN + iNaN. */ 64 1.1 mrg _Bool recalc = 0; 65 1.1 mrg if (isinf (a) || isinf (b)) 66 1.1 mrg { 67 1.1 mrg /* z is infinite. "Box" the infinity and change NaNs in 68 1.1 mrg the other factor to 0. */ 69 1.1 mrg a = COPYSIGN (isinf (a) ? 1 : 0, a); 70 1.1 mrg b = COPYSIGN (isinf (b) ? 1 : 0, b); 71 1.1 mrg if (isnan (c)) c = COPYSIGN (0, c); 72 1.1 mrg if (isnan (d)) d = COPYSIGN (0, d); 73 1.1 mrg recalc = 1; 74 1.1 mrg } 75 1.1 mrg if (isinf (c) || isinf (d)) 76 1.1 mrg { 77 1.1 mrg /* w is infinite. "Box" the infinity and change NaNs in 78 1.1 mrg the other factor to 0. */ 79 1.1 mrg c = COPYSIGN (isinf (c) ? 1 : 0, c); 80 1.1 mrg d = COPYSIGN (isinf (d) ? 1 : 0, d); 81 1.1 mrg if (isnan (a)) a = COPYSIGN (0, a); 82 1.1 mrg if (isnan (b)) b = COPYSIGN (0, b); 83 1.1 mrg recalc = 1; 84 1.1 mrg } 85 1.1 mrg if (!recalc 86 1.1 mrg && (isinf (ac) || isinf (bd) 87 1.1 mrg || isinf (ad) || isinf (bc))) 88 1.1 mrg { 89 1.1 mrg /* Recover infinities from overflow by changing NaNs to 0. */ 90 1.1 mrg if (isnan (a)) a = COPYSIGN (0, a); 91 1.1 mrg if (isnan (b)) b = COPYSIGN (0, b); 92 1.1 mrg if (isnan (c)) c = COPYSIGN (0, c); 93 1.1 mrg if (isnan (d)) d = COPYSIGN (0, d); 94 1.1 mrg recalc = 1; 95 1.1 mrg } 96 1.1 mrg if (recalc) 97 1.1 mrg { 98 1.1 mrg x = INFINITY * (a * c - b * d); 99 1.1 mrg y = INFINITY * (a * d + b * c); 100 1.1 mrg } 101 1.1 mrg } 102 1.1 mrg 103 1.1 mrg __real__ res = x; 104 1.1 mrg __imag__ res = y; 105 1.1 mrg return res; 106 1.1 mrg } 107 1.1 mrg 108