]> git.ipfire.org Git - thirdparty/glibc.git/blob - soft-fp/quad.h
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / soft-fp / quad.h
1 /* Software floating-point emulation.
2 Definitions for IEEE Quad Precision.
3 Copyright (C) 1997,1998,1999,2006,2007 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz),
7 David S. Miller (davem@redhat.com) and
8 Peter Maydell (pmaydell@chiark.greenend.org.uk).
9
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 In addition to the permissions in the GNU Lesser General Public
16 License, the Free Software Foundation gives you unlimited
17 permission to link the compiled version of this file into
18 combinations with other programs, and to distribute those
19 combinations without any restriction coming from the use of this
20 file. (The Lesser General Public License restrictions do apply in
21 other respects; for example, they cover modification of the file,
22 and distribution when not linked into a combine executable.)
23
24 The GNU C Library is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 Lesser General Public License for more details.
28
29 You should have received a copy of the GNU Lesser General Public
30 License along with the GNU C Library; if not, see
31 <http://www.gnu.org/licenses/>. */
32
33 #if _FP_W_TYPE_SIZE < 32
34 #error "Here's a nickel, kid. Go buy yourself a real computer."
35 #endif
36
37 #if _FP_W_TYPE_SIZE < 64
38 #define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
39 #else
40 #define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
41 #endif
42
43 #define _FP_FRACBITS_Q 113
44 #define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
45 #define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
46 #define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
47 #define _FP_EXPBITS_Q 15
48 #define _FP_EXPBIAS_Q 16383
49 #define _FP_EXPMAX_Q 32767
50
51 #define _FP_QNANBIT_Q \
52 ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
53 #define _FP_QNANBIT_SH_Q \
54 ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
55 #define _FP_IMPLBIT_Q \
56 ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
57 #define _FP_IMPLBIT_SH_Q \
58 ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
59 #define _FP_OVERFLOW_Q \
60 ((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
61
62 typedef float TFtype __attribute__((mode(TF)));
63
64 #if _FP_W_TYPE_SIZE < 64
65
66 union _FP_UNION_Q
67 {
68 TFtype flt;
69 struct
70 {
71 #if __BYTE_ORDER == __BIG_ENDIAN
72 unsigned sign : 1;
73 unsigned exp : _FP_EXPBITS_Q;
74 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
75 unsigned long frac2 : _FP_W_TYPE_SIZE;
76 unsigned long frac1 : _FP_W_TYPE_SIZE;
77 unsigned long frac0 : _FP_W_TYPE_SIZE;
78 #else
79 unsigned long frac0 : _FP_W_TYPE_SIZE;
80 unsigned long frac1 : _FP_W_TYPE_SIZE;
81 unsigned long frac2 : _FP_W_TYPE_SIZE;
82 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
83 unsigned exp : _FP_EXPBITS_Q;
84 unsigned sign : 1;
85 #endif /* not bigendian */
86 } bits __attribute__((packed));
87 };
88
89
90 #define FP_DECL_Q(X) _FP_DECL(4,X)
91 #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_4(Q,X,val)
92 #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_4_P(Q,X,val)
93 #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_4(Q,val,X)
94 #define FP_PACK_RAW_QP(val,X) \
95 do { \
96 if (!FP_INHIBIT_RESULTS) \
97 _FP_PACK_RAW_4_P(Q,val,X); \
98 } while (0)
99
100 #define FP_UNPACK_Q(X,val) \
101 do { \
102 _FP_UNPACK_RAW_4(Q,X,val); \
103 _FP_UNPACK_CANONICAL(Q,4,X); \
104 } while (0)
105
106 #define FP_UNPACK_QP(X,val) \
107 do { \
108 _FP_UNPACK_RAW_4_P(Q,X,val); \
109 _FP_UNPACK_CANONICAL(Q,4,X); \
110 } while (0)
111
112 #define FP_UNPACK_SEMIRAW_Q(X,val) \
113 do { \
114 _FP_UNPACK_RAW_4(Q,X,val); \
115 _FP_UNPACK_SEMIRAW(Q,4,X); \
116 } while (0)
117
118 #define FP_UNPACK_SEMIRAW_QP(X,val) \
119 do { \
120 _FP_UNPACK_RAW_4_P(Q,X,val); \
121 _FP_UNPACK_SEMIRAW(Q,4,X); \
122 } while (0)
123
124 #define FP_PACK_Q(val,X) \
125 do { \
126 _FP_PACK_CANONICAL(Q,4,X); \
127 _FP_PACK_RAW_4(Q,val,X); \
128 } while (0)
129
130 #define FP_PACK_QP(val,X) \
131 do { \
132 _FP_PACK_CANONICAL(Q,4,X); \
133 if (!FP_INHIBIT_RESULTS) \
134 _FP_PACK_RAW_4_P(Q,val,X); \
135 } while (0)
136
137 #define FP_PACK_SEMIRAW_Q(val,X) \
138 do { \
139 _FP_PACK_SEMIRAW(Q,4,X); \
140 _FP_PACK_RAW_4(Q,val,X); \
141 } while (0)
142
143 #define FP_PACK_SEMIRAW_QP(val,X) \
144 do { \
145 _FP_PACK_SEMIRAW(Q,4,X); \
146 if (!FP_INHIBIT_RESULTS) \
147 _FP_PACK_RAW_4_P(Q,val,X); \
148 } while (0)
149
150 #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,4,X)
151 #define FP_NEG_Q(R,X) _FP_NEG(Q,4,R,X)
152 #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,4,R,X,Y)
153 #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,4,R,X,Y)
154 #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,4,R,X,Y)
155 #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,4,R,X,Y)
156 #define FP_SQRT_Q(R,X) _FP_SQRT(Q,4,R,X)
157 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_4(R,S,T,X,Q)
158
159 #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,4,r,X,Y,un)
160 #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,4,r,X,Y)
161 #define FP_CMP_UNORD_Q(r,X,Y) _FP_CMP_UNORD(Q,4,r,X,Y)
162
163 #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,4,r,X,rsz,rsg)
164 #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,4,X,r,rs,rt)
165
166 #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4(X)
167 #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4(X)
168
169 #else /* not _FP_W_TYPE_SIZE < 64 */
170 union _FP_UNION_Q
171 {
172 TFtype flt /* __attribute__((mode(TF))) */ ;
173 struct {
174 _FP_W_TYPE a, b;
175 } longs;
176 struct {
177 #if __BYTE_ORDER == __BIG_ENDIAN
178 unsigned sign : 1;
179 unsigned exp : _FP_EXPBITS_Q;
180 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
181 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
182 #else
183 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
184 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
185 unsigned exp : _FP_EXPBITS_Q;
186 unsigned sign : 1;
187 #endif
188 } bits;
189 };
190
191 #define FP_DECL_Q(X) _FP_DECL(2,X)
192 #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_2(Q,X,val)
193 #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_2_P(Q,X,val)
194 #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_2(Q,val,X)
195 #define FP_PACK_RAW_QP(val,X) \
196 do { \
197 if (!FP_INHIBIT_RESULTS) \
198 _FP_PACK_RAW_2_P(Q,val,X); \
199 } while (0)
200
201 #define FP_UNPACK_Q(X,val) \
202 do { \
203 _FP_UNPACK_RAW_2(Q,X,val); \
204 _FP_UNPACK_CANONICAL(Q,2,X); \
205 } while (0)
206
207 #define FP_UNPACK_QP(X,val) \
208 do { \
209 _FP_UNPACK_RAW_2_P(Q,X,val); \
210 _FP_UNPACK_CANONICAL(Q,2,X); \
211 } while (0)
212
213 #define FP_UNPACK_SEMIRAW_Q(X,val) \
214 do { \
215 _FP_UNPACK_RAW_2(Q,X,val); \
216 _FP_UNPACK_SEMIRAW(Q,2,X); \
217 } while (0)
218
219 #define FP_UNPACK_SEMIRAW_QP(X,val) \
220 do { \
221 _FP_UNPACK_RAW_2_P(Q,X,val); \
222 _FP_UNPACK_SEMIRAW(Q,2,X); \
223 } while (0)
224
225 #define FP_PACK_Q(val,X) \
226 do { \
227 _FP_PACK_CANONICAL(Q,2,X); \
228 _FP_PACK_RAW_2(Q,val,X); \
229 } while (0)
230
231 #define FP_PACK_QP(val,X) \
232 do { \
233 _FP_PACK_CANONICAL(Q,2,X); \
234 if (!FP_INHIBIT_RESULTS) \
235 _FP_PACK_RAW_2_P(Q,val,X); \
236 } while (0)
237
238 #define FP_PACK_SEMIRAW_Q(val,X) \
239 do { \
240 _FP_PACK_SEMIRAW(Q,2,X); \
241 _FP_PACK_RAW_2(Q,val,X); \
242 } while (0)
243
244 #define FP_PACK_SEMIRAW_QP(val,X) \
245 do { \
246 _FP_PACK_SEMIRAW(Q,2,X); \
247 if (!FP_INHIBIT_RESULTS) \
248 _FP_PACK_RAW_2_P(Q,val,X); \
249 } while (0)
250
251 #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,2,X)
252 #define FP_NEG_Q(R,X) _FP_NEG(Q,2,R,X)
253 #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,2,R,X,Y)
254 #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,2,R,X,Y)
255 #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,2,R,X,Y)
256 #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,2,R,X,Y)
257 #define FP_SQRT_Q(R,X) _FP_SQRT(Q,2,R,X)
258 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
259
260 #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,2,r,X,Y,un)
261 #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,2,r,X,Y)
262 #define FP_CMP_UNORD_Q(r,X,Y) _FP_CMP_UNORD(Q,2,r,X,Y)
263
264 #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,2,r,X,rsz,rsg)
265 #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,2,X,r,rs,rt)
266
267 #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2(X)
268 #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2(X)
269
270 #endif /* not _FP_W_TYPE_SIZE < 64 */