1 /* Software floating-point emulation.
2 Definitions for IEEE Quad Precision.
3 Copyright (C) 1997-2020 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 <https://www.gnu.org/licenses/>. */
33 #ifndef SOFT_FP_QUAD_H
34 #define SOFT_FP_QUAD_H 1
36 #if _FP_W_TYPE_SIZE < 32
37 # error "Here's a nickel, kid. Go buy yourself a real computer."
40 #if _FP_W_TYPE_SIZE < 64
41 # define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
42 # define _FP_FRACTBITS_DW_Q (8*_FP_W_TYPE_SIZE)
44 # define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
45 # define _FP_FRACTBITS_DW_Q (4*_FP_W_TYPE_SIZE)
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
56 #define _FP_QNANBIT_Q \
57 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
58 #define _FP_QNANBIT_SH_Q \
59 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
60 #define _FP_IMPLBIT_Q \
61 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
62 #define _FP_IMPLBIT_SH_Q \
63 ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
64 #define _FP_OVERFLOW_Q \
65 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
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 \
70 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_Q - 1) % _FP_W_TYPE_SIZE)
72 typedef float TFtype
__attribute__ ((mode (TF
)));
74 #if _FP_W_TYPE_SIZE < 64
79 struct _FP_STRUCT_LAYOUT
81 # if __BYTE_ORDER == __BIG_ENDIAN
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
;
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
;
95 # endif /* not bigendian */
100 # define FP_DECL_Q(X) _FP_DECL (4, X)
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)
104 # define FP_PACK_RAW_QP(val, X) \
107 if (!FP_INHIBIT_RESULTS) \
108 _FP_PACK_RAW_4_P (Q, (val), X); \
112 # define FP_UNPACK_Q(X, val) \
115 _FP_UNPACK_RAW_4 (Q, X, (val)); \
116 _FP_UNPACK_CANONICAL (Q, 4, X); \
120 # define FP_UNPACK_QP(X, val) \
123 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
124 _FP_UNPACK_CANONICAL (Q, 4, X); \
128 # define FP_UNPACK_SEMIRAW_Q(X, val) \
131 _FP_UNPACK_RAW_4 (Q, X, (val)); \
132 _FP_UNPACK_SEMIRAW (Q, 4, X); \
136 # define FP_UNPACK_SEMIRAW_QP(X, val) \
139 _FP_UNPACK_RAW_4_P (Q, X, (val)); \
140 _FP_UNPACK_SEMIRAW (Q, 4, X); \
144 # define FP_PACK_Q(val, X) \
147 _FP_PACK_CANONICAL (Q, 4, X); \
148 _FP_PACK_RAW_4 (Q, (val), X); \
152 # define FP_PACK_QP(val, X) \
155 _FP_PACK_CANONICAL (Q, 4, X); \
156 if (!FP_INHIBIT_RESULTS) \
157 _FP_PACK_RAW_4_P (Q, (val), X); \
161 # define FP_PACK_SEMIRAW_Q(val, X) \
164 _FP_PACK_SEMIRAW (Q, 4, X); \
165 _FP_PACK_RAW_4 (Q, (val), X); \
169 # define FP_PACK_SEMIRAW_QP(val, X) \
172 _FP_PACK_SEMIRAW (Q, 4, X); \
173 if (!FP_INHIBIT_RESULTS) \
174 _FP_PACK_RAW_4_P (Q, (val), X); \
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)
185 # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_4 (R, S, T, X, (Q))
186 # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 4, 8, R, X, Y, Z)
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))
192 # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 4, (r), X, (rsz), (rsg))
193 # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
194 _FP_TO_INT_ROUND (Q, 4, (r), X, (rsz), (rsg))
195 # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 4, X, (r), (rs), rt)
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)
200 # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_8 (X)
202 #else /* not _FP_W_TYPE_SIZE < 64 */
205 TFtype flt
/* __attribute__ ((mode (TF))) */ ;
206 struct _FP_STRUCT_LAYOUT
210 struct _FP_STRUCT_LAYOUT
212 # if __BYTE_ORDER == __BIG_ENDIAN
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
;
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
;
226 # define FP_DECL_Q(X) _FP_DECL (2, X)
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)
230 # define FP_PACK_RAW_QP(val, X) \
233 if (!FP_INHIBIT_RESULTS) \
234 _FP_PACK_RAW_2_P (Q, (val), X); \
238 # define FP_UNPACK_Q(X, val) \
241 _FP_UNPACK_RAW_2 (Q, X, (val)); \
242 _FP_UNPACK_CANONICAL (Q, 2, X); \
246 # define FP_UNPACK_QP(X, val) \
249 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
250 _FP_UNPACK_CANONICAL (Q, 2, X); \
254 # define FP_UNPACK_SEMIRAW_Q(X, val) \
257 _FP_UNPACK_RAW_2 (Q, X, (val)); \
258 _FP_UNPACK_SEMIRAW (Q, 2, X); \
262 # define FP_UNPACK_SEMIRAW_QP(X, val) \
265 _FP_UNPACK_RAW_2_P (Q, X, (val)); \
266 _FP_UNPACK_SEMIRAW (Q, 2, X); \
270 # define FP_PACK_Q(val, X) \
273 _FP_PACK_CANONICAL (Q, 2, X); \
274 _FP_PACK_RAW_2 (Q, (val), X); \
278 # define FP_PACK_QP(val, X) \
281 _FP_PACK_CANONICAL (Q, 2, X); \
282 if (!FP_INHIBIT_RESULTS) \
283 _FP_PACK_RAW_2_P (Q, (val), X); \
287 # define FP_PACK_SEMIRAW_Q(val, X) \
290 _FP_PACK_SEMIRAW (Q, 2, X); \
291 _FP_PACK_RAW_2 (Q, (val), X); \
295 # define FP_PACK_SEMIRAW_QP(val, X) \
298 _FP_PACK_SEMIRAW (Q, 2, X); \
299 if (!FP_INHIBIT_RESULTS) \
300 _FP_PACK_RAW_2_P (Q, (val), X); \
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)
311 # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_2 (R, S, T, X, (Q))
312 # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 2, 4, R, X, Y, Z)
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))
318 # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 2, (r), X, (rsz), (rsg))
319 # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
320 _FP_TO_INT_ROUND (Q, 2, (r), X, (rsz), (rsg))
321 # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 2, X, (r), (rs), rt)
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)
326 # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_4 (X)
328 #endif /* not _FP_W_TYPE_SIZE < 64 */
330 #endif /* !SOFT_FP_QUAD_H */