PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
fenv-softfloat.h
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2004-2011 David Schultz <das@FreeBSD.ORG>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31/*
32 * This file implements the functionality of <fenv.h> on platforms that
33 * lack an FPU and use softfloat in libc for floating point. To use it,
34 * you must write an <fenv.h> that provides the following:
35 *
36 * - a typedef for fenv_t, which may be an integer or struct type
37 * - a typedef for fexcept_t (XXX This file assumes fexcept_t is a
38 * simple integer type containing the exception mask.)
39 * - definitions of FE_* constants for the five exceptions and four
40 * rounding modes in IEEE 754, as described in fenv(3)
41 * - a definition, and the corresponding external symbol, for FE_DFL_ENV
42 * - a macro __set_env(env, flags, mask, rnd), which sets the given fenv_t
43 * from the exception flags, mask, and rounding mode
44 * - macros __env_flags(env), __env_mask(env), and __env_round(env), which
45 * extract fields from an fenv_t
46 * - a definition of __fenv_static
47 *
48 * If the architecture supports an optional FPU, it's recommended that you
49 * define fenv_t and fexcept_t to match the hardware ABI. Otherwise, it
50 * doesn't matter how you define them.
51 */
52#include <errno.h>
53int __softfloat_float_exception_flags;
54int __softfloat_float_exception_mask;
55int __softfloat_float_rounding_mode;
56
57
58__fenv_static inline int
59feclearexcept(int excepts)
60{
61
62 __softfloat_float_exception_flags &= ~excepts;
63 return (0);
64}
65
66__fenv_static inline int
67fegetexceptflag(fexcept_t *flagp, int excepts)
68{
69
70 *flagp = __softfloat_float_exception_flags & excepts;
71 return (0);
72}
73
74__fenv_static inline int
75fesetexceptflag(const fexcept_t *flagp, int excepts)
76{
77
78 __softfloat_float_exception_flags &= ~excepts;
79 __softfloat_float_exception_flags |= *flagp & excepts;
80 return (0);
81}
82
83__fenv_static inline int
84feraiseexcept(int excepts)
85{
86
87return(excepts ? -ENOTSUP : 0 );
88
89}
90
91__fenv_static inline int
92fetestexcept(int excepts)
93{
94
95 return (__softfloat_float_exception_flags & excepts);
96}
97
98__fenv_static inline int
99fegetround(void)
100{
101
102 return (__softfloat_float_rounding_mode);
103}
104
105__fenv_static inline int
106fesetround(int rounding_mode)
107{
108
109 __softfloat_float_rounding_mode = rounding_mode;
110 return (0);
111}
112
113__fenv_static inline int
114fegetenv(fenv_t *envp)
115{
116
117 __set_env(*envp, __softfloat_float_exception_flags,
118 __softfloat_float_exception_mask, __softfloat_float_rounding_mode);
119 return (0);
120}
121
122__fenv_static inline int
123feholdexcept(fenv_t *envp)
124{
125 fenv_t __env;
126
127 fegetenv(envp);
128 __softfloat_float_exception_flags = 0;
129 __softfloat_float_exception_mask = 0;
130 return (0);
131}
132
133__fenv_static inline int
134fesetenv(const fenv_t *envp)
135{
136
137 __softfloat_float_exception_flags = __env_flags(*envp);
138 __softfloat_float_exception_mask = __env_mask(*envp);
139 __softfloat_float_rounding_mode = __env_round(*envp);
140 return (0);
141}
142
143__fenv_static inline int
144feupdateenv(const fenv_t *envp)
145{
146 int __oflags = __softfloat_float_exception_flags;
147
148 fesetenv(envp);
149 feraiseexcept(__oflags);
150 return (0);
151}
152
153#if __BSD_VISIBLE
154
155/* We currently provide no external definitions of the functions below. */
156
157__fenv_static inline int
158feenableexcept(int __mask)
159{
160 int __omask = __softfloat_float_exception_mask;
161
162 __softfloat_float_exception_mask |= __mask;
163 return (__omask);
164}
165
166__fenv_static inline int
167fedisableexcept(int __mask)
168{
169 int __omask = __softfloat_float_exception_mask;
170
171 __softfloat_float_exception_mask &= ~__mask;
172 return (__omask);
173}
174
175__fenv_static inline int
176fegetexcept(void)
177{
178
179 return (__softfloat_float_exception_mask);
180}
181
182#endif /* __BSD_VISIBLE */
#define ENOTSUP
Definition errno.h:259