_mulkc3.c (__mulkc3): Add forward declaration.
[official-gcc.git] / libgcc / config / rs6000 / _mulkc3.c
blobc2687bee97b470a7525c064499926ca3accae56a
1 /* Copyright (C) 1989-2017 Free Software Foundation, Inc.
3 This file is part of GCC.
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.
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.
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.
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/>. */
24 /* This is a temporary specialization of code from libgcc/libgcc2.c. */
26 typedef float KFtype __attribute__ ((mode (KF)));
27 typedef __complex float KCtype __attribute__ ((mode (KC)));
29 #define COPYSIGN(x,y) __builtin_copysignq (x, y)
30 #define INFINITY __builtin_infq ()
31 #define isnan __builtin_isnan
32 #define isinf __builtin_isinf
34 #if defined(FLOAT128_HW_INSNS) && !defined(__mulkc3)
35 #define __mulkc3 __mulkc3_sw
36 #endif
38 extern KCtype __mulkc3 (KFtype, KFtype, KFtype, KFtype);
40 KCtype
41 __mulkc3 (KFtype a, KFtype b, KFtype c, KFtype d)
43 KFtype ac, bd, ad, bc, x, y;
44 KCtype res;
46 ac = a * c;
47 bd = b * d;
48 ad = a * d;
49 bc = b * c;
51 x = ac - bd;
52 y = ad + bc;
54 if (isnan (x) && isnan (y))
56 /* Recover infinities that computed as NaN + iNaN. */
57 _Bool recalc = 0;
58 if (isinf (a) || isinf (b))
60 /* z is infinite. "Box" the infinity and change NaNs in
61 the other factor to 0. */
62 a = COPYSIGN (isinf (a) ? 1 : 0, a);
63 b = COPYSIGN (isinf (b) ? 1 : 0, b);
64 if (isnan (c)) c = COPYSIGN (0, c);
65 if (isnan (d)) d = COPYSIGN (0, d);
66 recalc = 1;
68 if (isinf (c) || isinf (d))
70 /* w is infinite. "Box" the infinity and change NaNs in
71 the other factor to 0. */
72 c = COPYSIGN (isinf (c) ? 1 : 0, c);
73 d = COPYSIGN (isinf (d) ? 1 : 0, d);
74 if (isnan (a)) a = COPYSIGN (0, a);
75 if (isnan (b)) b = COPYSIGN (0, b);
76 recalc = 1;
78 if (!recalc
79 && (isinf (ac) || isinf (bd)
80 || isinf (ad) || isinf (bc)))
82 /* Recover infinities from overflow by changing NaNs to 0. */
83 if (isnan (a)) a = COPYSIGN (0, a);
84 if (isnan (b)) b = COPYSIGN (0, b);
85 if (isnan (c)) c = COPYSIGN (0, c);
86 if (isnan (d)) d = COPYSIGN (0, d);
87 recalc = 1;
89 if (recalc)
91 x = INFINITY * (a * c - b * d);
92 y = INFINITY * (a * d + b * c);
96 __real__ res = x;
97 __imag__ res = y;
98 return res;