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