Minor cleanups in libio/iofdopen.c
[glibc.git] / sysdeps / mips / math_private.h
blobbaa5f28fd2c6c76557d45bb7974e1bf93bcc84f7
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 _MATH_PRIVATE_H
21 #ifdef __mips_nan2008
22 /* MIPS aligned to IEEE 754-2008. */
23 #else
24 /* One of the few architectures where the meaning of the quiet/signaling bit is
25 inverse to IEEE 754-2008 (as well as common practice for IEEE 754-1985). */
26 # define HIGH_ORDER_BIT_IS_SET_FOR_SNAN
27 #endif
29 /* Inline functions to speed up the math library implementation. The
30 default versions of these routines are in generic/math_private.h
31 and call fesetround, feholdexcept, etc. These routines use inlined
32 code instead. */
34 #ifdef __mips_hard_float
36 # include <fenv.h>
37 # include <fenv_libc.h>
38 # include <fpu_control.h>
40 # define _FPU_MASK_ALL (_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O \
41 |_FPU_MASK_U | _FPU_MASK_I | FE_ALL_EXCEPT)
43 static __always_inline void
44 libc_feholdexcept_mips (fenv_t *envp)
46 fpu_control_t cw;
48 /* Save the current state. */
49 _FPU_GETCW (cw);
50 envp->__fp_control_register = cw;
52 /* Clear all exception enable bits and flags. */
53 cw &= ~(_FPU_MASK_ALL);
54 _FPU_SETCW (cw);
56 # define libc_feholdexcept libc_feholdexcept_mips
57 # define libc_feholdexceptf libc_feholdexcept_mips
58 # define libc_feholdexceptl libc_feholdexcept_mips
60 static __always_inline void
61 libc_fesetround_mips (int round)
63 fpu_control_t cw;
65 /* Get current state. */
66 _FPU_GETCW (cw);
68 /* Set rounding bits. */
69 cw &= ~_FPU_RC_MASK;
70 cw |= round;
72 /* Set new state. */
73 _FPU_SETCW (cw);
75 # define libc_fesetround libc_fesetround_mips
76 # define libc_fesetroundf libc_fesetround_mips
77 # define libc_fesetroundl libc_fesetround_mips
79 static __always_inline void
80 libc_feholdexcept_setround_mips (fenv_t *envp, int round)
82 fpu_control_t cw;
84 /* Save the current state. */
85 _FPU_GETCW (cw);
86 envp->__fp_control_register = cw;
88 /* Clear all exception enable bits and flags. */
89 cw &= ~(_FPU_MASK_ALL);
91 /* Set rounding bits. */
92 cw &= ~_FPU_RC_MASK;
93 cw |= round;
95 /* Set new state. */
96 _FPU_SETCW (cw);
98 # define libc_feholdexcept_setround libc_feholdexcept_setround_mips
99 # define libc_feholdexcept_setroundf libc_feholdexcept_setround_mips
100 # define libc_feholdexcept_setroundl libc_feholdexcept_setround_mips
102 # define libc_feholdsetround libc_feholdexcept_setround_mips
103 # define libc_feholdsetroundf libc_feholdexcept_setround_mips
104 # define libc_feholdsetroundl libc_feholdexcept_setround_mips
106 static __always_inline void
107 libc_fesetenv_mips (fenv_t *envp)
109 fpu_control_t cw;
111 /* Read current state to flush fpu pipeline. */
112 _FPU_GETCW (cw);
114 _FPU_SETCW (envp->__fp_control_register);
116 # define libc_fesetenv libc_fesetenv_mips
117 # define libc_fesetenvf libc_fesetenv_mips
118 # define libc_fesetenvl libc_fesetenv_mips
120 static __always_inline int
121 libc_feupdateenv_test_mips (fenv_t *envp, int excepts)
123 /* int ret = fetestexcept (excepts); feupdateenv (envp); return ret; */
124 int cw, temp;
126 /* Get current control word. */
127 _FPU_GETCW (cw);
129 /* Set flag bits (which are accumulative), and *also* set the
130 cause bits. The setting of the cause bits is what actually causes
131 the hardware to generate the exception, if the corresponding enable
132 bit is set as well. */
133 temp = cw & FE_ALL_EXCEPT;
134 temp |= envp->__fp_control_register | (temp << CAUSE_SHIFT);
136 /* Set new state. */
137 _FPU_SETCW (temp);
139 return cw & excepts & FE_ALL_EXCEPT;
141 # define libc_feupdateenv_test libc_feupdateenv_test_mips
142 # define libc_feupdateenv_testf libc_feupdateenv_test_mips
143 # define libc_feupdateenv_testl libc_feupdateenv_test_mips
145 static __always_inline void
146 libc_feupdateenv_mips (fenv_t *envp)
148 libc_feupdateenv_test_mips (envp, 0);
150 # define libc_feupdateenv libc_feupdateenv_mips
151 # define libc_feupdateenvf libc_feupdateenv_mips
152 # define libc_feupdateenvl libc_feupdateenv_mips
154 # define libc_feresetround libc_feupdateenv_mips
155 # define libc_feresetroundf libc_feupdateenv_mips
156 # define libc_feresetroundl libc_feupdateenv_mips
158 static __always_inline int
159 libc_fetestexcept_mips (int excepts)
161 int cw;
163 /* Get current control word. */
164 _FPU_GETCW (cw);
166 return cw & excepts & FE_ALL_EXCEPT;
168 # define libc_fetestexcept libc_fetestexcept_mips
169 # define libc_fetestexceptf libc_fetestexcept_mips
170 # define libc_fetestexceptl libc_fetestexcept_mips
172 /* Enable support for rounding mode context. */
173 # define HAVE_RM_CTX 1
175 static __always_inline void
176 libc_feholdexcept_setround_mips_ctx (struct rm_ctx *ctx, int round)
178 fpu_control_t old, new;
180 /* Save the current state. */
181 _FPU_GETCW (old);
182 ctx->env.__fp_control_register = old;
184 /* Clear all exception enable bits and flags. */
185 new = old & ~(_FPU_MASK_ALL);
187 /* Set rounding bits. */
188 new = (new & ~_FPU_RC_MASK) | round;
190 if (__glibc_unlikely (new != old))
192 _FPU_SETCW (new);
193 ctx->updated_status = true;
195 else
196 ctx->updated_status = false;
198 # define libc_feholdexcept_setround_ctx libc_feholdexcept_setround_mips_ctx
199 # define libc_feholdexcept_setroundf_ctx libc_feholdexcept_setround_mips_ctx
200 # define libc_feholdexcept_setroundl_ctx libc_feholdexcept_setround_mips_ctx
202 static __always_inline void
203 libc_fesetenv_mips_ctx (struct rm_ctx *ctx)
205 libc_fesetenv_mips (&ctx->env);
207 # define libc_fesetenv_ctx libc_fesetenv_mips_ctx
208 # define libc_fesetenvf_ctx libc_fesetenv_mips_ctx
209 # define libc_fesetenvl_ctx libc_fesetenv_mips_ctx
211 static __always_inline void
212 libc_feupdateenv_mips_ctx (struct rm_ctx *ctx)
214 if (__glibc_unlikely (ctx->updated_status))
215 libc_feupdateenv_test_mips (&ctx->env, 0);
217 # define libc_feupdateenv_ctx libc_feupdateenv_mips_ctx
218 # define libc_feupdateenvf_ctx libc_feupdateenv_mips_ctx
219 # define libc_feupdateenvl_ctx libc_feupdateenv_mips_ctx
220 # define libc_feresetround_ctx libc_feupdateenv_mips_ctx
221 # define libc_feresetroundf_ctx libc_feupdateenv_mips_ctx
222 # define libc_feresetroundl_ctx libc_feupdateenv_mips_ctx
224 static __always_inline void
225 libc_feholdsetround_mips_ctx (struct rm_ctx *ctx, int round)
227 fpu_control_t old, new;
229 /* Save the current state. */
230 _FPU_GETCW (old);
231 ctx->env.__fp_control_register = old;
233 /* Set rounding bits. */
234 new = (old & ~_FPU_RC_MASK) | round;
236 if (__glibc_unlikely (new != old))
238 _FPU_SETCW (new);
239 ctx->updated_status = true;
241 else
242 ctx->updated_status = false;
244 # define libc_feholdsetround_ctx libc_feholdsetround_mips_ctx
245 # define libc_feholdsetroundf_ctx libc_feholdsetround_mips_ctx
246 # define libc_feholdsetroundl_ctx libc_feholdsetround_mips_ctx
248 #endif
250 #include_next <math_private.h>
252 #endif