blob: 655ccf1c47398b57f4448967d310df3104a4c038 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Software floating-point emulation.
2 Definitions for IEEE Double 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#ifndef __MATH_EMU_DOUBLE_H__
26#define __MATH_EMU_DOUBLE_H__
27
28#if _FP_W_TYPE_SIZE < 32
29#error "Here's a nickel kid. Go buy yourself a real computer."
30#endif
31
32#if _FP_W_TYPE_SIZE < 64
33#define _FP_FRACTBITS_D (2 * _FP_W_TYPE_SIZE)
34#else
35#define _FP_FRACTBITS_D _FP_W_TYPE_SIZE
36#endif
37
38#define _FP_FRACBITS_D 53
39#define _FP_FRACXBITS_D (_FP_FRACTBITS_D - _FP_FRACBITS_D)
40#define _FP_WFRACBITS_D (_FP_WORKBITS + _FP_FRACBITS_D)
41#define _FP_WFRACXBITS_D (_FP_FRACTBITS_D - _FP_WFRACBITS_D)
42#define _FP_EXPBITS_D 11
43#define _FP_EXPBIAS_D 1023
44#define _FP_EXPMAX_D 2047
45
46#define _FP_QNANBIT_D \
47 ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2) % _FP_W_TYPE_SIZE)
48#define _FP_IMPLBIT_D \
49 ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1) % _FP_W_TYPE_SIZE)
50#define _FP_OVERFLOW_D \
51 ((_FP_W_TYPE)1 << _FP_WFRACBITS_D % _FP_W_TYPE_SIZE)
52
53#if _FP_W_TYPE_SIZE < 64
54
55union _FP_UNION_D
56{
57 double flt;
58 struct {
59#if __BYTE_ORDER == __BIG_ENDIAN
60 unsigned sign : 1;
61 unsigned exp : _FP_EXPBITS_D;
62 unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
63 unsigned frac0 : _FP_W_TYPE_SIZE;
64#else
65 unsigned frac0 : _FP_W_TYPE_SIZE;
66 unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
67 unsigned exp : _FP_EXPBITS_D;
68 unsigned sign : 1;
69#endif
70 } bits __attribute__((packed));
71};
72
73#define FP_DECL_D(X) _FP_DECL(2,X)
74#define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_2(D,X,val)
75#define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_2_P(D,X,val)
76#define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_2(D,val,X)
77#define FP_PACK_RAW_DP(val,X) \
78 do { \
79 if (!FP_INHIBIT_RESULTS) \
80 _FP_PACK_RAW_2_P(D,val,X); \
81 } while (0)
82
83#define FP_UNPACK_D(X,val) \
84 do { \
85 _FP_UNPACK_RAW_2(D,X,val); \
86 _FP_UNPACK_CANONICAL(D,2,X); \
87 } while (0)
88
89#define FP_UNPACK_DP(X,val) \
90 do { \
91 _FP_UNPACK_RAW_2_P(D,X,val); \
92 _FP_UNPACK_CANONICAL(D,2,X); \
93 } while (0)
94
95#define FP_PACK_D(val,X) \
96 do { \
97 _FP_PACK_CANONICAL(D,2,X); \
98 _FP_PACK_RAW_2(D,val,X); \
99 } while (0)
100
101#define FP_PACK_DP(val,X) \
102 do { \
103 _FP_PACK_CANONICAL(D,2,X); \
104 if (!FP_INHIBIT_RESULTS) \
105 _FP_PACK_RAW_2_P(D,val,X); \
106 } while (0)
107
108#define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,2,X)
109#define FP_NEG_D(R,X) _FP_NEG(D,2,R,X)
110#define FP_ADD_D(R,X,Y) _FP_ADD(D,2,R,X,Y)
111#define FP_SUB_D(R,X,Y) _FP_SUB(D,2,R,X,Y)
112#define FP_MUL_D(R,X,Y) _FP_MUL(D,2,R,X,Y)
113#define FP_DIV_D(R,X,Y) _FP_DIV(D,2,R,X,Y)
114#define FP_SQRT_D(R,X) _FP_SQRT(D,2,R,X)
115#define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
116
117#define FP_CMP_D(r,X,Y,un) _FP_CMP(D,2,r,X,Y,un)
118#define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,2,r,X,Y)
119
120#define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,2,r,X,rsz,rsg)
121#define FP_TO_INT_ROUND_D(r,X,rsz,rsg) _FP_TO_INT_ROUND(D,2,r,X,rsz,rsg)
122#define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,2,X,r,rs,rt)
123
124#define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_2(X)
125#define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_2(X)
126
127#else
128
129union _FP_UNION_D
130{
131 double flt;
132 struct {
133#if __BYTE_ORDER == __BIG_ENDIAN
134 unsigned sign : 1;
135 unsigned exp : _FP_EXPBITS_D;
136 unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
137#else
138 unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
139 unsigned exp : _FP_EXPBITS_D;
140 unsigned sign : 1;
141#endif
142 } bits __attribute__((packed));
143};
144
145#define FP_DECL_D(X) _FP_DECL(1,X)
146#define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_1(D,X,val)
147#define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_1_P(D,X,val)
148#define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_1(D,val,X)
149#define FP_PACK_RAW_DP(val,X) \
150 do { \
151 if (!FP_INHIBIT_RESULTS) \
152 _FP_PACK_RAW_1_P(D,val,X); \
153 } while (0)
154
155#define FP_UNPACK_D(X,val) \
156 do { \
157 _FP_UNPACK_RAW_1(D,X,val); \
158 _FP_UNPACK_CANONICAL(D,1,X); \
159 } while (0)
160
161#define FP_UNPACK_DP(X,val) \
162 do { \
163 _FP_UNPACK_RAW_1_P(D,X,val); \
164 _FP_UNPACK_CANONICAL(D,1,X); \
165 } while (0)
166
167#define FP_PACK_D(val,X) \
168 do { \
169 _FP_PACK_CANONICAL(D,1,X); \
170 _FP_PACK_RAW_1(D,val,X); \
171 } while (0)
172
173#define FP_PACK_DP(val,X) \
174 do { \
175 _FP_PACK_CANONICAL(D,1,X); \
176 if (!FP_INHIBIT_RESULTS) \
177 _FP_PACK_RAW_1_P(D,val,X); \
178 } while (0)
179
180#define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,1,X)
181#define FP_NEG_D(R,X) _FP_NEG(D,1,R,X)
182#define FP_ADD_D(R,X,Y) _FP_ADD(D,1,R,X,Y)
183#define FP_SUB_D(R,X,Y) _FP_SUB(D,1,R,X,Y)
184#define FP_MUL_D(R,X,Y) _FP_MUL(D,1,R,X,Y)
185#define FP_DIV_D(R,X,Y) _FP_DIV(D,1,R,X,Y)
186#define FP_SQRT_D(R,X) _FP_SQRT(D,1,R,X)
187#define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_1(R,S,T,X,Q)
188
189/* The implementation of _FP_MUL_D and _FP_DIV_D should be chosen by
190 the target machine. */
191
192#define FP_CMP_D(r,X,Y,un) _FP_CMP(D,1,r,X,Y,un)
193#define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,1,r,X,Y)
194
195#define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,1,r,X,rsz,rsg)
196#define FP_TO_INT_ROUND_D(r,X,rsz,rsg) _FP_TO_INT_ROUND(D,1,r,X,rsz,rsg)
197#define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,1,X,r,rs,rt)
198
199#define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_1(X)
200#define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_1(X)
201
202#endif /* W_TYPE_SIZE < 64 */
203
204
205#endif /* __MATH_EMU_DOUBLE_H__ */