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