Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / config / rs6000 / ppc64-fp.c
blob6be3ca8235feafede4a04d66a66956935cfffbd4
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, 51 Franklin Street, Fifth Floor, Boston, MA
31 02110-1301, 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 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);
49 static DItype local_fixunssfdi (SFtype);
50 static DItype local_fixunsdfdi (DFtype);
52 DItype
53 __fixtfdi (TFtype a)
55 if (a < 0)
56 return - __fixunstfdi (-a);
57 return __fixunstfdi (a);
60 DItype
61 __fixdfdi (DFtype a)
63 if (a < 0)
64 return - local_fixunsdfdi (-a);
65 return local_fixunsdfdi (a);
68 DItype
69 __fixsfdi (SFtype a)
71 if (a < 0)
72 return - local_fixunssfdi (-a);
73 return local_fixunssfdi (a);
76 USItype
77 __fixunsdfsi (DFtype a)
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;
85 USItype
86 __fixunssfsi (SFtype a)
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;
94 TFtype
95 __floatditf (DItype u)
97 DFtype dh, dl;
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));
103 return (TFtype) dh + (TFtype) dl;
106 TFtype
107 __floatunditf (UDItype u)
109 DFtype dh, dl;
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));
115 return (TFtype) dh + (TFtype) dl;
118 DFtype
119 __floatdidf (DItype u)
121 DFtype d;
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));
127 return d;
130 DFtype
131 __floatundidf (UDItype u)
133 DFtype d;
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));
139 return d;
142 SFtype
143 __floatdisf (DItype u)
145 DFtype f;
147 if (53 < (sizeof (DItype) * 8)
148 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
150 if (! (- ((DItype) 1 << 53) < u
151 && u < ((DItype) 1 << 53)))
153 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
155 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
156 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
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));
164 return (SFtype) f;
167 SFtype
168 __floatundisf (UDItype u)
170 DFtype f;
172 if (53 < (sizeof (DItype) * 8)
173 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
175 if (u >= ((UDItype) 1 << 53))
177 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
179 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
180 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
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));
188 return (SFtype) f;
191 DItype
192 __fixunstfdi (TFtype a)
194 if (a < 0)
195 return 0;
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;
215 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
216 calls fixdfdi, which in turn calls calls fixunsdfdi. */
218 static DItype
219 local_fixunsdfdi (DFtype a)
221 USItype hi, lo;
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;
228 /* This version is needed to prevent recursion; fixunssfdi in libgcc
229 calls fixsfdi, which in turn calls calls fixunssfdi. */
231 static DItype
232 local_fixunssfdi (SFtype original_a)
234 DFtype a = original_a;
235 USItype hi, lo;
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;
242 #endif /* __powerpc64__ */