Revert:
[glibc/history.git] / soft-fp / soft-fp.h
blob2dc66c1ba31f2f21b8658bcf0f39786177729019
1 /* Software floating-point emulation.
2 Copyright (C) 1997,1998,1999,2000,2002,2003 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 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 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with the GNU C Library; if not, write to the Free
21 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 02111-1307 USA. */
24 #ifndef SOFT_FP_H
25 #define SOFT_FP_H
27 #include "sfp-machine.h"
29 /* Allow sfp-machine to have its own byte order definitions. */
30 #ifndef __BYTE_ORDER
31 #include <endian.h>
32 #endif
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
45 #endif
46 #ifndef FP_ROUNDMODE
47 # define FP_ROUNDMODE FP_RND_NEAREST
48 #endif
50 /* By default don't care about exceptions. */
51 #ifndef FP_EX_INVALID
52 #define FP_EX_INVALID 0
53 #endif
54 #ifndef FP_EX_OVERFLOW
55 #define FP_EX_OVERFLOW 0
56 #endif
57 #ifndef FP_EX_UNDERFLOW
58 #define FP_EX_UNDERFLOW 0
59 #endif
60 #ifndef FP_EX_DIVZERO
61 #define FP_EX_DIVZERO 0
62 #endif
63 #ifndef FP_EX_INEXACT
64 #define FP_EX_INEXACT 0
65 #endif
66 #ifndef FP_EX_DENORM
67 #define FP_EX_DENORM 0
68 #endif
70 #ifdef _FP_DECL_EX
71 #define FP_DECL_EX \
72 int _fex = 0; \
73 _FP_DECL_EX
74 #else
75 #define FP_DECL_EX int _fex = 0
76 #endif
78 #ifndef FP_INIT_ROUNDMODE
79 #define FP_INIT_ROUNDMODE do {} while (0)
80 #endif
82 #ifndef FP_HANDLE_EXCEPTIONS
83 #define FP_HANDLE_EXCEPTIONS do {} while (0)
84 #endif
86 #ifndef FP_INHIBIT_RESULTS
87 /* By default we write the results always.
88 * sfp-machine may override this and e.g.
89 * check if some exceptions are unmasked
90 * and inhibit it in such a case.
92 #define FP_INHIBIT_RESULTS 0
93 #endif
95 #define FP_SET_EXCEPTION(ex) \
96 _fex |= (ex)
98 #define FP_UNSET_EXCEPTION(ex) \
99 _fex &= ~(ex)
101 #define FP_CLEAR_EXCEPTIONS \
102 _fex = 0
104 #define _FP_ROUND_NEAREST(wc, X) \
105 do { \
106 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
107 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
108 } while (0)
110 #define _FP_ROUND_ZERO(wc, X) (void)0
112 #define _FP_ROUND_PINF(wc, X) \
113 do { \
114 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
115 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
116 } while (0)
118 #define _FP_ROUND_MINF(wc, X) \
119 do { \
120 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
121 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
122 } while (0)
124 #define _FP_ROUND(wc, X) \
125 do { \
126 if (_FP_FRAC_LOW_##wc(X) & 7) \
127 FP_SET_EXCEPTION(FP_EX_INEXACT); \
128 switch (FP_ROUNDMODE) \
130 case FP_RND_NEAREST: \
131 _FP_ROUND_NEAREST(wc,X); \
132 break; \
133 case FP_RND_ZERO: \
134 _FP_ROUND_ZERO(wc,X); \
135 break; \
136 case FP_RND_PINF: \
137 _FP_ROUND_PINF(wc,X); \
138 break; \
139 case FP_RND_MINF: \
140 _FP_ROUND_MINF(wc,X); \
141 break; \
143 } while (0)
145 #define FP_CLS_NORMAL 0
146 #define FP_CLS_ZERO 1
147 #define FP_CLS_INF 2
148 #define FP_CLS_NAN 3
150 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
152 #include "op-1.h"
153 #include "op-2.h"
154 #include "op-4.h"
155 #include "op-8.h"
156 #include "op-common.h"
158 /* Sigh. Silly things longlong.h needs. */
159 #define UWtype _FP_W_TYPE
160 #define W_TYPE_SIZE _FP_W_TYPE_SIZE
162 typedef int QItype __attribute__((mode(QI)));
163 typedef int SItype __attribute__((mode(SI)));
164 typedef int DItype __attribute__((mode(DI)));
165 typedef unsigned int UQItype __attribute__((mode(QI)));
166 typedef unsigned int USItype __attribute__((mode(SI)));
167 typedef unsigned int UDItype __attribute__((mode(DI)));
168 #if _FP_W_TYPE_SIZE == 32
169 typedef unsigned int UHWtype __attribute__((mode(HI)));
170 #elif _FP_W_TYPE_SIZE == 64
171 typedef USItype UHWtype;
172 #endif
174 #ifndef umul_ppmm
175 #include <stdlib/longlong.h>
176 #endif
178 #include <stdlib.h>
180 #endif