1 /* Software floating-point emulation.
2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
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).
9 The GNU C Library is free software; you can redistribute it and/or
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.
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.)
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
26 Lesser General Public License for more details.
28 You should have received a copy of the GNU Lesser General Public
29 License along with the GNU C Library; if not, see
30 <http://www.gnu.org/licenses/>. */
36 # include <sfp-machine.h>
38 # include "sfp-machine.h"
41 /* Allow sfp-machine to have its own byte order definitions. */
46 # error "endianness not defined by sfp-machine.h"
50 #define _FP_WORKBITS 3
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)
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
63 # define FP_ROUNDMODE FP_RND_NEAREST
66 /* By default don't care about exceptions. */
68 # define FP_EX_INVALID 0
70 #ifndef FP_EX_OVERFLOW
71 # define FP_EX_OVERFLOW 0
73 #ifndef FP_EX_UNDERFLOW
74 # define FP_EX_UNDERFLOW 0
77 # define FP_EX_DIVZERO 0
80 # define FP_EX_INEXACT 0
83 # define FP_EX_DENORM 0
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
93 # define _FP_STRUCT_LAYOUT
101 # define FP_DECL_EX int _fex = 0
104 /* Initialize any machine-specific state used in FP_ROUNDMODE,
105 FP_TRAPPING_EXCEPTIONS or FP_HANDLE_EXCEPTIONS. */
106 #ifndef FP_INIT_ROUNDMODE
107 # define FP_INIT_ROUNDMODE do {} while (0)
110 /* Initialize any machine-specific state used in
111 FP_HANDLE_EXCEPTIONS. */
112 #ifndef FP_INIT_EXCEPTIONS
113 # define FP_INIT_EXCEPTIONS FP_INIT_ROUNDMODE
116 #ifndef FP_HANDLE_EXCEPTIONS
117 # define FP_HANDLE_EXCEPTIONS do {} while (0)
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.
126 # define FP_INHIBIT_RESULTS 0
129 #define FP_SET_EXCEPTION(ex) \
132 #define FP_CLEAR_EXCEPTIONS \
135 #define FP_CUR_EXCEPTIONS \
138 #ifndef FP_TRAPPING_EXCEPTIONS
139 # define FP_TRAPPING_EXCEPTIONS 0
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
152 # undef FP_SET_EXCEPTION
153 # define FP_SET_EXCEPTION(ex) do {} while (0)
155 # undef FP_CUR_EXCEPTIONS
156 # define FP_CUR_EXCEPTIONS 0
158 # undef FP_TRAPPING_EXCEPTIONS
159 # define FP_TRAPPING_EXCEPTIONS 0
162 # define FP_ROUNDMODE FP_RND_ZERO
166 #define _FP_ROUND_NEAREST(wc, X) \
169 if ((_FP_FRAC_LOW_##wc (X) & 15) != _FP_WORK_ROUND) \
170 _FP_FRAC_ADDI_##wc (X, _FP_WORK_ROUND); \
174 #define _FP_ROUND_ZERO(wc, X) (void) 0
176 #define _FP_ROUND_PINF(wc, X) \
179 if (!X##_s && (_FP_FRAC_LOW_##wc (X) & 7)) \
180 _FP_FRAC_ADDI_##wc (X, _FP_WORK_LSB); \
184 #define _FP_ROUND_MINF(wc, X) \
187 if (X##_s && (_FP_FRAC_LOW_##wc (X) & 7)) \
188 _FP_FRAC_ADDI_##wc (X, _FP_WORK_LSB); \
192 #define _FP_ROUND(wc, X) \
195 if (_FP_FRAC_LOW_##wc (X) & 7) \
197 FP_SET_EXCEPTION (FP_EX_INEXACT); \
198 switch (FP_ROUNDMODE) \
200 case FP_RND_NEAREST: \
201 _FP_ROUND_NEAREST (wc, X); \
204 _FP_ROUND_ZERO (wc, X); \
207 _FP_ROUND_PINF (wc, X); \
210 _FP_ROUND_MINF (wc, X); \
217 #define FP_CLS_NORMAL 0
218 #define FP_CLS_ZERO 1
222 #define _FP_CLS_COMBINE(x, y) (((x) << 2) | (y))
228 #include "op-common.h"
230 /* Sigh. Silly things longlong.h needs. */
231 #define UWtype _FP_W_TYPE
232 #define W_TYPE_SIZE _FP_W_TYPE_SIZE
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
)));
240 #if _FP_W_TYPE_SIZE == 32
241 typedef unsigned int UHWtype
__attribute__ ((mode (HI
)));
242 #elif _FP_W_TYPE_SIZE == 64
243 typedef USItype UHWtype
;
250 #define SI_BITS (__CHAR_BIT__ * (int) sizeof (SItype))
251 #define DI_BITS (__CHAR_BIT__ * (int) sizeof (DItype))
255 # include <stdlib/longlong.h>
257 # include "longlong.h"
264 extern void abort (void);