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
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__) || defined (__64BIT__) || defined(__ppc64__)
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);
57 return - __fixunstfdi (-a);
58 return __fixunstfdi (a);
65 return - local_fixunsdfdi (-a);
66 return local_fixunsdfdi (a);
73 return - local_fixunssfdi (-a);
74 return local_fixunssfdi (a);
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);
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);
96 __floatditf (DItype u)
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;
108 __floatunditf (UDItype u)
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;
120 __floatdidf (DItype u)
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));
132 __floatundidf (UDItype u)
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));
144 __floatdisf (DItype u)
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));
169 __floatundisf (UDItype u)
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));
193 __fixunstfdi (TFtype a)
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. */
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. */
216 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
217 calls fixdfdi, which in turn calls calls fixunsdfdi. */
220 local_fixunsdfdi (DFtype a)
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. */
233 local_fixunssfdi (SFtype original_a)
235 DFtype a = original_a;
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__ */