]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/config/rs6000/_mulkc3.c
1 /* Copyright (C) 1989-2024 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
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
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. */
27 #include "quad-float128.h"
29 /* Use the correct built-in function based on whether TFmode is _Float128 or
30 long double. See quad-float128.h for more details. */
31 #ifndef __LONG_DOUBLE_IEEE128__
32 #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
33 #define INFINITY __builtin_inff128 ()
36 #define COPYSIGN(x,y) __builtin_copysignl (x, y)
37 #define INFINITY __builtin_infl ()
40 #define isnan __builtin_isnan
41 #define isinf __builtin_isinf
43 #if defined(FLOAT128_HW_INSNS) && !defined(__mulkc3)
44 #define __mulkc3 __mulkc3_sw
48 __mulkc3 (TFtype a
, TFtype b
, TFtype c
, TFtype d
)
50 TFtype ac
, bd
, ad
, bc
, x
, y
;
61 if (isnan (x
) && isnan (y
))
63 /* Recover infinities that computed as NaN + iNaN. */
65 if (isinf (a
) || isinf (b
))
67 /* z is infinite. "Box" the infinity and change NaNs in
68 the other factor to 0. */
69 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
70 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
71 if (isnan (c
)) c
= COPYSIGN (0, c
);
72 if (isnan (d
)) d
= COPYSIGN (0, d
);
75 if (isinf (c
) || isinf (d
))
77 /* w is infinite. "Box" the infinity and change NaNs in
78 the other factor to 0. */
79 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
80 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
81 if (isnan (a
)) a
= COPYSIGN (0, a
);
82 if (isnan (b
)) b
= COPYSIGN (0, b
);
86 && (isinf (ac
) || isinf (bd
)
87 || isinf (ad
) || isinf (bc
)))
89 /* Recover infinities from overflow by changing NaNs to 0. */
90 if (isnan (a
)) a
= COPYSIGN (0, a
);
91 if (isnan (b
)) b
= COPYSIGN (0, b
);
92 if (isnan (c
)) c
= COPYSIGN (0, c
);
93 if (isnan (d
)) d
= COPYSIGN (0, d
);
98 x
= INFINITY
* (a
* c
- b
* d
);
99 y
= INFINITY
* (a
* d
+ b
* c
);