* config/alpha/alpha.md, arm/arm.c, darwin.c, frv/frv.md,
[official-gcc.git] / gcc / config / rs6000 / ppc64-fp.c
blob184f34e1de99421dca772bc515135da1efc3521c
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, 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA
31 02110-1301, USA. */
33 #if defined(__powerpc64__) || defined (__64BIT__) || defined(__ppc64__)
34 #define TMODES
35 #include "config/fp-bit.h"
37 extern DItype __fixtfdi (TFtype);
38 extern DItype __fixdfdi (DFtype);
39 extern DItype __fixsfdi (SFtype);
40 extern USItype __fixunsdfsi (DFtype);
41 extern USItype __fixunssfsi (SFtype);
42 extern TFtype __floatditf (DItype);
43 extern TFtype __floatunditf (UDItype);
44 extern DFtype __floatdidf (DItype);
45 extern DFtype __floatundidf (UDItype);
46 extern SFtype __floatdisf (DItype);
47 extern SFtype __floatundisf (UDItype);
48 extern DItype __fixunstfdi (TFtype);
50 static DItype local_fixunssfdi (SFtype);
51 static DItype local_fixunsdfdi (DFtype);
53 DItype
54 __fixtfdi (TFtype a)
56 if (a < 0)
57 return - __fixunstfdi (-a);
58 return __fixunstfdi (a);
61 DItype
62 __fixdfdi (DFtype a)
64 if (a < 0)
65 return - local_fixunsdfdi (-a);
66 return local_fixunsdfdi (a);
69 DItype
70 __fixsfdi (SFtype a)
72 if (a < 0)
73 return - local_fixunssfdi (-a);
74 return local_fixunssfdi (a);
77 USItype
78 __fixunsdfsi (DFtype a)
80 if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
81 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
82 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
83 return (SItype) a;
86 USItype
87 __fixunssfsi (SFtype a)
89 if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
90 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
91 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
92 return (SItype) a;
95 TFtype
96 __floatditf (DItype u)
98 DFtype dh, dl;
100 dh = (SItype) (u >> (sizeof (SItype) * 8));
101 dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
102 dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
104 return (TFtype) dh + (TFtype) dl;
107 TFtype
108 __floatunditf (UDItype u)
110 DFtype dh, dl;
112 dh = (USItype) (u >> (sizeof (SItype) * 8));
113 dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
114 dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
116 return (TFtype) dh + (TFtype) dl;
119 DFtype
120 __floatdidf (DItype u)
122 DFtype d;
124 d = (SItype) (u >> (sizeof (SItype) * 8));
125 d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
126 d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
128 return d;
131 DFtype
132 __floatundidf (UDItype u)
134 DFtype d;
136 d = (USItype) (u >> (sizeof (SItype) * 8));
137 d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
138 d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
140 return d;
143 SFtype
144 __floatdisf (DItype u)
146 DFtype f;
148 if (53 < (sizeof (DItype) * 8)
149 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
151 if (! (- ((DItype) 1 << 53) < u
152 && u < ((DItype) 1 << 53)))
154 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
156 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
157 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
161 f = (SItype) (u >> (sizeof (SItype) * 8));
162 f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
163 f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
165 return (SFtype) f;
168 SFtype
169 __floatundisf (UDItype u)
171 DFtype f;
173 if (53 < (sizeof (DItype) * 8)
174 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
176 if (u >= ((UDItype) 1 << 53))
178 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
180 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
181 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
185 f = (USItype) (u >> (sizeof (SItype) * 8));
186 f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
187 f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
189 return (SFtype) f;
192 DItype
193 __fixunstfdi (TFtype a)
195 if (a < 0)
196 return 0;
198 /* Compute high word of result, as a flonum. */
199 const TFtype b = (a / (((UDItype) 1) << (sizeof (SItype) * 8)));
200 /* Convert that to fixed (but not to DItype!),
201 and shift it into the high word. */
202 UDItype v = (USItype) b;
203 v <<= (sizeof (SItype) * 8);
204 /* Remove high part from the TFtype, leaving the low part as flonum. */
205 a -= (TFtype) v;
206 /* Convert that to fixed (but not to DItype!) and add it in.
207 Sometimes A comes out negative. This is significant, since
208 A has more bits than a long int does. */
209 if (a < 0)
210 v -= (USItype) (-a);
211 else
212 v += (USItype) a;
213 return v;
216 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
217 calls fixdfdi, which in turn calls calls fixunsdfdi. */
219 static DItype
220 local_fixunsdfdi (DFtype a)
222 USItype hi, lo;
224 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
225 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
226 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
229 /* This version is needed to prevent recursion; fixunssfdi in libgcc
230 calls fixsfdi, which in turn calls calls fixunssfdi. */
232 static DItype
233 local_fixunssfdi (SFtype original_a)
235 DFtype a = original_a;
236 USItype hi, lo;
238 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
239 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
240 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
243 #endif /* __powerpc64__ */