]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/gcc/config/soft-fp/soft-fp.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / gcc / config / soft-fp / soft-fp.h
1 /* Software floating-point emulation.
2    Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006
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).
9
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.
14
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.)
23
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.
28
29    You should have received a copy of the GNU Lesser General Public
30    License along with the GNU C Library; if not, write to the Free
31    Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
32    MA 02110-1301, USA.  */
33
34 #ifndef SOFT_FP_H
35 #define SOFT_FP_H
36
37 #ifdef _LIBC
38 #include <sfp-machine.h>
39 #else
40 #include "sfp-machine.h"
41 #endif
42
43 /* Allow sfp-machine to have its own byte order definitions. */
44 #ifndef __BYTE_ORDER
45 #ifdef _LIBC
46 #include <endian.h>
47 #else
48 #error "endianness not defined by sfp-machine.h"
49 #endif
50 #endif
51
52 #define _FP_WORKBITS            3
53 #define _FP_WORK_LSB            ((_FP_W_TYPE)1 << 3)
54 #define _FP_WORK_ROUND          ((_FP_W_TYPE)1 << 2)
55 #define _FP_WORK_GUARD          ((_FP_W_TYPE)1 << 1)
56 #define _FP_WORK_STICKY         ((_FP_W_TYPE)1 << 0)
57
58 #ifndef FP_RND_NEAREST
59 # define FP_RND_NEAREST         0
60 # define FP_RND_ZERO            1
61 # define FP_RND_PINF            2
62 # define FP_RND_MINF            3
63 #endif
64 #ifndef FP_ROUNDMODE
65 # define FP_ROUNDMODE           FP_RND_NEAREST
66 #endif
67
68 /* By default don't care about exceptions. */
69 #ifndef FP_EX_INVALID
70 #define FP_EX_INVALID           0
71 #endif
72 #ifndef FP_EX_OVERFLOW
73 #define FP_EX_OVERFLOW          0
74 #endif
75 #ifndef FP_EX_UNDERFLOW
76 #define FP_EX_UNDERFLOW         0
77 #endif
78 #ifndef FP_EX_DIVZERO
79 #define FP_EX_DIVZERO           0
80 #endif
81 #ifndef FP_EX_INEXACT
82 #define FP_EX_INEXACT           0
83 #endif
84 #ifndef FP_EX_DENORM
85 #define FP_EX_DENORM            0
86 #endif
87
88 #ifdef _FP_DECL_EX
89 #define FP_DECL_EX                                      \
90   int _fex = 0;                                         \
91   _FP_DECL_EX
92 #else
93 #define FP_DECL_EX int _fex = 0
94 #endif
95
96 #ifndef FP_INIT_ROUNDMODE
97 #define FP_INIT_ROUNDMODE do {} while (0)
98 #endif
99
100 #ifndef FP_HANDLE_EXCEPTIONS
101 #define FP_HANDLE_EXCEPTIONS do {} while (0)
102 #endif
103
104 #ifndef FP_INHIBIT_RESULTS
105 /* By default we write the results always.
106  * sfp-machine may override this and e.g.
107  * check if some exceptions are unmasked
108  * and inhibit it in such a case.
109  */
110 #define FP_INHIBIT_RESULTS 0
111 #endif
112
113 #define FP_SET_EXCEPTION(ex)                            \
114   _fex |= (ex)
115
116 #define FP_UNSET_EXCEPTION(ex)                          \
117   _fex &= ~(ex)
118
119 #define FP_CLEAR_EXCEPTIONS                             \
120   _fex = 0
121
122 #define _FP_ROUND_NEAREST(wc, X)                        \
123 do {                                                    \
124     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)  \
125       _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND);            \
126 } while (0)
127
128 #define _FP_ROUND_ZERO(wc, X)           (void)0
129
130 #define _FP_ROUND_PINF(wc, X)                           \
131 do {                                                    \
132     if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7))           \
133       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
134 } while (0)
135
136 #define _FP_ROUND_MINF(wc, X)                           \
137 do {                                                    \
138     if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7))            \
139       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
140 } while (0)
141
142 #define _FP_ROUND(wc, X)                        \
143 do {                                            \
144         if (_FP_FRAC_LOW_##wc(X) & 7)           \
145           FP_SET_EXCEPTION(FP_EX_INEXACT);      \
146         switch (FP_ROUNDMODE)                   \
147         {                                       \
148           case FP_RND_NEAREST:                  \
149             _FP_ROUND_NEAREST(wc,X);            \
150             break;                              \
151           case FP_RND_ZERO:                     \
152             _FP_ROUND_ZERO(wc,X);               \
153             break;                              \
154           case FP_RND_PINF:                     \
155             _FP_ROUND_PINF(wc,X);               \
156             break;                              \
157           case FP_RND_MINF:                     \
158             _FP_ROUND_MINF(wc,X);               \
159             break;                              \
160         }                                       \
161 } while (0)
162
163 #define FP_CLS_NORMAL           0
164 #define FP_CLS_ZERO             1
165 #define FP_CLS_INF              2
166 #define FP_CLS_NAN              3
167
168 #define _FP_CLS_COMBINE(x,y)    (((x) << 2) | (y))
169
170 #include "op-1.h"
171 #include "op-2.h"
172 #include "op-4.h"
173 #include "op-8.h"
174 #include "op-common.h"
175
176 /* Sigh.  Silly things longlong.h needs.  */
177 #define UWtype          _FP_W_TYPE
178 #define W_TYPE_SIZE     _FP_W_TYPE_SIZE
179
180 typedef int QItype __attribute__((mode(QI)));
181 typedef int SItype __attribute__((mode(SI)));
182 typedef int DItype __attribute__((mode(DI)));
183 typedef unsigned int UQItype __attribute__((mode(QI)));
184 typedef unsigned int USItype __attribute__((mode(SI)));
185 typedef unsigned int UDItype __attribute__((mode(DI)));
186 #if _FP_W_TYPE_SIZE == 32
187 typedef unsigned int UHWtype __attribute__((mode(HI)));
188 #elif _FP_W_TYPE_SIZE == 64
189 typedef USItype UHWtype;
190 #endif
191
192 #define SI_BITS         (__CHAR_BIT__ * (int)sizeof(SItype))
193 #define DI_BITS         (__CHAR_BIT__ * (int)sizeof(DItype))
194
195 #ifndef umul_ppmm
196 #ifdef _LIBC
197 #include <stdlib/longlong.h>
198 #else
199 #include "longlong.h"
200 #endif
201 #endif
202
203 #ifdef _LIBC
204 #include <stdlib.h>
205 #else
206 extern void abort (void);
207 #endif
208
209 #endif