]>
Commit | Line | Data |
---|---|---|
d876f532 | 1 | /* Software floating-point emulation. |
d4697bc9 | 2 | Copyright (C) 1997-2014 Free Software Foundation, Inc. |
d876f532 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Richard Henderson (rth@cygnus.com), | |
5 | Jakub Jelinek (jj@ultra.linux.cz), | |
6 | David S. Miller (davem@redhat.com) and | |
7 | Peter Maydell (pmaydell@chiark.greenend.org.uk). | |
8 | ||
9 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
10 | modify it under the terms of the GNU Lesser General Public |
11 | License as published by the Free Software Foundation; either | |
12 | version 2.1 of the License, or (at your option) any later version. | |
d876f532 | 13 | |
638a783c RM |
14 | In addition to the permissions in the GNU Lesser General Public |
15 | License, the Free Software Foundation gives you unlimited | |
16 | permission to link the compiled version of this file into | |
17 | combinations with other programs, and to distribute those | |
18 | combinations without any restriction coming from the use of this | |
19 | file. (The Lesser General Public License restrictions do apply in | |
20 | other respects; for example, they cover modification of the file, | |
21 | and distribution when not linked into a combine executable.) | |
22 | ||
d876f532 UD |
23 | The GNU C Library is distributed in the hope that it will be useful, |
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 26 | Lesser General Public License for more details. |
d876f532 | 27 | |
41bdb6e2 | 28 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
29 | License along with the GNU C Library; if not, see |
30 | <http://www.gnu.org/licenses/>. */ | |
d876f532 UD |
31 | |
32 | #ifndef SOFT_FP_H | |
33 | #define SOFT_FP_H | |
34 | ||
fe0b1e85 | 35 | #ifdef _LIBC |
71b4dea7 | 36 | # include <sfp-machine.h> |
fe0b1e85 | 37 | #else |
71b4dea7 | 38 | # include "sfp-machine.h" |
fe0b1e85 | 39 | #endif |
d876f532 UD |
40 | |
41 | /* Allow sfp-machine to have its own byte order definitions. */ | |
42 | #ifndef __BYTE_ORDER | |
71b4dea7 JM |
43 | # ifdef _LIBC |
44 | # include <endian.h> | |
45 | # else | |
46 | # error "endianness not defined by sfp-machine.h" | |
47 | # endif | |
d876f532 UD |
48 | #endif |
49 | ||
50 | #define _FP_WORKBITS 3 | |
51ca9e29 JM |
51 | #define _FP_WORK_LSB ((_FP_W_TYPE) 1 << 3) |
52 | #define _FP_WORK_ROUND ((_FP_W_TYPE) 1 << 2) | |
53 | #define _FP_WORK_GUARD ((_FP_W_TYPE) 1 << 1) | |
54 | #define _FP_WORK_STICKY ((_FP_W_TYPE) 1 << 0) | |
d876f532 UD |
55 | |
56 | #ifndef FP_RND_NEAREST | |
57 | # define FP_RND_NEAREST 0 | |
58 | # define FP_RND_ZERO 1 | |
59 | # define FP_RND_PINF 2 | |
60 | # define FP_RND_MINF 3 | |
bde40c2f | 61 | #endif |
d876f532 UD |
62 | #ifndef FP_ROUNDMODE |
63 | # define FP_ROUNDMODE FP_RND_NEAREST | |
64 | #endif | |
d876f532 UD |
65 | |
66 | /* By default don't care about exceptions. */ | |
67 | #ifndef FP_EX_INVALID | |
71b4dea7 | 68 | # define FP_EX_INVALID 0 |
d876f532 UD |
69 | #endif |
70 | #ifndef FP_EX_OVERFLOW | |
71b4dea7 | 71 | # define FP_EX_OVERFLOW 0 |
d876f532 UD |
72 | #endif |
73 | #ifndef FP_EX_UNDERFLOW | |
71b4dea7 | 74 | # define FP_EX_UNDERFLOW 0 |
d876f532 UD |
75 | #endif |
76 | #ifndef FP_EX_DIVZERO | |
71b4dea7 | 77 | # define FP_EX_DIVZERO 0 |
d876f532 UD |
78 | #endif |
79 | #ifndef FP_EX_INEXACT | |
71b4dea7 | 80 | # define FP_EX_INEXACT 0 |
d876f532 UD |
81 | #endif |
82 | #ifndef FP_EX_DENORM | |
71b4dea7 | 83 | # define FP_EX_DENORM 0 |
d876f532 UD |
84 | #endif |
85 | ||
f775c276 KT |
86 | /* _FP_STRUCT_LAYOUT may be defined as an attribute to determine the |
87 | struct layout variant used for structures where bit-fields are used | |
88 | to access specific parts of binary floating-point numbers. This is | |
89 | required for systems where the default ABI uses struct layout with | |
90 | differences in how consecutive bit-fields are laid out from the | |
91 | default expected by soft-fp. */ | |
92 | #ifndef _FP_STRUCT_LAYOUT | |
71b4dea7 | 93 | # define _FP_STRUCT_LAYOUT |
f775c276 KT |
94 | #endif |
95 | ||
d876f532 | 96 | #ifdef _FP_DECL_EX |
71b4dea7 | 97 | # define FP_DECL_EX \ |
d876f532 UD |
98 | int _fex = 0; \ |
99 | _FP_DECL_EX | |
100 | #else | |
71b4dea7 | 101 | # define FP_DECL_EX int _fex = 0 |
d876f532 | 102 | #endif |
fe2dcbcc | 103 | |
dcc2dd3f JM |
104 | /* Initialize any machine-specific state used in FP_ROUNDMODE, |
105 | FP_TRAPPING_EXCEPTIONS or FP_HANDLE_EXCEPTIONS. */ | |
d876f532 | 106 | #ifndef FP_INIT_ROUNDMODE |
71b4dea7 | 107 | # define FP_INIT_ROUNDMODE do {} while (0) |
d876f532 UD |
108 | #endif |
109 | ||
dcc2dd3f JM |
110 | /* Initialize any machine-specific state used in |
111 | FP_HANDLE_EXCEPTIONS. */ | |
112 | #ifndef FP_INIT_EXCEPTIONS | |
71b4dea7 | 113 | # define FP_INIT_EXCEPTIONS FP_INIT_ROUNDMODE |
dcc2dd3f JM |
114 | #endif |
115 | ||
d876f532 | 116 | #ifndef FP_HANDLE_EXCEPTIONS |
71b4dea7 | 117 | # define FP_HANDLE_EXCEPTIONS do {} while (0) |
d876f532 UD |
118 | #endif |
119 | ||
120 | #ifndef FP_INHIBIT_RESULTS | |
121 | /* By default we write the results always. | |
122 | * sfp-machine may override this and e.g. | |
123 | * check if some exceptions are unmasked | |
124 | * and inhibit it in such a case. | |
125 | */ | |
71b4dea7 | 126 | # define FP_INHIBIT_RESULTS 0 |
d876f532 UD |
127 | #endif |
128 | ||
129 | #define FP_SET_EXCEPTION(ex) \ | |
130 | _fex |= (ex) | |
fe2dcbcc | 131 | |
d876f532 UD |
132 | #define FP_CLEAR_EXCEPTIONS \ |
133 | _fex = 0 | |
134 | ||
ae251b0b DM |
135 | #define FP_CUR_EXCEPTIONS \ |
136 | (_fex) | |
137 | ||
138 | #ifndef FP_TRAPPING_EXCEPTIONS | |
71b4dea7 | 139 | # define FP_TRAPPING_EXCEPTIONS 0 |
ae251b0b DM |
140 | #endif |
141 | ||
8edc4a11 JM |
142 | /* A file using soft-fp may define FP_NO_EXCEPTIONS before including |
143 | soft-fp.h to indicate that, although a macro used there could raise | |
144 | exceptions, or do rounding and potentially thereby raise | |
145 | exceptions, for some arguments, for the particular arguments used | |
146 | in that file no exceptions or rounding can occur. Such a file | |
147 | should not itself use macros relating to handling exceptions and | |
148 | rounding modes; this is only for indirect uses (in particular, in | |
149 | _FP_FROM_INT and the macros it calls). */ | |
150 | #ifdef FP_NO_EXCEPTIONS | |
151 | ||
71b4dea7 JM |
152 | # undef FP_SET_EXCEPTION |
153 | # define FP_SET_EXCEPTION(ex) do {} while (0) | |
8edc4a11 | 154 | |
71b4dea7 JM |
155 | # undef FP_CUR_EXCEPTIONS |
156 | # define FP_CUR_EXCEPTIONS 0 | |
8edc4a11 | 157 | |
71b4dea7 JM |
158 | # undef FP_TRAPPING_EXCEPTIONS |
159 | # define FP_TRAPPING_EXCEPTIONS 0 | |
8edc4a11 | 160 | |
71b4dea7 JM |
161 | # undef FP_ROUNDMODE |
162 | # define FP_ROUNDMODE FP_RND_ZERO | |
8edc4a11 JM |
163 | |
164 | #endif | |
165 | ||
1e145589 JM |
166 | #define _FP_ROUND_NEAREST(wc, X) \ |
167 | do \ | |
168 | { \ | |
51ca9e29 JM |
169 | if ((_FP_FRAC_LOW_##wc (X) & 15) != _FP_WORK_ROUND) \ |
170 | _FP_FRAC_ADDI_##wc (X, _FP_WORK_ROUND); \ | |
1e145589 JM |
171 | } \ |
172 | while (0) | |
d876f532 | 173 | |
51ca9e29 | 174 | #define _FP_ROUND_ZERO(wc, X) (void) 0 |
d876f532 | 175 | |
51ca9e29 JM |
176 | #define _FP_ROUND_PINF(wc, X) \ |
177 | do \ | |
178 | { \ | |
179 | if (!X##_s && (_FP_FRAC_LOW_##wc (X) & 7)) \ | |
180 | _FP_FRAC_ADDI_##wc (X, _FP_WORK_LSB); \ | |
181 | } \ | |
1e145589 JM |
182 | while (0) |
183 | ||
184 | #define _FP_ROUND_MINF(wc, X) \ | |
185 | do \ | |
186 | { \ | |
51ca9e29 JM |
187 | if (X##_s && (_FP_FRAC_LOW_##wc (X) & 7)) \ |
188 | _FP_FRAC_ADDI_##wc (X, _FP_WORK_LSB); \ | |
1e145589 JM |
189 | } \ |
190 | while (0) | |
d876f532 UD |
191 | |
192 | #define _FP_ROUND(wc, X) \ | |
1e145589 JM |
193 | do \ |
194 | { \ | |
51ca9e29 | 195 | if (_FP_FRAC_LOW_##wc (X) & 7) \ |
1e145589 | 196 | { \ |
51ca9e29 | 197 | FP_SET_EXCEPTION (FP_EX_INEXACT); \ |
1e145589 JM |
198 | switch (FP_ROUNDMODE) \ |
199 | { \ | |
200 | case FP_RND_NEAREST: \ | |
51ca9e29 | 201 | _FP_ROUND_NEAREST (wc, X); \ |
1e145589 JM |
202 | break; \ |
203 | case FP_RND_ZERO: \ | |
51ca9e29 | 204 | _FP_ROUND_ZERO (wc, X); \ |
1e145589 JM |
205 | break; \ |
206 | case FP_RND_PINF: \ | |
51ca9e29 | 207 | _FP_ROUND_PINF (wc, X); \ |
1e145589 JM |
208 | break; \ |
209 | case FP_RND_MINF: \ | |
51ca9e29 | 210 | _FP_ROUND_MINF (wc, X); \ |
1e145589 JM |
211 | break; \ |
212 | } \ | |
213 | } \ | |
214 | } \ | |
215 | while (0) | |
d876f532 UD |
216 | |
217 | #define FP_CLS_NORMAL 0 | |
218 | #define FP_CLS_ZERO 1 | |
219 | #define FP_CLS_INF 2 | |
220 | #define FP_CLS_NAN 3 | |
221 | ||
51ca9e29 | 222 | #define _FP_CLS_COMBINE(x, y) (((x) << 2) | (y)) |
d876f532 UD |
223 | |
224 | #include "op-1.h" | |
225 | #include "op-2.h" | |
226 | #include "op-4.h" | |
227 | #include "op-8.h" | |
228 | #include "op-common.h" | |
229 | ||
230 | /* Sigh. Silly things longlong.h needs. */ | |
231 | #define UWtype _FP_W_TYPE | |
232 | #define W_TYPE_SIZE _FP_W_TYPE_SIZE | |
233 | ||
51ca9e29 JM |
234 | typedef int QItype __attribute__ ((mode (QI))); |
235 | typedef int SItype __attribute__ ((mode (SI))); | |
236 | typedef int DItype __attribute__ ((mode (DI))); | |
237 | typedef unsigned int UQItype __attribute__ ((mode (QI))); | |
238 | typedef unsigned int USItype __attribute__ ((mode (SI))); | |
239 | typedef unsigned int UDItype __attribute__ ((mode (DI))); | |
d876f532 | 240 | #if _FP_W_TYPE_SIZE == 32 |
51ca9e29 | 241 | typedef unsigned int UHWtype __attribute__ ((mode (HI))); |
d876f532 UD |
242 | #elif _FP_W_TYPE_SIZE == 64 |
243 | typedef USItype UHWtype; | |
244 | #endif | |
245 | ||
ae8e81f5 | 246 | #ifndef CMPtype |
71b4dea7 | 247 | # define CMPtype int |
ae8e81f5 JJ |
248 | #endif |
249 | ||
51ca9e29 JM |
250 | #define SI_BITS (__CHAR_BIT__ * (int) sizeof (SItype)) |
251 | #define DI_BITS (__CHAR_BIT__ * (int) sizeof (DItype)) | |
fe0b1e85 | 252 | |
d876f532 | 253 | #ifndef umul_ppmm |
71b4dea7 JM |
254 | # ifdef _LIBC |
255 | # include <stdlib/longlong.h> | |
256 | # else | |
257 | # include "longlong.h" | |
258 | # endif | |
d876f532 UD |
259 | #endif |
260 | ||
fe0b1e85 | 261 | #ifdef _LIBC |
71b4dea7 | 262 | # include <stdlib.h> |
fe0b1e85 RM |
263 | #else |
264 | extern void abort (void); | |
265 | #endif | |
d57e7471 | 266 | |
d876f532 | 267 | #endif |