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