Fix SYSCALL_CANCEL for empty argumetns
[glibc.git] / sysdeps / mips / math_private.h
blob27de7149c2b6dbc2d2ae95e6c2cd4daa0c30dba8
1 /* Internal math stuff. MIPS version.
2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef MIPS_MATH_PRIVATE_H
20 #define MIPS_MATH_PRIVATE_H 1
22 #ifdef __mips_nan2008
23 /* MIPS aligned to IEEE 754-2008. */
24 #else
25 /* One of the few architectures where the meaning of the quiet/signaling bit is
26 inverse to IEEE 754-2008 (as well as common practice for IEEE 754-1985). */
27 # define HIGH_ORDER_BIT_IS_SET_FOR_SNAN
28 #endif
30 /* Inline functions to speed up the math library implementation. The
31 default versions of these routines are in generic/math_private.h
32 and call fesetround, feholdexcept, etc. These routines use inlined
33 code instead. */
35 #ifdef __mips_hard_float
37 # include <fenv.h>
38 # include <fenv_libc.h>
39 # include <fpu_control.h>
41 # define _FPU_MASK_ALL (_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O \
42 |_FPU_MASK_U | _FPU_MASK_I | FE_ALL_EXCEPT)
44 static __always_inline void
45 libc_feholdexcept_mips (fenv_t *envp)
47 fpu_control_t cw;
49 /* Save the current state. */
50 _FPU_GETCW (cw);
51 envp->__fp_control_register = cw;
53 /* Clear all exception enable bits and flags. */
54 cw &= ~(_FPU_MASK_ALL);
55 _FPU_SETCW (cw);
57 # define libc_feholdexcept libc_feholdexcept_mips
58 # define libc_feholdexceptf libc_feholdexcept_mips
59 # define libc_feholdexceptl libc_feholdexcept_mips
61 static __always_inline void
62 libc_fesetround_mips (int round)
64 fpu_control_t cw;
66 /* Get current state. */
67 _FPU_GETCW (cw);
69 /* Set rounding bits. */
70 cw &= ~_FPU_RC_MASK;
71 cw |= round;
73 /* Set new state. */
74 _FPU_SETCW (cw);
76 # define libc_fesetround libc_fesetround_mips
77 # define libc_fesetroundf libc_fesetround_mips
78 # define libc_fesetroundl libc_fesetround_mips
80 static __always_inline void
81 libc_feholdexcept_setround_mips (fenv_t *envp, int round)
83 fpu_control_t cw;
85 /* Save the current state. */
86 _FPU_GETCW (cw);
87 envp->__fp_control_register = cw;
89 /* Clear all exception enable bits and flags. */
90 cw &= ~(_FPU_MASK_ALL);
92 /* Set rounding bits. */
93 cw &= ~_FPU_RC_MASK;
94 cw |= round;
96 /* Set new state. */
97 _FPU_SETCW (cw);
99 # define libc_feholdexcept_setround libc_feholdexcept_setround_mips
100 # define libc_feholdexcept_setroundf libc_feholdexcept_setround_mips
101 # define libc_feholdexcept_setroundl libc_feholdexcept_setround_mips
103 # define libc_feholdsetround libc_feholdexcept_setround_mips
104 # define libc_feholdsetroundf libc_feholdexcept_setround_mips
105 # define libc_feholdsetroundl libc_feholdexcept_setround_mips
107 static __always_inline void
108 libc_fesetenv_mips (fenv_t *envp)
110 fpu_control_t cw __attribute__ ((unused));
112 /* Read current state to flush fpu pipeline. */
113 _FPU_GETCW (cw);
115 _FPU_SETCW (envp->__fp_control_register);
117 # define libc_fesetenv libc_fesetenv_mips
118 # define libc_fesetenvf libc_fesetenv_mips
119 # define libc_fesetenvl libc_fesetenv_mips
121 static __always_inline int
122 libc_feupdateenv_test_mips (fenv_t *envp, int excepts)
124 /* int ret = fetestexcept (excepts); feupdateenv (envp); return ret; */
125 int cw, temp;
127 /* Get current control word. */
128 _FPU_GETCW (cw);
130 /* Set flag bits (which are accumulative), and *also* set the
131 cause bits. The setting of the cause bits is what actually causes
132 the hardware to generate the exception, if the corresponding enable
133 bit is set as well. */
134 temp = cw & FE_ALL_EXCEPT;
135 temp |= envp->__fp_control_register | (temp << CAUSE_SHIFT);
137 /* Set new state. */
138 _FPU_SETCW (temp);
140 return cw & excepts & FE_ALL_EXCEPT;
142 # define libc_feupdateenv_test libc_feupdateenv_test_mips
143 # define libc_feupdateenv_testf libc_feupdateenv_test_mips
144 # define libc_feupdateenv_testl libc_feupdateenv_test_mips
146 static __always_inline void
147 libc_feupdateenv_mips (fenv_t *envp)
149 libc_feupdateenv_test_mips (envp, 0);
151 # define libc_feupdateenv libc_feupdateenv_mips
152 # define libc_feupdateenvf libc_feupdateenv_mips
153 # define libc_feupdateenvl libc_feupdateenv_mips
155 # define libc_feresetround libc_feupdateenv_mips
156 # define libc_feresetroundf libc_feupdateenv_mips
157 # define libc_feresetroundl libc_feupdateenv_mips
159 static __always_inline int
160 libc_fetestexcept_mips (int excepts)
162 int cw;
164 /* Get current control word. */
165 _FPU_GETCW (cw);
167 return cw & excepts & FE_ALL_EXCEPT;
169 # define libc_fetestexcept libc_fetestexcept_mips
170 # define libc_fetestexceptf libc_fetestexcept_mips
171 # define libc_fetestexceptl libc_fetestexcept_mips
173 /* Enable support for rounding mode context. */
174 # define HAVE_RM_CTX 1
176 static __always_inline void
177 libc_feholdexcept_setround_mips_ctx (struct rm_ctx *ctx, int round)
179 fpu_control_t old, new;
181 /* Save the current state. */
182 _FPU_GETCW (old);
183 ctx->env.__fp_control_register = old;
185 /* Clear all exception enable bits and flags. */
186 new = old & ~(_FPU_MASK_ALL);
188 /* Set rounding bits. */
189 new = (new & ~_FPU_RC_MASK) | round;
191 if (__glibc_unlikely (new != old))
193 _FPU_SETCW (new);
194 ctx->updated_status = true;
196 else
197 ctx->updated_status = false;
199 # define libc_feholdexcept_setround_ctx libc_feholdexcept_setround_mips_ctx
200 # define libc_feholdexcept_setroundf_ctx libc_feholdexcept_setround_mips_ctx
201 # define libc_feholdexcept_setroundl_ctx libc_feholdexcept_setround_mips_ctx
203 static __always_inline void
204 libc_fesetenv_mips_ctx (struct rm_ctx *ctx)
206 libc_fesetenv_mips (&ctx->env);
208 # define libc_fesetenv_ctx libc_fesetenv_mips_ctx
209 # define libc_fesetenvf_ctx libc_fesetenv_mips_ctx
210 # define libc_fesetenvl_ctx libc_fesetenv_mips_ctx
212 static __always_inline void
213 libc_feupdateenv_mips_ctx (struct rm_ctx *ctx)
215 if (__glibc_unlikely (ctx->updated_status))
216 libc_feupdateenv_test_mips (&ctx->env, 0);
218 # define libc_feupdateenv_ctx libc_feupdateenv_mips_ctx
219 # define libc_feupdateenvf_ctx libc_feupdateenv_mips_ctx
220 # define libc_feupdateenvl_ctx libc_feupdateenv_mips_ctx
221 # define libc_feresetround_ctx libc_feupdateenv_mips_ctx
222 # define libc_feresetroundf_ctx libc_feupdateenv_mips_ctx
223 # define libc_feresetroundl_ctx libc_feupdateenv_mips_ctx
225 static __always_inline void
226 libc_feholdsetround_mips_ctx (struct rm_ctx *ctx, int round)
228 fpu_control_t old, new;
230 /* Save the current state. */
231 _FPU_GETCW (old);
232 ctx->env.__fp_control_register = old;
234 /* Set rounding bits. */
235 new = (old & ~_FPU_RC_MASK) | round;
237 if (__glibc_unlikely (new != old))
239 _FPU_SETCW (new);
240 ctx->updated_status = true;
242 else
243 ctx->updated_status = false;
245 # define libc_feholdsetround_ctx libc_feholdsetround_mips_ctx
246 # define libc_feholdsetroundf_ctx libc_feholdsetround_mips_ctx
247 # define libc_feholdsetroundl_ctx libc_feholdsetround_mips_ctx
249 #endif
251 /* Enable __finitel, __isinfl, and __isnanl for binary compatibility
252 when built without long double support. */
253 #define LDBL_CLASSIFY_COMPAT 1
255 #include_next <math_private.h>
257 #endif