2015-02-18 Steve Ellcey <sellcey@imgtec.com>
[glibc.git] / soft-fp / quad.h
blob78387fc75b16d2682e1e26b7323df72c498f3a20
1 /* Software floating-point emulation.
2 Definitions for IEEE Quad Precision.
3 Copyright (C) 1997-2015 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).
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.
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.)
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.
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/>. */
33 #if _FP_W_TYPE_SIZE < 32
34 # error "Here's a nickel, kid. Go buy yourself a real computer."
35 #endif
37 #if _FP_W_TYPE_SIZE < 64
38 # define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
39 # define _FP_FRACTBITS_DW_Q (8*_FP_W_TYPE_SIZE)
40 #else
41 # define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
42 # define _FP_FRACTBITS_DW_Q (4*_FP_W_TYPE_SIZE)
43 #endif
45 #define _FP_FRACBITS_Q 113
46 #define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
47 #define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
48 #define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
49 #define _FP_EXPBITS_Q 15
50 #define _FP_EXPBIAS_Q 16383
51 #define _FP_EXPMAX_Q 32767
53 #define _FP_QNANBIT_Q \
54 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
55 #define _FP_QNANBIT_SH_Q \
56 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
57 #define _FP_IMPLBIT_Q \
58 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
59 #define _FP_IMPLBIT_SH_Q \
60 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
61 #define _FP_OVERFLOW_Q \
62 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
64 #define _FP_WFRACBITS_DW_Q (2 * _FP_WFRACBITS_Q)
65 #define _FP_WFRACXBITS_DW_Q (_FP_FRACTBITS_DW_Q - _FP_WFRACBITS_DW_Q)
66 #define _FP_HIGHBIT_DW_Q \
67 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_Q - 1) % _FP_W_TYPE_SIZE)
69 typedef float TFtype __attribute__ ((mode (TF)));
71 #if _FP_W_TYPE_SIZE < 64
73 union _FP_UNION_Q
75 TFtype flt;
76 struct _FP_STRUCT_LAYOUT
78 # if __BYTE_ORDER == __BIG_ENDIAN
79 unsigned sign : 1;
80 unsigned exp : _FP_EXPBITS_Q;
81 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
82 unsigned long frac2 : _FP_W_TYPE_SIZE;
83 unsigned long frac1 : _FP_W_TYPE_SIZE;
84 unsigned long frac0 : _FP_W_TYPE_SIZE;
85 # else
86 unsigned long frac0 : _FP_W_TYPE_SIZE;
87 unsigned long frac1 : _FP_W_TYPE_SIZE;
88 unsigned long frac2 : _FP_W_TYPE_SIZE;
89 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
90 unsigned exp : _FP_EXPBITS_Q;
91 unsigned sign : 1;
92 # endif /* not bigendian */
93 } bits __attribute__ ((packed));
97 # define FP_DECL_Q(X) _FP_DECL (4, X)
98 # define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_4 (Q, X, (val))
99 # define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_4_P (Q, X, (val))
100 # define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_4 (Q, (val), X)
101 # define FP_PACK_RAW_QP(val, X) \
102 do \
104 if (!FP_INHIBIT_RESULTS) \
105 _FP_PACK_RAW_4_P (Q, (val), X); \
107 while (0)
109 # define FP_UNPACK_Q(X, val) \
110 do \
112 _FP_UNPACK_RAW_4 (Q, X, (val)); \
113 _FP_UNPACK_CANONICAL (Q, 4, X); \
115 while (0)
117 # define FP_UNPACK_QP(X, val) \
118 do \
120 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
121 _FP_UNPACK_CANONICAL (Q, 4, X); \
123 while (0)
125 # define FP_UNPACK_SEMIRAW_Q(X, val) \
126 do \
128 _FP_UNPACK_RAW_4 (Q, X, (val)); \
129 _FP_UNPACK_SEMIRAW (Q, 4, X); \
131 while (0)
133 # define FP_UNPACK_SEMIRAW_QP(X, val) \
134 do \
136 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
137 _FP_UNPACK_SEMIRAW (Q, 4, X); \
139 while (0)
141 # define FP_PACK_Q(val, X) \
142 do \
144 _FP_PACK_CANONICAL (Q, 4, X); \
145 _FP_PACK_RAW_4 (Q, (val), X); \
147 while (0)
149 # define FP_PACK_QP(val, X) \
150 do \
152 _FP_PACK_CANONICAL (Q, 4, X); \
153 if (!FP_INHIBIT_RESULTS) \
154 _FP_PACK_RAW_4_P (Q, (val), X); \
156 while (0)
158 # define FP_PACK_SEMIRAW_Q(val, X) \
159 do \
161 _FP_PACK_SEMIRAW (Q, 4, X); \
162 _FP_PACK_RAW_4 (Q, (val), X); \
164 while (0)
166 # define FP_PACK_SEMIRAW_QP(val, X) \
167 do \
169 _FP_PACK_SEMIRAW (Q, 4, X); \
170 if (!FP_INHIBIT_RESULTS) \
171 _FP_PACK_RAW_4_P (Q, (val), X); \
173 while (0)
175 # define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 4, X)
176 # define FP_NEG_Q(R, X) _FP_NEG (Q, 4, R, X)
177 # define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 4, R, X, Y)
178 # define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 4, R, X, Y)
179 # define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 4, R, X, Y)
180 # define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 4, R, X, Y)
181 # define FP_SQRT_Q(R, X) _FP_SQRT (Q, 4, R, X)
182 # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_4 (R, S, T, X, (Q))
183 # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 4, 8, R, X, Y, Z)
185 # define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 4, (r), X, Y, (un), (ex))
186 # define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 4, (r), X, Y, (ex))
187 # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 4, (r), X, Y, (ex))
189 # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 4, (r), X, (rsz), (rsg))
190 # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
191 _FP_TO_INT_ROUND (Q, 4, (r), X, (rsz), (rsg))
192 # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 4, X, (r), (rs), rt)
194 # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4 (X)
195 # define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4 (X)
197 # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_8 (X)
199 #else /* not _FP_W_TYPE_SIZE < 64 */
200 union _FP_UNION_Q
202 TFtype flt /* __attribute__ ((mode (TF))) */ ;
203 struct _FP_STRUCT_LAYOUT
205 _FP_W_TYPE a, b;
206 } longs;
207 struct _FP_STRUCT_LAYOUT
209 # if __BYTE_ORDER == __BIG_ENDIAN
210 unsigned sign : 1;
211 unsigned exp : _FP_EXPBITS_Q;
212 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
213 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
214 # else
215 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
216 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
217 unsigned exp : _FP_EXPBITS_Q;
218 unsigned sign : 1;
219 # endif
220 } bits;
223 # define FP_DECL_Q(X) _FP_DECL (2, X)
224 # define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_2 (Q, X, (val))
225 # define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_2_P (Q, X, (val))
226 # define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_2 (Q, (val), X)
227 # define FP_PACK_RAW_QP(val, X) \
228 do \
230 if (!FP_INHIBIT_RESULTS) \
231 _FP_PACK_RAW_2_P (Q, (val), X); \
233 while (0)
235 # define FP_UNPACK_Q(X, val) \
236 do \
238 _FP_UNPACK_RAW_2 (Q, X, (val)); \
239 _FP_UNPACK_CANONICAL (Q, 2, X); \
241 while (0)
243 # define FP_UNPACK_QP(X, val) \
244 do \
246 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
247 _FP_UNPACK_CANONICAL (Q, 2, X); \
249 while (0)
251 # define FP_UNPACK_SEMIRAW_Q(X, val) \
252 do \
254 _FP_UNPACK_RAW_2 (Q, X, (val)); \
255 _FP_UNPACK_SEMIRAW (Q, 2, X); \
257 while (0)
259 # define FP_UNPACK_SEMIRAW_QP(X, val) \
260 do \
262 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
263 _FP_UNPACK_SEMIRAW (Q, 2, X); \
265 while (0)
267 # define FP_PACK_Q(val, X) \
268 do \
270 _FP_PACK_CANONICAL (Q, 2, X); \
271 _FP_PACK_RAW_2 (Q, (val), X); \
273 while (0)
275 # define FP_PACK_QP(val, X) \
276 do \
278 _FP_PACK_CANONICAL (Q, 2, X); \
279 if (!FP_INHIBIT_RESULTS) \
280 _FP_PACK_RAW_2_P (Q, (val), X); \
282 while (0)
284 # define FP_PACK_SEMIRAW_Q(val, X) \
285 do \
287 _FP_PACK_SEMIRAW (Q, 2, X); \
288 _FP_PACK_RAW_2 (Q, (val), X); \
290 while (0)
292 # define FP_PACK_SEMIRAW_QP(val, X) \
293 do \
295 _FP_PACK_SEMIRAW (Q, 2, X); \
296 if (!FP_INHIBIT_RESULTS) \
297 _FP_PACK_RAW_2_P (Q, (val), X); \
299 while (0)
301 # define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 2, X)
302 # define FP_NEG_Q(R, X) _FP_NEG (Q, 2, R, X)
303 # define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 2, R, X, Y)
304 # define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 2, R, X, Y)
305 # define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 2, R, X, Y)
306 # define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 2, R, X, Y)
307 # define FP_SQRT_Q(R, X) _FP_SQRT (Q, 2, R, X)
308 # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_2 (R, S, T, X, (Q))
309 # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 2, 4, R, X, Y, Z)
311 # define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 2, (r), X, Y, (un), (ex))
312 # define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 2, (r), X, Y, (ex))
313 # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 2, (r), X, Y, (ex))
315 # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 2, (r), X, (rsz), (rsg))
316 # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
317 _FP_TO_INT_ROUND (Q, 2, (r), X, (rsz), (rsg))
318 # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 2, X, (r), (rs), rt)
320 # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2 (X)
321 # define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2 (X)
323 # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_4 (X)
325 #endif /* not _FP_W_TYPE_SIZE < 64 */