1 /* Software floating-point emulation.
2 Copyright (C) 1997,1998,1999 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 Library General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with the GNU C Library; see the file COPYING.LIB. If
21 not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #ifndef __MATH_EMU_SOFT_FP_H__
25 #define __MATH_EMU_SOFT_FP_H__
27 #include <asm/sfp-machine.h>
29 /* Allow sfp-machine to have its own byte order definitions. */
34 #define _FP_WORKBITS 3
35 #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
36 #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
37 #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
38 #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
40 #ifndef FP_RND_NEAREST
41 # define FP_RND_NEAREST 0
42 # define FP_RND_ZERO 1
43 # define FP_RND_PINF 2
44 # define FP_RND_MINF 3
46 # define FP_ROUNDMODE FP_RND_NEAREST
50 /* By default don't care about exceptions. */
52 #define FP_EX_INVALID 0
54 #ifndef FP_EX_OVERFLOW
55 #define FP_EX_OVERFLOW 0
57 #ifndef FP_EX_UNDERFLOW
58 #define FP_EX_UNDERFLOW
61 #define FP_EX_DIVZERO 0
64 #define FP_EX_INEXACT 0
67 #define FP_EX_DENORM 0
75 #define FP_DECL_EX int _fex = 0
78 #ifndef FP_INIT_ROUNDMODE
79 #define FP_INIT_ROUNDMODE do {} while (0)
82 #ifndef FP_HANDLE_EXCEPTIONS
83 #define FP_HANDLE_EXCEPTIONS do {} while (0)
86 /* By default we never flush denormal input operands to signed zero. */
87 #ifndef FP_DENORM_ZERO
88 #define FP_DENORM_ZERO 0
91 #ifndef FP_INHIBIT_RESULTS
92 /* By default we write the results always.
93 * sfp-machine may override this and e.g.
94 * check if some exceptions are unmasked
95 * and inhibit it in such a case.
97 #define FP_INHIBIT_RESULTS 0
100 #ifndef FP_TRAPPING_EXCEPTIONS
101 #define FP_TRAPPING_EXCEPTIONS 0
104 #define FP_SET_EXCEPTION(ex) \
107 #define FP_UNSET_EXCEPTION(ex) \
110 #define FP_CUR_EXCEPTIONS \
113 #define FP_CLEAR_EXCEPTIONS \
116 #define _FP_ROUND_NEAREST(wc, X) \
118 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
119 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
122 #define _FP_ROUND_ZERO(wc, X) 0
124 #define _FP_ROUND_PINF(wc, X) \
126 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
127 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
130 #define _FP_ROUND_MINF(wc, X) \
132 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
133 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
136 #define _FP_ROUND(wc, X) \
138 if (_FP_FRAC_LOW_##wc(X) & 7) \
139 FP_SET_EXCEPTION(FP_EX_INEXACT); \
140 switch (FP_ROUNDMODE) \
142 case FP_RND_NEAREST: \
143 _FP_ROUND_NEAREST(wc,X); \
146 _FP_ROUND_ZERO(wc,X); \
149 _FP_ROUND_PINF(wc,X); \
152 _FP_ROUND_MINF(wc,X); \
157 #define FP_CLS_NORMAL 0
158 #define FP_CLS_ZERO 1
162 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
164 #include <math-emu/op-1.h>
165 #include <math-emu/op-2.h>
166 #include <math-emu/op-4.h>
167 #include <math-emu/op-8.h>
168 #include <math-emu/op-common.h>
170 /* Sigh. Silly things longlong.h needs. */
171 #define UWtype _FP_W_TYPE
172 #define W_TYPE_SIZE _FP_W_TYPE_SIZE
174 typedef int SItype __attribute__((mode(SI)));
175 typedef int DItype __attribute__((mode(DI)));
176 typedef unsigned int USItype __attribute__((mode(SI)));
177 typedef unsigned int UDItype __attribute__((mode(DI)));
178 #if _FP_W_TYPE_SIZE == 32
179 typedef unsigned int UHWtype __attribute__((mode(HI)));
180 #elif _FP_W_TYPE_SIZE == 64
181 typedef USItype UHWtype;
185 #include <stdlib/longlong.h>
188 #endif /* __MATH_EMU_SOFT_FP_H__ */