* sysdeps/unix/sysv/linux/sparc/sparc64/dl-procinfo.c: Moved to ...
[platform/upstream/glibc.git] / soft-fp / quad.h
1 /* Software floating-point emulation.
2    Definitions for IEEE Quad Precision.
3    Copyright (C) 1997,1998,1999,2006 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 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.
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    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with the GNU C Library; if not, write to the Free
22    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23    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_QNANBIT_SH_Q                \
46         ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
47 #define _FP_IMPLBIT_Q           \
48         ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
49 #define _FP_IMPLBIT_SH_Q                \
50         ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
51 #define _FP_OVERFLOW_Q          \
52         ((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
53
54 typedef float TFtype __attribute__((mode(TF)));
55
56 #if _FP_W_TYPE_SIZE < 64
57
58 union _FP_UNION_Q
59 {
60    TFtype flt;
61    struct 
62    {
63 #if __BYTE_ORDER == __BIG_ENDIAN
64       unsigned sign : 1;
65       unsigned exp : _FP_EXPBITS_Q;
66       unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
67       unsigned long frac2 : _FP_W_TYPE_SIZE;
68       unsigned long frac1 : _FP_W_TYPE_SIZE;
69       unsigned long frac0 : _FP_W_TYPE_SIZE;
70 #else
71       unsigned long frac0 : _FP_W_TYPE_SIZE;
72       unsigned long frac1 : _FP_W_TYPE_SIZE;
73       unsigned long frac2 : _FP_W_TYPE_SIZE;
74       unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
75       unsigned exp : _FP_EXPBITS_Q;
76       unsigned sign : 1;
77 #endif /* not bigendian */
78    } bits __attribute__((packed));
79 };
80
81
82 #define FP_DECL_Q(X)            _FP_DECL(4,X)
83 #define FP_UNPACK_RAW_Q(X,val)  _FP_UNPACK_RAW_4(Q,X,val)
84 #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_4_P(Q,X,val)
85 #define FP_PACK_RAW_Q(val,X)    _FP_PACK_RAW_4(Q,val,X)
86 #define FP_PACK_RAW_QP(val,X)           \
87   do {                                  \
88     if (!FP_INHIBIT_RESULTS)            \
89       _FP_PACK_RAW_4_P(Q,val,X);        \
90   } while (0)
91
92 #define FP_UNPACK_Q(X,val)              \
93   do {                                  \
94     _FP_UNPACK_RAW_4(Q,X,val);          \
95     _FP_UNPACK_CANONICAL(Q,4,X);        \
96   } while (0)
97
98 #define FP_UNPACK_QP(X,val)             \
99   do {                                  \
100     _FP_UNPACK_RAW_4_P(Q,X,val);        \
101     _FP_UNPACK_CANONICAL(Q,4,X);        \
102   } while (0)
103
104 #define FP_UNPACK_SEMIRAW_Q(X,val)      \
105   do {                                  \
106     _FP_UNPACK_RAW_4(Q,X,val);          \
107     _FP_UNPACK_SEMIRAW(Q,4,X);          \
108   } while (0)
109
110 #define FP_UNPACK_SEMIRAW_QP(X,val)     \
111   do {                                  \
112     _FP_UNPACK_RAW_4_P(Q,X,val);        \
113     _FP_UNPACK_SEMIRAW(Q,4,X);          \
114   } while (0)
115
116 #define FP_PACK_Q(val,X)                \
117   do {                                  \
118     _FP_PACK_CANONICAL(Q,4,X);          \
119     _FP_PACK_RAW_4(Q,val,X);            \
120   } while (0)
121
122 #define FP_PACK_QP(val,X)               \
123   do {                                  \
124     _FP_PACK_CANONICAL(Q,4,X);          \
125     if (!FP_INHIBIT_RESULTS)            \
126       _FP_PACK_RAW_4_P(Q,val,X);        \
127   } while (0)
128
129 #define FP_PACK_SEMIRAW_Q(val,X)        \
130   do {                                  \
131     _FP_PACK_SEMIRAW(Q,4,X);            \
132     _FP_PACK_RAW_4(Q,val,X);            \
133   } while (0)
134
135 #define FP_PACK_SEMIRAW_QP(val,X)       \
136   do {                                  \
137     _FP_PACK_SEMIRAW(Q,4,X);            \
138     if (!FP_INHIBIT_RESULTS)            \
139       _FP_PACK_RAW_4_P(Q,val,X);        \
140   } while (0)
141
142 #define FP_ISSIGNAN_Q(X)                _FP_ISSIGNAN(Q,4,X)
143 #define FP_NEG_Q(R,X)                   _FP_NEG(Q,4,R,X)
144 #define FP_ADD_Q(R,X,Y)                 _FP_ADD(Q,4,R,X,Y)
145 #define FP_SUB_Q(R,X,Y)                 _FP_SUB(Q,4,R,X,Y)
146 #define FP_MUL_Q(R,X,Y)                 _FP_MUL(Q,4,R,X,Y)
147 #define FP_DIV_Q(R,X,Y)                 _FP_DIV(Q,4,R,X,Y)
148 #define FP_SQRT_Q(R,X)                  _FP_SQRT(Q,4,R,X)
149 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q)      _FP_SQRT_MEAT_4(R,S,T,X,Q)
150
151 #define FP_CMP_Q(r,X,Y,un)      _FP_CMP(Q,4,r,X,Y,un)
152 #define FP_CMP_EQ_Q(r,X,Y)      _FP_CMP_EQ(Q,4,r,X,Y)
153 #define FP_CMP_UNORD_Q(r,X,Y)   _FP_CMP_UNORD(Q,4,r,X,Y)
154
155 #define FP_TO_INT_Q(r,X,rsz,rsg)        _FP_TO_INT(Q,4,r,X,rsz,rsg)
156 #define FP_FROM_INT_Q(X,r,rs,rt)        _FP_FROM_INT(Q,4,X,r,rs,rt)
157
158 #define _FP_FRAC_HIGH_Q(X)      _FP_FRAC_HIGH_4(X)
159 #define _FP_FRAC_HIGH_RAW_Q(X)  _FP_FRAC_HIGH_4(X)
160
161 #else   /* not _FP_W_TYPE_SIZE < 64 */
162 union _FP_UNION_Q
163 {
164   TFtype flt /* __attribute__((mode(TF))) */ ;
165   struct {
166     _FP_W_TYPE a, b;
167   } longs;
168   struct {
169 #if __BYTE_ORDER == __BIG_ENDIAN
170     unsigned sign  : 1;
171     unsigned exp   : _FP_EXPBITS_Q;
172     unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
173     unsigned long frac0 : _FP_W_TYPE_SIZE;
174 #else
175     unsigned long frac0 : _FP_W_TYPE_SIZE;
176     unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
177     unsigned exp   : _FP_EXPBITS_Q;
178     unsigned sign  : 1;
179 #endif
180   } bits;
181 };
182
183 #define FP_DECL_Q(X)            _FP_DECL(2,X)
184 #define FP_UNPACK_RAW_Q(X,val)  _FP_UNPACK_RAW_2(Q,X,val)
185 #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_2_P(Q,X,val)
186 #define FP_PACK_RAW_Q(val,X)    _FP_PACK_RAW_2(Q,val,X)
187 #define FP_PACK_RAW_QP(val,X)           \
188   do {                                  \
189     if (!FP_INHIBIT_RESULTS)            \
190       _FP_PACK_RAW_2_P(Q,val,X);        \
191   } while (0)
192
193 #define FP_UNPACK_Q(X,val)              \
194   do {                                  \
195     _FP_UNPACK_RAW_2(Q,X,val);          \
196     _FP_UNPACK_CANONICAL(Q,2,X);        \
197   } while (0)
198
199 #define FP_UNPACK_QP(X,val)             \
200   do {                                  \
201     _FP_UNPACK_RAW_2_P(Q,X,val);        \
202     _FP_UNPACK_CANONICAL(Q,2,X);        \
203   } while (0)
204
205 #define FP_UNPACK_SEMIRAW_Q(X,val)      \
206   do {                                  \
207     _FP_UNPACK_RAW_2(Q,X,val);          \
208     _FP_UNPACK_SEMIRAW(Q,2,X);          \
209   } while (0)
210
211 #define FP_UNPACK_SEMIRAW_QP(X,val)     \
212   do {                                  \
213     _FP_UNPACK_RAW_2_P(Q,X,val);        \
214     _FP_UNPACK_SEMIRAW(Q,2,X);          \
215   } while (0)
216
217 #define FP_PACK_Q(val,X)                \
218   do {                                  \
219     _FP_PACK_CANONICAL(Q,2,X);          \
220     _FP_PACK_RAW_2(Q,val,X);            \
221   } while (0)
222
223 #define FP_PACK_QP(val,X)               \
224   do {                                  \
225     _FP_PACK_CANONICAL(Q,2,X);          \
226     if (!FP_INHIBIT_RESULTS)            \
227       _FP_PACK_RAW_2_P(Q,val,X);        \
228   } while (0)
229
230 #define FP_PACK_SEMIRAW_Q(val,X)        \
231   do {                                  \
232     _FP_PACK_SEMIRAW(Q,2,X);            \
233     _FP_PACK_RAW_2(Q,val,X);            \
234   } while (0)
235
236 #define FP_PACK_SEMIRAW_QP(val,X)       \
237   do {                                  \
238     _FP_PACK_SEMIRAW(Q,2,X);            \
239     if (!FP_INHIBIT_RESULTS)            \
240       _FP_PACK_RAW_2_P(Q,val,X);        \
241   } while (0)
242
243 #define FP_ISSIGNAN_Q(X)                _FP_ISSIGNAN(Q,2,X)
244 #define FP_NEG_Q(R,X)                   _FP_NEG(Q,2,R,X)
245 #define FP_ADD_Q(R,X,Y)                 _FP_ADD(Q,2,R,X,Y)
246 #define FP_SUB_Q(R,X,Y)                 _FP_SUB(Q,2,R,X,Y)
247 #define FP_MUL_Q(R,X,Y)                 _FP_MUL(Q,2,R,X,Y)
248 #define FP_DIV_Q(R,X,Y)                 _FP_DIV(Q,2,R,X,Y)
249 #define FP_SQRT_Q(R,X)                  _FP_SQRT(Q,2,R,X)
250 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q)      _FP_SQRT_MEAT_2(R,S,T,X,Q)
251
252 #define FP_CMP_Q(r,X,Y,un)      _FP_CMP(Q,2,r,X,Y,un)
253 #define FP_CMP_EQ_Q(r,X,Y)      _FP_CMP_EQ(Q,2,r,X,Y)
254 #define FP_CMP_UNORD_Q(r,X,Y)   _FP_CMP_UNORD(Q,2,r,X,Y)
255
256 #define FP_TO_INT_Q(r,X,rsz,rsg)        _FP_TO_INT(Q,2,r,X,rsz,rsg)
257 #define FP_FROM_INT_Q(X,r,rs,rt)        _FP_FROM_INT(Q,2,X,r,rs,rt)
258
259 #define _FP_FRAC_HIGH_Q(X)      _FP_FRAC_HIGH_2(X)
260 #define _FP_FRAC_HIGH_RAW_Q(X)  _FP_FRAC_HIGH_2(X)
261
262 #endif /* not _FP_W_TYPE_SIZE < 64 */