OSDN Git Service

* config/rs6000/rs6000.c (rs6000_stack_t): Remove toc_save_p,
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / ppc64-fp.c
1 /* Functions needed for soft-float on powerpc64-linux, copied from
2    libgcc2.c with macros expanded to force the use of specific types.
3  
4    Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
5    2000, 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
6
7 This file is part of GCC.
8
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.
13
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.)
22
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.
27
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.  */
32
33 #if defined(__powerpc64__)
34 #include "config/fp-bit.h"
35
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 TFtype __floatunditf (UDItype);
43 extern DFtype __floatdidf (DItype);
44 extern DFtype __floatundidf (UDItype);
45 extern SFtype __floatdisf (DItype);
46 extern SFtype __floatundisf (UDItype);
47 extern DItype __fixunstfdi (TFtype);
48
49 static DItype local_fixunssfdi (SFtype);
50 static DItype local_fixunsdfdi (DFtype);
51
52 DItype
53 __fixtfdi (TFtype a)
54 {
55   if (a < 0)
56     return - __fixunstfdi (-a);
57   return __fixunstfdi (a);
58 }
59
60 DItype
61 __fixdfdi (DFtype a)
62 {
63   if (a < 0)
64     return - local_fixunsdfdi (-a);
65   return local_fixunsdfdi (a);
66 }
67
68 DItype
69 __fixsfdi (SFtype a)
70 {
71   if (a < 0)
72     return - local_fixunssfdi (-a);
73   return local_fixunssfdi (a);
74 }
75
76 USItype
77 __fixunsdfsi (DFtype a)
78 {
79   if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
80     return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
81                        - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
82   return (SItype) a;
83 }
84
85 USItype
86 __fixunssfsi (SFtype a)
87 {
88   if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
89     return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
90                        - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
91   return (SItype) a;
92 }
93
94 TFtype
95 __floatditf (DItype u)
96 {
97   DFtype dh, dl;
98
99   dh = (SItype) (u >> (sizeof (SItype) * 8));
100   dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
101   dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
102
103   return (TFtype) dh + (TFtype) dl;
104 }
105
106 TFtype
107 __floatunditf (UDItype u)
108 {
109   DFtype dh, dl;
110
111   dh = (USItype) (u >> (sizeof (SItype) * 8));
112   dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
113   dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
114
115   return (TFtype) dh + (TFtype) dl;
116 }
117
118 DFtype
119 __floatdidf (DItype u)
120 {
121   DFtype d;
122
123   d = (SItype) (u >> (sizeof (SItype) * 8));
124   d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
125   d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
126
127   return d;
128 }
129
130 DFtype
131 __floatundidf (UDItype u)
132 {
133   DFtype d;
134
135   d = (USItype) (u >> (sizeof (SItype) * 8));
136   d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
137   d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
138
139   return d;
140 }
141
142 SFtype
143 __floatdisf (DItype u)
144 {
145   DFtype f;
146
147   if (53 < (sizeof (DItype) * 8)
148       && 53 > ((sizeof (DItype) * 8) - 53 + 24))
149     {
150       if (! (- ((DItype) 1 << 53) < u
151              && u < ((DItype) 1 << 53)))
152         {
153           if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
154             {
155               u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
156               u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
157             }
158         }
159     }
160   f = (SItype) (u >> (sizeof (SItype) * 8));
161   f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
162   f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
163
164   return (SFtype) f;
165 }
166
167 SFtype
168 __floatundisf (UDItype u)
169 {
170   DFtype f;
171
172   if (53 < (sizeof (DItype) * 8)
173       && 53 > ((sizeof (DItype) * 8) - 53 + 24))
174     {
175       if (u >= ((UDItype) 1 << 53))
176         {
177           if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
178             {
179               u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
180               u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
181             }
182         }
183     }
184   f = (USItype) (u >> (sizeof (SItype) * 8));
185   f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
186   f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
187
188   return (SFtype) f;
189 }
190
191 DItype
192 __fixunstfdi (TFtype a)
193 {
194   if (a < 0)
195     return 0;
196
197   /* Compute high word of result, as a flonum.  */
198   const TFtype b = (a / (((UDItype) 1) << (sizeof (SItype) * 8)));
199   /* Convert that to fixed (but not to DItype!),
200      and shift it into the high word.  */
201   UDItype v = (USItype) b;
202   v <<= (sizeof (SItype) * 8);
203   /* Remove high part from the TFtype, leaving the low part as flonum.  */
204   a -= (TFtype) v;
205   /* Convert that to fixed (but not to DItype!) and add it in.
206      Sometimes A comes out negative.  This is significant, since
207      A has more bits than a long int does.  */
208   if (a < 0)
209     v -= (USItype) (-a);
210   else
211     v += (USItype) a;
212   return v;
213 }
214
215 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
216    calls fixdfdi, which in turn calls calls fixunsdfdi.  */
217
218 static DItype
219 local_fixunsdfdi (DFtype a)
220 {
221   USItype hi, lo;
222
223   hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
224   lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
225   return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
226 }
227
228 /* This version is needed to prevent recursion; fixunssfdi in libgcc
229    calls fixsfdi, which in turn calls calls fixunssfdi.  */
230
231 static DItype
232 local_fixunssfdi (SFtype original_a)
233 {
234   DFtype a = original_a;
235   USItype hi, lo;
236
237   hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
238   lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
239   return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
240 }
241
242 #endif /* __powerpc64__ */