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
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. */
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 FABS __builtin_fabsq
32 #define isnan __builtin_isnan
33 #define isinf __builtin_isinf
34 #define isfinite __builtin_isfinite
36 #if defined(FLOAT128_HW_INSNS) && !defined(__divkc3)
37 #define __divkc3 __divkc3_sw
40 extern KCtype
__divkc3 (KFtype
, KFtype
, KFtype
, KFtype
);
43 __divkc3 (KFtype a
, KFtype b
, KFtype c
, KFtype d
)
45 KFtype denom
, ratio
, x
, y
;
48 /* ??? We can get better behavior from logarithmic scaling instead of
49 the division. But that would mean starting to link libgcc against
50 libm. We could implement something akin to ldexp/frexp as gcc builtins
52 if (FABS (c
) < FABS (d
))
55 denom
= (c
* ratio
) + d
;
56 x
= ((a
* ratio
) + b
) / denom
;
57 y
= ((b
* ratio
) - a
) / denom
;
62 denom
= (d
* ratio
) + c
;
63 x
= ((b
* ratio
) + a
) / denom
;
64 y
= (b
- (a
* ratio
)) / denom
;
67 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
68 are nonzero/zero, infinite/finite, and finite/infinite. */
69 if (isnan (x
) && isnan (y
))
71 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
73 x
= COPYSIGN (INFINITY
, c
) * a
;
74 y
= COPYSIGN (INFINITY
, c
) * b
;
76 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
78 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
79 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
80 x
= INFINITY
* (a
* c
+ b
* d
);
81 y
= INFINITY
* (b
* c
- a
* d
);
83 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
85 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
86 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
87 x
= 0.0 * (a
* c
+ b
* d
);
88 y
= 0.0 * (b
* c
- a
* d
);