]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/sparc/soft-fp/soft-fp.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / sparc / soft-fp / soft-fp.h
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).
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 #include "sfp-machine.h"
38
39 /* Allow sfp-machine to have its own byte order definitions. */
40 #ifndef __BYTE_ORDER
41 #ifdef _LIBC
42 #include <endian.h>
43 #else
44 #error "endianness not defined by sfp-machine.h"
45 #endif
46 #endif
47
48 #define _FP_WORKBITS            3
49 #define _FP_WORK_LSB            ((_FP_W_TYPE)1 << 3)
50 #define _FP_WORK_ROUND          ((_FP_W_TYPE)1 << 2)
51 #define _FP_WORK_GUARD          ((_FP_W_TYPE)1 << 1)
52 #define _FP_WORK_STICKY         ((_FP_W_TYPE)1 << 0)
53
54 #ifndef FP_RND_NEAREST
55 # define FP_RND_NEAREST         0
56 # define FP_RND_ZERO            1
57 # define FP_RND_PINF            2
58 # define FP_RND_MINF            3
59 #endif
60 #ifndef FP_ROUNDMODE
61 # define FP_ROUNDMODE           FP_RND_NEAREST
62 #endif
63
64 /* By default don't care about exceptions. */
65 #ifndef FP_EX_INVALID
66 #define FP_EX_INVALID           0
67 #endif
68 #ifndef FP_EX_OVERFLOW
69 #define FP_EX_OVERFLOW          0
70 #endif
71 #ifndef FP_EX_UNDERFLOW
72 #define FP_EX_UNDERFLOW         0
73 #endif
74 #ifndef FP_EX_DIVZERO
75 #define FP_EX_DIVZERO           0
76 #endif
77 #ifndef FP_EX_INEXACT
78 #define FP_EX_INEXACT           0
79 #endif
80 #ifndef FP_EX_DENORM
81 #define FP_EX_DENORM            0
82 #endif
83
84 #ifdef _FP_DECL_EX
85 #define FP_DECL_EX                                      \
86   int _fex = 0;                                         \
87   _FP_DECL_EX
88 #else
89 #define FP_DECL_EX int _fex = 0
90 #endif
91
92 #ifndef FP_INIT_ROUNDMODE
93 #define FP_INIT_ROUNDMODE do {} while (0)
94 #endif
95
96 #ifndef FP_HANDLE_EXCEPTIONS
97 #define FP_HANDLE_EXCEPTIONS do {} while (0)
98 #endif
99
100 #ifndef FP_INHIBIT_RESULTS
101 /* By default we write the results always.
102  * sfp-machine may override this and e.g.
103  * check if some exceptions are unmasked
104  * and inhibit it in such a case.
105  */
106 #define FP_INHIBIT_RESULTS 0
107 #endif
108
109 #define FP_SET_EXCEPTION(ex)                            \
110   _fex |= (ex)
111
112 #define FP_UNSET_EXCEPTION(ex)                          \
113   _fex &= ~(ex)
114
115 #define FP_CLEAR_EXCEPTIONS                             \
116   _fex = 0
117
118 #define _FP_ROUND_NEAREST(wc, X)                        \
119 do {                                                    \
120     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)  \
121       _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND);            \
122 } while (0)
123
124 #define _FP_ROUND_ZERO(wc, X)           (void)0
125
126 #define _FP_ROUND_PINF(wc, X)                           \
127 do {                                                    \
128     if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7))           \
129       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
130 } while (0)
131
132 #define _FP_ROUND_MINF(wc, X)                           \
133 do {                                                    \
134     if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7))            \
135       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
136 } while (0)
137
138 #define _FP_ROUND(wc, X)                        \
139 do {                                            \
140         if (_FP_FRAC_LOW_##wc(X) & 7)           \
141           FP_SET_EXCEPTION(FP_EX_INEXACT);      \
142         switch (FP_ROUNDMODE)                   \
143         {                                       \
144           case FP_RND_NEAREST:                  \
145             _FP_ROUND_NEAREST(wc,X);            \
146             break;                              \
147           case FP_RND_ZERO:                     \
148             _FP_ROUND_ZERO(wc,X);               \
149             break;                              \
150           case FP_RND_PINF:                     \
151             _FP_ROUND_PINF(wc,X);               \
152             break;                              \
153           case FP_RND_MINF:                     \
154             _FP_ROUND_MINF(wc,X);               \
155             break;                              \
156         }                                       \
157 } while (0)
158
159 #define FP_CLS_NORMAL           0
160 #define FP_CLS_ZERO             1
161 #define FP_CLS_INF              2
162 #define FP_CLS_NAN              3
163
164 #define _FP_CLS_COMBINE(x,y)    (((x) << 2) | (y))
165
166 #include "op-1.h"
167 #include "op-2.h"
168 #include "op-4.h"
169 #include "op-8.h"
170 #include "op-common.h"
171
172 /* Sigh.  Silly things longlong.h needs.  */
173 #define UWtype          _FP_W_TYPE
174 #define W_TYPE_SIZE     _FP_W_TYPE_SIZE
175
176 typedef int QItype __attribute__((mode(QI)));
177 typedef int SItype __attribute__((mode(SI)));
178 typedef int DItype __attribute__((mode(DI)));
179 typedef unsigned int UQItype __attribute__((mode(QI)));
180 typedef unsigned int USItype __attribute__((mode(SI)));
181 typedef unsigned int UDItype __attribute__((mode(DI)));
182 #if _FP_W_TYPE_SIZE == 32
183 typedef unsigned int UHWtype __attribute__((mode(HI)));
184 #elif _FP_W_TYPE_SIZE == 64
185 typedef USItype UHWtype;
186 #endif
187
188 #ifndef CMPtype
189 #define CMPtype         int
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 #include "longlong.h"
197 #endif
198
199 #ifdef _LIBC
200 #include <stdlib.h>
201 #else
202 extern void abort (void);
203 #endif
204
205 #endif