]> git.ipfire.org Git - thirdparty/glibc.git/blame - soft-fp/quad.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / soft-fp / quad.h
CommitLineData
d876f532
UD
1/* Software floating-point emulation.
2 Definitions for IEEE Quad Precision.
d614a753 3 Copyright (C) 1997-2020 Free Software Foundation, Inc.
d876f532
UD
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
41bdb6e2
AJ
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.
d876f532 14
638a783c
RM
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
d876f532
UD
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
41bdb6e2 27 Lesser General Public License for more details.
d876f532 28
41bdb6e2 29 You should have received a copy of the GNU Lesser General Public
59ba27a6 30 License along with the GNU C Library; if not, see
5a82c748 31 <https://www.gnu.org/licenses/>. */
d876f532 32
a2f8be9c
JM
33#ifndef SOFT_FP_QUAD_H
34#define SOFT_FP_QUAD_H 1
35
d876f532 36#if _FP_W_TYPE_SIZE < 32
71b4dea7 37# error "Here's a nickel, kid. Go buy yourself a real computer."
d876f532
UD
38#endif
39
40#if _FP_W_TYPE_SIZE < 64
71b4dea7
JM
41# define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
42# define _FP_FRACTBITS_DW_Q (8*_FP_W_TYPE_SIZE)
d876f532 43#else
71b4dea7
JM
44# define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
45# define _FP_FRACTBITS_DW_Q (4*_FP_W_TYPE_SIZE)
d876f532
UD
46#endif
47
48#define _FP_FRACBITS_Q 113
49#define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
50#define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
51#define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
52#define _FP_EXPBITS_Q 15
53#define _FP_EXPBIAS_Q 16383
54#define _FP_EXPMAX_Q 32767
55
56#define _FP_QNANBIT_Q \
51ca9e29 57 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
fe0b1e85 58#define _FP_QNANBIT_SH_Q \
51ca9e29 59 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
d876f532 60#define _FP_IMPLBIT_Q \
51ca9e29 61 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
fe0b1e85 62#define _FP_IMPLBIT_SH_Q \
51ca9e29 63 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
d876f532 64#define _FP_OVERFLOW_Q \
51ca9e29 65 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
d876f532 66
77f01ab5
JM
67#define _FP_WFRACBITS_DW_Q (2 * _FP_WFRACBITS_Q)
68#define _FP_WFRACXBITS_DW_Q (_FP_FRACTBITS_DW_Q - _FP_WFRACBITS_DW_Q)
69#define _FP_HIGHBIT_DW_Q \
51ca9e29 70 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_Q - 1) % _FP_W_TYPE_SIZE)
77f01ab5 71
51ca9e29 72typedef float TFtype __attribute__ ((mode (TF)));
fe0b1e85 73
d876f532
UD
74#if _FP_W_TYPE_SIZE < 64
75
76union _FP_UNION_Q
77{
1e145589
JM
78 TFtype flt;
79 struct _FP_STRUCT_LAYOUT
80 {
71b4dea7 81# if __BYTE_ORDER == __BIG_ENDIAN
1e145589
JM
82 unsigned sign : 1;
83 unsigned exp : _FP_EXPBITS_Q;
84 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
85 unsigned long frac2 : _FP_W_TYPE_SIZE;
86 unsigned long frac1 : _FP_W_TYPE_SIZE;
87 unsigned long frac0 : _FP_W_TYPE_SIZE;
71b4dea7 88# else
1e145589
JM
89 unsigned long frac0 : _FP_W_TYPE_SIZE;
90 unsigned long frac1 : _FP_W_TYPE_SIZE;
91 unsigned long frac2 : _FP_W_TYPE_SIZE;
92 unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
93 unsigned exp : _FP_EXPBITS_Q;
94 unsigned sign : 1;
71b4dea7 95# endif /* not bigendian */
049375e2 96 } bits;
d876f532
UD
97};
98
99
51ca9e29 100# define FP_DECL_Q(X) _FP_DECL (4, X)
5c0508a3
JM
101# define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_4 (Q, X, (val))
102# define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_4_P (Q, X, (val))
103# define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_4 (Q, (val), X)
51ca9e29 104# define FP_PACK_RAW_QP(val, X) \
1e145589
JM
105 do \
106 { \
107 if (!FP_INHIBIT_RESULTS) \
5c0508a3 108 _FP_PACK_RAW_4_P (Q, (val), X); \
1e145589
JM
109 } \
110 while (0)
111
51ca9e29 112# define FP_UNPACK_Q(X, val) \
1e145589
JM
113 do \
114 { \
5c0508a3 115 _FP_UNPACK_RAW_4 (Q, X, (val)); \
51ca9e29 116 _FP_UNPACK_CANONICAL (Q, 4, X); \
1e145589
JM
117 } \
118 while (0)
119
51ca9e29 120# define FP_UNPACK_QP(X, val) \
1e145589
JM
121 do \
122 { \
5c0508a3 123 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
51ca9e29 124 _FP_UNPACK_CANONICAL (Q, 4, X); \
1e145589
JM
125 } \
126 while (0)
127
51ca9e29 128# define FP_UNPACK_SEMIRAW_Q(X, val) \
1e145589
JM
129 do \
130 { \
5c0508a3 131 _FP_UNPACK_RAW_4 (Q, X, (val)); \
51ca9e29 132 _FP_UNPACK_SEMIRAW (Q, 4, X); \
1e145589
JM
133 } \
134 while (0)
135
51ca9e29 136# define FP_UNPACK_SEMIRAW_QP(X, val) \
1e145589
JM
137 do \
138 { \
5c0508a3 139 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
51ca9e29 140 _FP_UNPACK_SEMIRAW (Q, 4, X); \
1e145589
JM
141 } \
142 while (0)
143
51ca9e29 144# define FP_PACK_Q(val, X) \
1e145589
JM
145 do \
146 { \
51ca9e29 147 _FP_PACK_CANONICAL (Q, 4, X); \
5c0508a3 148 _FP_PACK_RAW_4 (Q, (val), X); \
1e145589
JM
149 } \
150 while (0)
151
51ca9e29 152# define FP_PACK_QP(val, X) \
1e145589
JM
153 do \
154 { \
51ca9e29 155 _FP_PACK_CANONICAL (Q, 4, X); \
1e145589 156 if (!FP_INHIBIT_RESULTS) \
5c0508a3 157 _FP_PACK_RAW_4_P (Q, (val), X); \
1e145589
JM
158 } \
159 while (0)
160
51ca9e29 161# define FP_PACK_SEMIRAW_Q(val, X) \
1e145589
JM
162 do \
163 { \
51ca9e29 164 _FP_PACK_SEMIRAW (Q, 4, X); \
5c0508a3 165 _FP_PACK_RAW_4 (Q, (val), X); \
1e145589
JM
166 } \
167 while (0)
168
51ca9e29 169# define FP_PACK_SEMIRAW_QP(val, X) \
1e145589
JM
170 do \
171 { \
51ca9e29 172 _FP_PACK_SEMIRAW (Q, 4, X); \
1e145589 173 if (!FP_INHIBIT_RESULTS) \
5c0508a3 174 _FP_PACK_RAW_4_P (Q, (val), X); \
1e145589
JM
175 } \
176 while (0)
fe0b1e85 177
51ca9e29
JM
178# define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 4, X)
179# define FP_NEG_Q(R, X) _FP_NEG (Q, 4, R, X)
180# define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 4, R, X, Y)
181# define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 4, R, X, Y)
182# define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 4, R, X, Y)
183# define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 4, R, X, Y)
184# define FP_SQRT_Q(R, X) _FP_SQRT (Q, 4, R, X)
5c0508a3 185# define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_4 (R, S, T, X, (Q))
51ca9e29 186# define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 4, 8, R, X, Y, Z)
d876f532 187
5c0508a3
JM
188# define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 4, (r), X, Y, (un), (ex))
189# define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 4, (r), X, Y, (ex))
190# define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 4, (r), X, Y, (ex))
d876f532 191
5c0508a3 192# define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 4, (r), X, (rsz), (rsg))
2004e7fb
JM
193# define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
194 _FP_TO_INT_ROUND (Q, 4, (r), X, (rsz), (rsg))
5c0508a3 195# define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 4, X, (r), (rs), rt)
d876f532 196
51ca9e29
JM
197# define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4 (X)
198# define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4 (X)
d876f532 199
51ca9e29 200# define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_8 (X)
77f01ab5 201
d876f532
UD
202#else /* not _FP_W_TYPE_SIZE < 64 */
203union _FP_UNION_Q
204{
51ca9e29 205 TFtype flt /* __attribute__ ((mode (TF))) */ ;
1e145589
JM
206 struct _FP_STRUCT_LAYOUT
207 {
a598e3fc
RH
208 _FP_W_TYPE a, b;
209 } longs;
1e145589
JM
210 struct _FP_STRUCT_LAYOUT
211 {
71b4dea7 212# if __BYTE_ORDER == __BIG_ENDIAN
06029c20
JJ
213 unsigned sign : 1;
214 unsigned exp : _FP_EXPBITS_Q;
215 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
216 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
71b4dea7 217# else
06029c20
JJ
218 _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
219 _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
220 unsigned exp : _FP_EXPBITS_Q;
221 unsigned sign : 1;
71b4dea7 222# endif
d876f532
UD
223 } bits;
224};
225
51ca9e29 226# define FP_DECL_Q(X) _FP_DECL (2, X)
5c0508a3
JM
227# define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_2 (Q, X, (val))
228# define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_2_P (Q, X, (val))
229# define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_2 (Q, (val), X)
51ca9e29 230# define FP_PACK_RAW_QP(val, X) \
1e145589
JM
231 do \
232 { \
233 if (!FP_INHIBIT_RESULTS) \
5c0508a3 234 _FP_PACK_RAW_2_P (Q, (val), X); \
1e145589
JM
235 } \
236 while (0)
237
51ca9e29 238# define FP_UNPACK_Q(X, val) \
1e145589
JM
239 do \
240 { \
5c0508a3 241 _FP_UNPACK_RAW_2 (Q, X, (val)); \
51ca9e29 242 _FP_UNPACK_CANONICAL (Q, 2, X); \
1e145589
JM
243 } \
244 while (0)
245
51ca9e29 246# define FP_UNPACK_QP(X, val) \
1e145589
JM
247 do \
248 { \
5c0508a3 249 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
51ca9e29 250 _FP_UNPACK_CANONICAL (Q, 2, X); \
1e145589
JM
251 } \
252 while (0)
253
51ca9e29 254# define FP_UNPACK_SEMIRAW_Q(X, val) \
1e145589
JM
255 do \
256 { \
5c0508a3 257 _FP_UNPACK_RAW_2 (Q, X, (val)); \
51ca9e29 258 _FP_UNPACK_SEMIRAW (Q, 2, X); \
1e145589
JM
259 } \
260 while (0)
261
51ca9e29 262# define FP_UNPACK_SEMIRAW_QP(X, val) \
1e145589
JM
263 do \
264 { \
5c0508a3 265 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
51ca9e29 266 _FP_UNPACK_SEMIRAW (Q, 2, X); \
1e145589
JM
267 } \
268 while (0)
269
51ca9e29 270# define FP_PACK_Q(val, X) \
1e145589
JM
271 do \
272 { \
51ca9e29 273 _FP_PACK_CANONICAL (Q, 2, X); \
5c0508a3 274 _FP_PACK_RAW_2 (Q, (val), X); \
1e145589
JM
275 } \
276 while (0)
277
51ca9e29 278# define FP_PACK_QP(val, X) \
1e145589
JM
279 do \
280 { \
51ca9e29 281 _FP_PACK_CANONICAL (Q, 2, X); \
1e145589 282 if (!FP_INHIBIT_RESULTS) \
5c0508a3 283 _FP_PACK_RAW_2_P (Q, (val), X); \
1e145589
JM
284 } \
285 while (0)
286
51ca9e29 287# define FP_PACK_SEMIRAW_Q(val, X) \
1e145589
JM
288 do \
289 { \
51ca9e29 290 _FP_PACK_SEMIRAW (Q, 2, X); \
5c0508a3 291 _FP_PACK_RAW_2 (Q, (val), X); \
1e145589
JM
292 } \
293 while (0)
294
51ca9e29 295# define FP_PACK_SEMIRAW_QP(val, X) \
1e145589
JM
296 do \
297 { \
51ca9e29 298 _FP_PACK_SEMIRAW (Q, 2, X); \
1e145589 299 if (!FP_INHIBIT_RESULTS) \
5c0508a3 300 _FP_PACK_RAW_2_P (Q, (val), X); \
1e145589
JM
301 } \
302 while (0)
fe0b1e85 303
51ca9e29
JM
304# define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 2, X)
305# define FP_NEG_Q(R, X) _FP_NEG (Q, 2, R, X)
306# define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 2, R, X, Y)
307# define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 2, R, X, Y)
308# define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 2, R, X, Y)
309# define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 2, R, X, Y)
310# define FP_SQRT_Q(R, X) _FP_SQRT (Q, 2, R, X)
5c0508a3 311# define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_2 (R, S, T, X, (Q))
51ca9e29 312# define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 2, 4, R, X, Y, Z)
d876f532 313
5c0508a3
JM
314# define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 2, (r), X, Y, (un), (ex))
315# define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 2, (r), X, Y, (ex))
316# define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 2, (r), X, Y, (ex))
d876f532 317
5c0508a3 318# define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 2, (r), X, (rsz), (rsg))
2004e7fb
JM
319# define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
320 _FP_TO_INT_ROUND (Q, 2, (r), X, (rsz), (rsg))
5c0508a3 321# define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 2, X, (r), (rs), rt)
d876f532 322
51ca9e29
JM
323# define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2 (X)
324# define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2 (X)
d876f532 325
51ca9e29 326# define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_4 (X)
77f01ab5 327
d876f532 328#endif /* not _FP_W_TYPE_SIZE < 64 */
a2f8be9c
JM
329
330#endif /* !SOFT_FP_QUAD_H */