]> git.ipfire.org Git - thirdparty/glibc.git/blame - soft-fp/soft-fp.h
soft-fp: fix typo in comment.
[thirdparty/glibc.git] / soft-fp / soft-fp.h
CommitLineData
d876f532 1/* Software floating-point emulation.
568035b7 2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
d876f532
UD
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).
8
9 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
d876f532 13
638a783c
RM
14 In addition to the permissions in the GNU Lesser General Public
15 License, the Free Software Foundation gives you unlimited
16 permission to link the compiled version of this file into
17 combinations with other programs, and to distribute those
18 combinations without any restriction coming from the use of this
19 file. (The Lesser General Public License restrictions do apply in
20 other respects; for example, they cover modification of the file,
21 and distribution when not linked into a combine executable.)
22
d876f532
UD
23 The GNU C Library is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 26 Lesser General Public License for more details.
d876f532 27
41bdb6e2 28 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
29 License along with the GNU C Library; if not, see
30 <http://www.gnu.org/licenses/>. */
d876f532
UD
31
32#ifndef SOFT_FP_H
33#define SOFT_FP_H
34
fe0b1e85 35#ifdef _LIBC
8f480b4b 36#include <sfp-machine.h>
fe0b1e85
RM
37#else
38#include "sfp-machine.h"
39#endif
d876f532
UD
40
41/* Allow sfp-machine to have its own byte order definitions. */
42#ifndef __BYTE_ORDER
fe0b1e85 43#ifdef _LIBC
d876f532 44#include <endian.h>
fe0b1e85
RM
45#else
46#error "endianness not defined by sfp-machine.h"
47#endif
d876f532
UD
48#endif
49
50#define _FP_WORKBITS 3
51#define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
52#define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
53#define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
54#define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
55
56#ifndef FP_RND_NEAREST
57# define FP_RND_NEAREST 0
58# define FP_RND_ZERO 1
59# define FP_RND_PINF 2
60# define FP_RND_MINF 3
bde40c2f 61#endif
d876f532
UD
62#ifndef FP_ROUNDMODE
63# define FP_ROUNDMODE FP_RND_NEAREST
64#endif
d876f532
UD
65
66/* By default don't care about exceptions. */
67#ifndef FP_EX_INVALID
68#define FP_EX_INVALID 0
69#endif
70#ifndef FP_EX_OVERFLOW
71#define FP_EX_OVERFLOW 0
72#endif
73#ifndef FP_EX_UNDERFLOW
fe2dcbcc 74#define FP_EX_UNDERFLOW 0
d876f532
UD
75#endif
76#ifndef FP_EX_DIVZERO
77#define FP_EX_DIVZERO 0
78#endif
79#ifndef FP_EX_INEXACT
80#define FP_EX_INEXACT 0
81#endif
82#ifndef FP_EX_DENORM
83#define FP_EX_DENORM 0
84#endif
85
f775c276
KT
86/* _FP_STRUCT_LAYOUT may be defined as an attribute to determine the
87 struct layout variant used for structures where bit-fields are used
88 to access specific parts of binary floating-point numbers. This is
89 required for systems where the default ABI uses struct layout with
90 differences in how consecutive bit-fields are laid out from the
91 default expected by soft-fp. */
92#ifndef _FP_STRUCT_LAYOUT
93#define _FP_STRUCT_LAYOUT
94#endif
95
d876f532
UD
96#ifdef _FP_DECL_EX
97#define FP_DECL_EX \
98 int _fex = 0; \
99 _FP_DECL_EX
100#else
101#define FP_DECL_EX int _fex = 0
102#endif
fe2dcbcc 103
d876f532
UD
104#ifndef FP_INIT_ROUNDMODE
105#define FP_INIT_ROUNDMODE do {} while (0)
106#endif
107
108#ifndef FP_HANDLE_EXCEPTIONS
109#define FP_HANDLE_EXCEPTIONS do {} while (0)
110#endif
111
112#ifndef FP_INHIBIT_RESULTS
113/* By default we write the results always.
114 * sfp-machine may override this and e.g.
115 * check if some exceptions are unmasked
116 * and inhibit it in such a case.
117 */
118#define FP_INHIBIT_RESULTS 0
119#endif
120
121#define FP_SET_EXCEPTION(ex) \
122 _fex |= (ex)
fe2dcbcc 123
d876f532
UD
124#define FP_UNSET_EXCEPTION(ex) \
125 _fex &= ~(ex)
126
127#define FP_CLEAR_EXCEPTIONS \
128 _fex = 0
129
ae251b0b
DM
130#define FP_CUR_EXCEPTIONS \
131 (_fex)
132
133#ifndef FP_TRAPPING_EXCEPTIONS
134#define FP_TRAPPING_EXCEPTIONS 0
135#endif
136
d876f532
UD
137#define _FP_ROUND_NEAREST(wc, X) \
138do { \
139 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
140 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
141} while (0)
142
8ed1e7d5 143#define _FP_ROUND_ZERO(wc, X) (void)0
d876f532
UD
144
145#define _FP_ROUND_PINF(wc, X) \
146do { \
147 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
148 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
149} while (0)
150
151#define _FP_ROUND_MINF(wc, X) \
152do { \
153 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
154 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
155} while (0)
156
157#define _FP_ROUND(wc, X) \
158do { \
159 if (_FP_FRAC_LOW_##wc(X) & 7) \
47594329
MS
160 { \
161 FP_SET_EXCEPTION(FP_EX_INEXACT); \
162 switch (FP_ROUNDMODE) \
163 { \
164 case FP_RND_NEAREST: \
165 _FP_ROUND_NEAREST(wc,X); \
166 break; \
167 case FP_RND_ZERO: \
168 _FP_ROUND_ZERO(wc,X); \
169 break; \
170 case FP_RND_PINF: \
171 _FP_ROUND_PINF(wc,X); \
172 break; \
173 case FP_RND_MINF: \
174 _FP_ROUND_MINF(wc,X); \
175 break; \
176 } \
177 } \
d876f532
UD
178} while (0)
179
180#define FP_CLS_NORMAL 0
181#define FP_CLS_ZERO 1
182#define FP_CLS_INF 2
183#define FP_CLS_NAN 3
184
185#define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
186
187#include "op-1.h"
188#include "op-2.h"
189#include "op-4.h"
190#include "op-8.h"
191#include "op-common.h"
192
193/* Sigh. Silly things longlong.h needs. */
194#define UWtype _FP_W_TYPE
195#define W_TYPE_SIZE _FP_W_TYPE_SIZE
196
cbc85992 197typedef int QItype __attribute__((mode(QI)));
d876f532
UD
198typedef int SItype __attribute__((mode(SI)));
199typedef int DItype __attribute__((mode(DI)));
cbc85992 200typedef unsigned int UQItype __attribute__((mode(QI)));
d876f532
UD
201typedef unsigned int USItype __attribute__((mode(SI)));
202typedef unsigned int UDItype __attribute__((mode(DI)));
203#if _FP_W_TYPE_SIZE == 32
204typedef unsigned int UHWtype __attribute__((mode(HI)));
205#elif _FP_W_TYPE_SIZE == 64
206typedef USItype UHWtype;
207#endif
208
ae8e81f5
JJ
209#ifndef CMPtype
210#define CMPtype int
211#endif
212
fe0b1e85
RM
213#define SI_BITS (__CHAR_BIT__ * (int)sizeof(SItype))
214#define DI_BITS (__CHAR_BIT__ * (int)sizeof(DItype))
215
d876f532 216#ifndef umul_ppmm
fe0b1e85 217#ifdef _LIBC
d876f532 218#include <stdlib/longlong.h>
fe0b1e85
RM
219#else
220#include "longlong.h"
221#endif
d876f532
UD
222#endif
223
fe0b1e85 224#ifdef _LIBC
d57e7471 225#include <stdlib.h>
fe0b1e85
RM
226#else
227extern void abort (void);
228#endif
d57e7471 229
d876f532 230#endif