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
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
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
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
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);
56 return - __fixunstfdi (-a);
57 return __fixunstfdi (a);
64 return - local_fixunsdfdi (-a);
65 return local_fixunsdfdi (a);
72 return - local_fixunssfdi (-a);
73 return local_fixunssfdi (a);
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);
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);
95 __floatditf (DItype u)
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;
107 __floatunditf (UDItype u)
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;
119 __floatdidf (DItype u)
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));
131 __floatundidf (UDItype u)
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));
143 __floatdisf (DItype u)
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));
168 __floatundisf (UDItype u)
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));
192 __fixunstfdi (TFtype a)
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. */
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. */
215 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
216 calls fixdfdi, which in turn calls calls fixunsdfdi. */
219 local_fixunsdfdi (DFtype a)
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. */
232 local_fixunssfdi (SFtype original_a)
234 DFtype a = original_a;
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__ */