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