Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / config / rs6000 / ppc64-fp.c
blobf3ba4ccef84c077791b1f38fdbe62bab4d70f315
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__)
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 DFtype __floatdidf (DItype);
44 extern SFtype __floatdisf (DItype);
45 extern DItype __fixunstfdi (TFtype);
47 static DItype local_fixunssfdi (SFtype);
48 static DItype local_fixunsdfdi (DFtype);
50 DItype
51 __fixtfdi (TFtype a)
53 if (a < 0)
54 return - __fixunstfdi (-a);
55 return __fixunstfdi (a);
58 DItype
59 __fixdfdi (DFtype a)
61 if (a < 0)
62 return - local_fixunsdfdi (-a);
63 return local_fixunsdfdi (a);
66 DItype
67 __fixsfdi (SFtype a)
69 if (a < 0)
70 return - local_fixunssfdi (-a);
71 return local_fixunssfdi (a);
74 USItype
75 __fixunsdfsi (DFtype a)
77 if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
78 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
79 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
80 return (SItype) a;
83 USItype
84 __fixunssfsi (SFtype a)
86 if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
87 return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
88 - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
89 return (SItype) a;
92 TFtype
93 __floatditf (DItype u)
95 DFtype dh, dl;
97 dh = (SItype) (u >> (sizeof (SItype) * 8));
98 dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
99 dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
101 return (TFtype) dh + (TFtype) dl;
104 DFtype
105 __floatdidf (DItype u)
107 DFtype d;
109 d = (SItype) (u >> (sizeof (SItype) * 8));
110 d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
111 d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
113 return d;
116 SFtype
117 __floatdisf (DItype u)
119 DFtype f;
121 if (53 < (sizeof (DItype) * 8)
122 && 53 > ((sizeof (DItype) * 8) - 53 + 24))
124 if (! (- ((DItype) 1 << 53) < u
125 && u < ((DItype) 1 << 53)))
127 if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
129 u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
130 u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
134 f = (SItype) (u >> (sizeof (SItype) * 8));
135 f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
136 f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
138 return (SFtype) f;
141 DItype
142 __fixunstfdi (TFtype a)
144 if (a < 0)
145 return 0;
147 /* Compute high word of result, as a flonum. */
148 const TFtype b = (a / (((UDItype) 1) << (sizeof (SItype) * 8)));
149 /* Convert that to fixed (but not to DItype!),
150 and shift it into the high word. */
151 UDItype v = (USItype) b;
152 v <<= (sizeof (SItype) * 8);
153 /* Remove high part from the TFtype, leaving the low part as flonum. */
154 a -= (TFtype) v;
155 /* Convert that to fixed (but not to DItype!) and add it in.
156 Sometimes A comes out negative. This is significant, since
157 A has more bits than a long int does. */
158 if (a < 0)
159 v -= (USItype) (-a);
160 else
161 v += (USItype) a;
162 return v;
165 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
166 calls fixdfdi, which in turn calls calls fixunsdfdi. */
168 static DItype
169 local_fixunsdfdi (DFtype a)
171 USItype hi, lo;
173 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
174 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
175 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
178 /* This version is needed to prevent recursion; fixunssfdi in libgcc
179 calls fixsfdi, which in turn calls calls fixunssfdi. */
181 static DItype
182 local_fixunssfdi (SFtype original_a)
184 DFtype a = original_a;
185 USItype hi, lo;
187 hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
188 lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
189 return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
192 #endif /* __powerpc64__ */