OSDN Git Service

bce99d2cee8bcbbb9a413e682b781f49bb105d65
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / quadlib.c
1 /* Subroutines for long double support.
2    Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file.  (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
19
20 GCC is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with GCC; see the file COPYING.  If not, write to
27 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.  */
29
30 /* HPUX TFmode compare requires a library call to _U_Qfcmp, which takes a
31    magic number as its third argument, that indicates what to do.
32    The return value is an integer to be compared against zero.  */
33 enum qfcmp_magic {
34   QCMP_INV = 1,         /* Raise FP_INVALID on SNaN as a side effect.  */
35   QCMP_UNORD = 2,
36   QCMP_EQ = 4,
37   QCMP_LT = 8,
38   QCMP_GT = 16
39 } magic;
40
41 int _U_Qfcmp (long double a, long double b, int);
42 long _U_Qfcnvfxt_quad_to_sgl (long double);
43
44 int _U_Qfeq (long double, long double);
45 int _U_Qfne (long double, long double);
46 int _U_Qfgt (long double, long double);
47 int _U_Qfge (long double, long double);
48 int _U_Qflt (long double, long double);
49 int _U_Qfle (long double, long double);
50 int _U_Qfltgt (long double, long double);
51 int _U_Qfunle (long double, long double);
52 int _U_Qfunlt (long double, long double);
53 int _U_Qfunge (long double, long double);
54 int _U_Qfungt (long double, long double);
55 int _U_Qfuneq (long double, long double);
56 int _U_Qfunord (long double, long double);
57 int _U_Qford (long double, long double);
58
59 int _U_Qfcomp (long double, long double);
60
61 long double _U_Qfneg (long double);
62
63 #ifdef __LP64__
64 int __U_Qfcnvfxt_quad_to_sgl (long double);
65 #endif
66 unsigned int _U_Qfcnvfxt_quad_to_usgl(long double);
67 long double _U_Qfcnvxf_usgl_to_quad (unsigned int);
68 unsigned long long _U_Qfcnvfxt_quad_to_udbl(long double);
69 long double _U_Qfcnvxf_udbl_to_quad (unsigned long long);
70
71 int
72 _U_Qfeq (long double a, long double b)
73 {
74   return (_U_Qfcmp (a, b, QCMP_EQ) != 0);
75 }
76
77 int
78 _U_Qfne (long double a, long double b)
79 {
80   return (_U_Qfcmp (a, b, QCMP_EQ) == 0);
81 }
82         
83 int
84 _U_Qfgt (long double a, long double b)
85 {
86   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_GT) != 0);
87 }
88
89 int
90 _U_Qfge (long double a, long double b)
91 {
92   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_GT) != 0);
93 }
94
95 int
96 _U_Qflt (long double a, long double b)
97 {
98   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_LT) != 0);
99 }
100
101 int
102 _U_Qfle (long double a, long double b)
103 {
104   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_LT) != 0);
105 }
106
107 int
108 _U_Qfltgt (long double a, long double b)
109 {
110   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_LT | QCMP_GT) != 0);
111 }
112
113 int
114 _U_Qfunle (long double a, long double b)
115 {
116   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ | QCMP_LT) != 0);
117 }
118
119 int
120 _U_Qfunlt (long double a, long double b)
121 {
122   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_LT) != 0);
123 }
124
125 int
126 _U_Qfunge (long double a, long double b)
127 {
128   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ | QCMP_GT) != 0);
129 }
130
131 int
132 _U_Qfungt (long double a, long double b)
133 {
134   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_GT) != 0);
135 }
136
137 int
138 _U_Qfuneq (long double a, long double b)
139 {
140   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ) != 0);
141 }
142
143 int
144 _U_Qfunord (long double a, long double b)
145 {
146   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD) != 0);
147 }
148
149 int
150 _U_Qford (long double a, long double b)
151 {
152   return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_LT | QCMP_GT) != 0);
153 }
154
155 int
156 _U_Qfcomp (long double a, long double b)
157 {
158   if (_U_Qfcmp (a, b, QCMP_EQ) == 0)
159     return 0;
160
161   return (_U_Qfcmp (a, b, QCMP_UNORD | QCMP_EQ | QCMP_GT) != 0 ? 1 : -1);
162 }
163
164
165 /* Negate long double A.  */
166 long double
167 _U_Qfneg (long double a)
168 {
169   union
170    {
171      long double ld;
172      int i[4];
173    } u;
174
175   u.ld = a;
176   u.i[0] ^= 0x80000000;
177   return u.ld;
178 }
179
180 #ifdef __LP64__
181 /* This routine is only necessary for the PA64 port; for reasons unknown
182    _U_Qfcnvfxt_quad_to_sgl returns the integer in the high 32bits of the
183    return value.  Ugh.  */
184 int
185 __U_Qfcnvfxt_quad_to_sgl (long double a)
186 {
187   return _U_Qfcnvfxt_quad_to_sgl (a) >> 32;
188 }
189 #endif
190
191 /* HP only has signed conversion in the C library, so need to synthesize
192    unsigned versions.  */
193 unsigned int
194 _U_Qfcnvfxt_quad_to_usgl (long double a)
195 {
196   extern long long _U_Qfcnvfxt_quad_to_dbl (long double a);
197   return (unsigned int) _U_Qfcnvfxt_quad_to_dbl (a);
198 }
199
200 long double
201 _U_Qfcnvxf_usgl_to_quad (unsigned int a)
202 {
203   extern long double _U_Qfcnvxf_dbl_to_quad (long long);
204   return _U_Qfcnvxf_dbl_to_quad ((long long) a);
205 }
206
207 typedef union {
208     unsigned long long u[2];
209     long double d[1];
210 } quad_type;
211
212 unsigned long long
213 _U_Qfcnvfxt_quad_to_udbl (long double a)
214 {
215   extern quad_type _U_Qfcnvfxt_quad_to_quad (long double a);
216   quad_type u;
217   u = _U_Qfcnvfxt_quad_to_quad(a);
218   return u.u[1];
219 }
220
221 long double
222 _U_Qfcnvxf_udbl_to_quad (unsigned long long a)
223 {
224   extern long double _U_Qfcnvxf_quad_to_quad (quad_type a);
225   quad_type u;
226   u.u[0] = 0;
227   u.u[1] = a;
228   return _U_Qfcnvxf_quad_to_quad (u);
229 }