File: /usr/src/linux/include/math-emu/quad.h

1     /* Software floating-point emulation.
2        Definitions for IEEE Quad Precision.
3        Copyright (C) 1997,1998,1999 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 Library General Public License as
12        published by the Free Software Foundation; either version 2 of the
13        License, or (at your option) any later version.
14     
15        The GNU C Library is distributed in the hope that it will be useful,
16        but WITHOUT ANY WARRANTY; without even the implied warranty of
17        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18        Library General Public License for more details.
19     
20        You should have received a copy of the GNU Library General Public
21        License along with the GNU C Library; see the file COPYING.LIB.  If
22        not, write to the Free Software Foundation, Inc.,
23        59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
24     
25     #if _FP_W_TYPE_SIZE < 32
26     #error "Here's a nickel, kid. Go buy yourself a real computer."
27     #endif
28     
29     #if _FP_W_TYPE_SIZE < 64
30     #define _FP_FRACTBITS_Q         (4*_FP_W_TYPE_SIZE)
31     #else
32     #define _FP_FRACTBITS_Q		(2*_FP_W_TYPE_SIZE)
33     #endif
34     
35     #define _FP_FRACBITS_Q		113
36     #define _FP_FRACXBITS_Q		(_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
37     #define _FP_WFRACBITS_Q		(_FP_WORKBITS + _FP_FRACBITS_Q)
38     #define _FP_WFRACXBITS_Q	(_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
39     #define _FP_EXPBITS_Q		15
40     #define _FP_EXPBIAS_Q		16383
41     #define _FP_EXPMAX_Q		32767
42     
43     #define _FP_QNANBIT_Q		\
44     	((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
45     #define _FP_IMPLBIT_Q		\
46     	((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
47     #define _FP_OVERFLOW_Q		\
48     	((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
49     
50     #if _FP_W_TYPE_SIZE < 64
51     
52     union _FP_UNION_Q
53     {
54        long double flt;
55        struct 
56        {
57     #if __BYTE_ORDER == __BIG_ENDIAN
58           unsigned sign : 1;
59           unsigned exp : _FP_EXPBITS_Q;
60           unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
61           unsigned long frac2 : _FP_W_TYPE_SIZE;
62           unsigned long frac1 : _FP_W_TYPE_SIZE;
63           unsigned long frac0 : _FP_W_TYPE_SIZE;
64     #else
65           unsigned long frac0 : _FP_W_TYPE_SIZE;
66           unsigned long frac1 : _FP_W_TYPE_SIZE;
67           unsigned long frac2 : _FP_W_TYPE_SIZE;
68           unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
69           unsigned exp : _FP_EXPBITS_Q;
70           unsigned sign : 1;
71     #endif /* not bigendian */
72        } bits __attribute__((packed));
73     };
74     
75     
76     #define FP_DECL_Q(X)		_FP_DECL(4,X)
77     #define FP_UNPACK_RAW_Q(X,val)	_FP_UNPACK_RAW_4(Q,X,val)
78     #define FP_UNPACK_RAW_QP(X,val)	_FP_UNPACK_RAW_4_P(Q,X,val)
79     #define FP_PACK_RAW_Q(val,X)	_FP_PACK_RAW_4(Q,val,X)
80     #define FP_PACK_RAW_QP(val,X)		\
81       do {					\
82         if (!FP_INHIBIT_RESULTS)		\
83           _FP_PACK_RAW_4_P(Q,val,X);	\
84       } while (0)
85     
86     #define FP_UNPACK_Q(X,val)		\
87       do {					\
88         _FP_UNPACK_RAW_4(Q,X,val);		\
89         _FP_UNPACK_CANONICAL(Q,4,X);	\
90       } while (0)
91     
92     #define FP_UNPACK_QP(X,val)		\
93       do {					\
94         _FP_UNPACK_RAW_4_P(Q,X,val);	\
95         _FP_UNPACK_CANONICAL(Q,4,X);	\
96       } while (0)
97     
98     #define FP_PACK_Q(val,X)		\
99       do {					\
100         _FP_PACK_CANONICAL(Q,4,X);		\
101         _FP_PACK_RAW_4(Q,val,X);		\
102       } while (0)
103     
104     #define FP_PACK_QP(val,X)		\
105       do {					\
106         _FP_PACK_CANONICAL(Q,4,X);		\
107         if (!FP_INHIBIT_RESULTS)		\
108           _FP_PACK_RAW_4_P(Q,val,X);	\
109       } while (0)
110     
111     #define FP_ISSIGNAN_Q(X)		_FP_ISSIGNAN(Q,4,X)
112     #define FP_NEG_Q(R,X)			_FP_NEG(Q,4,R,X)
113     #define FP_ADD_Q(R,X,Y)			_FP_ADD(Q,4,R,X,Y)
114     #define FP_SUB_Q(R,X,Y)			_FP_SUB(Q,4,R,X,Y)
115     #define FP_MUL_Q(R,X,Y)			_FP_MUL(Q,4,R,X,Y)
116     #define FP_DIV_Q(R,X,Y)			_FP_DIV(Q,4,R,X,Y)
117     #define FP_SQRT_Q(R,X)			_FP_SQRT(Q,4,R,X)
118     #define _FP_SQRT_MEAT_Q(R,S,T,X,Q)	_FP_SQRT_MEAT_4(R,S,T,X,Q)
119     
120     #define FP_CMP_Q(r,X,Y,un)	_FP_CMP(Q,4,r,X,Y,un)
121     #define FP_CMP_EQ_Q(r,X,Y)	_FP_CMP_EQ(Q,4,r,X,Y)
122     
123     #define FP_TO_INT_Q(r,X,rsz,rsg)	_FP_TO_INT(Q,4,r,X,rsz,rsg)
124     #define FP_TO_INT_ROUND_Q(r,X,rsz,rsg)	_FP_TO_INT_ROUND(Q,4,r,X,rsz,rsg)
125     #define FP_FROM_INT_Q(X,r,rs,rt)	_FP_FROM_INT(Q,4,X,r,rs,rt)
126     
127     #define _FP_FRAC_HIGH_Q(X)	_FP_FRAC_HIGH_4(X)
128     #define _FP_FRAC_HIGH_RAW_Q(X)	_FP_FRAC_HIGH_4(X)
129     
130     #else   /* not _FP_W_TYPE_SIZE < 64 */
131     union _FP_UNION_Q
132     {
133       long double flt /* __attribute__((mode(TF))) */ ;
134       struct {
135     #if __BYTE_ORDER == __BIG_ENDIAN
136         unsigned sign  : 1;
137         unsigned exp   : _FP_EXPBITS_Q;
138         unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
139         unsigned long frac0 : _FP_W_TYPE_SIZE;
140     #else
141         unsigned long frac0 : _FP_W_TYPE_SIZE;
142         unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
143         unsigned exp   : _FP_EXPBITS_Q;
144         unsigned sign  : 1;
145     #endif
146       } bits;
147     };
148     
149     #define FP_DECL_Q(X)		_FP_DECL(2,X)
150     #define FP_UNPACK_RAW_Q(X,val)	_FP_UNPACK_RAW_2(Q,X,val)
151     #define FP_UNPACK_RAW_QP(X,val)	_FP_UNPACK_RAW_2_P(Q,X,val)
152     #define FP_PACK_RAW_Q(val,X)	_FP_PACK_RAW_2(Q,val,X)
153     #define FP_PACK_RAW_QP(val,X)		\
154       do {					\
155         if (!FP_INHIBIT_RESULTS)		\
156           _FP_PACK_RAW_2_P(Q,val,X);	\
157       } while (0)
158     
159     #define FP_UNPACK_Q(X,val)		\
160       do {					\
161         _FP_UNPACK_RAW_2(Q,X,val);		\
162         _FP_UNPACK_CANONICAL(Q,2,X);	\
163       } while (0)
164     
165     #define FP_UNPACK_QP(X,val)		\
166       do {					\
167         _FP_UNPACK_RAW_2_P(Q,X,val);	\
168         _FP_UNPACK_CANONICAL(Q,2,X);	\
169       } while (0)
170     
171     #define FP_PACK_Q(val,X)		\
172       do {					\
173         _FP_PACK_CANONICAL(Q,2,X);		\
174         _FP_PACK_RAW_2(Q,val,X);		\
175       } while (0)
176     
177     #define FP_PACK_QP(val,X)		\
178       do {					\
179         _FP_PACK_CANONICAL(Q,2,X);		\
180         if (!FP_INHIBIT_RESULTS)		\
181           _FP_PACK_RAW_2_P(Q,val,X);	\
182       } while (0)
183     
184     #define FP_ISSIGNAN_Q(X)		_FP_ISSIGNAN(Q,2,X)
185     #define FP_NEG_Q(R,X)			_FP_NEG(Q,2,R,X)
186     #define FP_ADD_Q(R,X,Y)			_FP_ADD(Q,2,R,X,Y)
187     #define FP_SUB_Q(R,X,Y)			_FP_SUB(Q,2,R,X,Y)
188     #define FP_MUL_Q(R,X,Y)			_FP_MUL(Q,2,R,X,Y)
189     #define FP_DIV_Q(R,X,Y)			_FP_DIV(Q,2,R,X,Y)
190     #define FP_SQRT_Q(R,X)			_FP_SQRT(Q,2,R,X)
191     #define _FP_SQRT_MEAT_Q(R,S,T,X,Q)	_FP_SQRT_MEAT_2(R,S,T,X,Q)
192     
193     #define FP_CMP_Q(r,X,Y,un)	_FP_CMP(Q,2,r,X,Y,un)
194     #define FP_CMP_EQ_Q(r,X,Y)	_FP_CMP_EQ(Q,2,r,X,Y)
195     
196     #define FP_TO_INT_Q(r,X,rsz,rsg)	_FP_TO_INT(Q,2,r,X,rsz,rsg)
197     #define FP_TO_INT_ROUND_Q(r,X,rsz,rsg)	_FP_TO_INT_ROUND(Q,2,r,X,rsz,rsg)
198     #define FP_FROM_INT_Q(X,r,rs,rt)	_FP_FROM_INT(Q,2,X,r,rs,rt)
199     
200     #define _FP_FRAC_HIGH_Q(X)	_FP_FRAC_HIGH_2(X)
201     #define _FP_FRAC_HIGH_RAW_Q(X)	_FP_FRAC_HIGH_2(X)
202     
203     #endif /* not _FP_W_TYPE_SIZE < 64 */
204