PR target/16201
[official-gcc.git] / gcc / config / rs6000 / ppc64-fp.c
blobc2dda75cf2290bb5b740fa8c72c60bb32d99a8f3
1 /* Functions needed for soft-float on powerpc64-linux, copied from
2 libgcc2.c with macros expanded to force the use of specific types.
4 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
5 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
14 In addition to the permissions in the GNU General Public License, the
15 Free Software Foundation gives you unlimited permission to link the
16 compiled version of this file into combinations with other programs,
17 and to distribute those combinations without any restriction coming
18 from the use of this file. (The General Public License restrictions
19 do apply in other respects; for example, they cover modification of
20 the file, and distribution when not linked into a combine
21 executable.)
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 for more details.
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING. If not, write to the Free
30 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 02111-1307, USA. */
33 #if defined(__powerpc64__)
34 #include "config/fp-bit.h"
36 extern DItype __fixtfdi (TFtype);
37 extern DItype __fixdfdi (DFtype);
38 extern DItype __fixsfdi (SFtype);
39 extern USItype __fixunsdfsi (DFtype);
40 extern USItype __fixunssfsi (SFtype);
41 extern TFtype __floatditf (DItype);
42 extern DFtype __floatdidf (DItype);
43 extern SFtype __floatdisf (DItype);
44 extern DItype __fixunstfdi (TFtype);
46 static DItype local_fixunssfdi (SFtype);
47 static DItype local_fixunsdfdi (DFtype);
49 DItype
50 __fixtfdi (TFtype a)
52 if (a < 0)
53 return - __fixunstfdi (-a);
54 return __fixunstfdi (a);
57 DItype
58 __fixdfdi (DFtype a)
60 if (a < 0)
61 return - local_fixunsdfdi (-a);
62 return local_fixunsdfdi (a);
65 DItype
66 __fixsfdi (SFtype a)
68 if (a < 0)
69 return - local_fixunssfdi (-a);
70 return local_fixunssfdi (a);
73 USItype
74 __fixunsdfsi (DFtype a)
76 if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
77 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
78 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
79 return (SItype) a;
82 USItype
83 __fixunssfsi (SFtype a)
85 if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
86 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
87 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
88 return (SItype) a;
91 TFtype
92 __floatditf (DItype u)
94 DFtype dh, dl;
96 dh = (SItype) (u >> (sizeof (SItype) * 8));
97 dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
98 dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
100 return (TFtype) dh + (TFtype) dl;
103 DFtype
104 __floatdidf (DItype u)
106 DFtype d;
108 d = (SItype) (u >> (sizeof (SItype) * 8));
109 d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
110 d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
112 return d;
115 SFtype
116 __floatdisf (DItype u)
118 DFtype f;
120 if (53 < (sizeof (DItype) * 8)
121 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
123 if (! (- ((DItype) 1 << 53) < u
124 && u < ((DItype) 1 << 53)))
126 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
128 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
129 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
133 f = (SItype) (u >> (sizeof (SItype) * 8));
134 f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
135 f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
137 return (SFtype) f;
140 DItype
141 __fixunstfdi (TFtype a)
143 if (a < 0)
144 return 0;
146 /* Compute high word of result, as a flonum. */
147 const TFtype b = (a / (((UDItype) 1) << (sizeof (SItype) * 8)));
148 /* Convert that to fixed (but not to DItype!),
149 and shift it into the high word. */
150 UDItype v = (USItype) b;
151 v <<= (sizeof (SItype) * 8);
152 /* Remove high part from the TFtype, leaving the low part as flonum. */
153 a -= (TFtype) v;
154 /* Convert that to fixed (but not to DItype!) and add it in.
155 Sometimes A comes out negative. This is significant, since
156 A has more bits than a long int does. */
157 if (a < 0)
158 v -= (USItype) (-a);
159 else
160 v += (USItype) a;
161 return v;
164 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
165 calls fixdfdi, which in turn calls calls fixunsdfdi. */
167 static DItype
168 local_fixunsdfdi (DFtype a)
170 USItype hi, lo;
172 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
173 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
174 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
177 /* This version is needed to prevent recursion; fixunssfdi in libgcc
178 calls fixsfdi, which in turn calls calls fixunssfdi. */
180 static DItype
181 local_fixunssfdi (SFtype original_a)
183 DFtype a = original_a;
184 USItype hi, lo;
186 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
187 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
188 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
191 #endif /* __powerpc64__ */