nscd: remove reference to libnsl
[glibc.git] / sysdeps / mips / math_private.h
blob05f1f084a4779f3ebedd77181aa34be699b288e7
1 /* Internal math stuff. MIPS version.
2 Copyright (C) 2013-2017 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 /* Inline functions to speed up the math library implementation. The
23 default versions of these routines are in generic/math_private.h
24 and call fesetround, feholdexcept, etc. These routines use inlined
25 code instead. */
27 #ifdef __mips_hard_float
29 # include <fenv.h>
30 # include <fenv_libc.h>
31 # include <fpu_control.h>
33 # define _FPU_MASK_ALL (_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O \
34 |_FPU_MASK_U | _FPU_MASK_I | FE_ALL_EXCEPT)
36 static __always_inline void
37 libc_feholdexcept_mips (fenv_t *envp)
39 fpu_control_t cw;
41 /* Save the current state. */
42 _FPU_GETCW (cw);
43 envp->__fp_control_register = cw;
45 /* Clear all exception enable bits and flags. */
46 cw &= ~(_FPU_MASK_ALL);
47 _FPU_SETCW (cw);
49 # define libc_feholdexcept libc_feholdexcept_mips
50 # define libc_feholdexceptf libc_feholdexcept_mips
51 # define libc_feholdexceptl libc_feholdexcept_mips
53 static __always_inline void
54 libc_fesetround_mips (int round)
56 fpu_control_t cw;
58 /* Get current state. */
59 _FPU_GETCW (cw);
61 /* Set rounding bits. */
62 cw &= ~_FPU_RC_MASK;
63 cw |= round;
65 /* Set new state. */
66 _FPU_SETCW (cw);
68 # define libc_fesetround libc_fesetround_mips
69 # define libc_fesetroundf libc_fesetround_mips
70 # define libc_fesetroundl libc_fesetround_mips
72 static __always_inline void
73 libc_feholdexcept_setround_mips (fenv_t *envp, int round)
75 fpu_control_t cw;
77 /* Save the current state. */
78 _FPU_GETCW (cw);
79 envp->__fp_control_register = cw;
81 /* Clear all exception enable bits and flags. */
82 cw &= ~(_FPU_MASK_ALL);
84 /* Set rounding bits. */
85 cw &= ~_FPU_RC_MASK;
86 cw |= round;
88 /* Set new state. */
89 _FPU_SETCW (cw);
91 # define libc_feholdexcept_setround libc_feholdexcept_setround_mips
92 # define libc_feholdexcept_setroundf libc_feholdexcept_setround_mips
93 # define libc_feholdexcept_setroundl libc_feholdexcept_setround_mips
95 # define libc_feholdsetround libc_feholdexcept_setround_mips
96 # define libc_feholdsetroundf libc_feholdexcept_setround_mips
97 # define libc_feholdsetroundl libc_feholdexcept_setround_mips
99 static __always_inline void
100 libc_fesetenv_mips (fenv_t *envp)
102 fpu_control_t cw __attribute__ ((unused));
104 /* Read current state to flush fpu pipeline. */
105 _FPU_GETCW (cw);
107 _FPU_SETCW (envp->__fp_control_register);
109 # define libc_fesetenv libc_fesetenv_mips
110 # define libc_fesetenvf libc_fesetenv_mips
111 # define libc_fesetenvl libc_fesetenv_mips
113 static __always_inline int
114 libc_feupdateenv_test_mips (fenv_t *envp, int excepts)
116 /* int ret = fetestexcept (excepts); feupdateenv (envp); return ret; */
117 int cw, temp;
119 /* Get current control word. */
120 _FPU_GETCW (cw);
122 /* Set flag bits (which are accumulative), and *also* set the
123 cause bits. The setting of the cause bits is what actually causes
124 the hardware to generate the exception, if the corresponding enable
125 bit is set as well. */
126 temp = cw & FE_ALL_EXCEPT;
127 temp |= envp->__fp_control_register | (temp << CAUSE_SHIFT);
129 /* Set new state. */
130 _FPU_SETCW (temp);
132 return cw & excepts & FE_ALL_EXCEPT;
134 # define libc_feupdateenv_test libc_feupdateenv_test_mips
135 # define libc_feupdateenv_testf libc_feupdateenv_test_mips
136 # define libc_feupdateenv_testl libc_feupdateenv_test_mips
138 static __always_inline void
139 libc_feupdateenv_mips (fenv_t *envp)
141 libc_feupdateenv_test_mips (envp, 0);
143 # define libc_feupdateenv libc_feupdateenv_mips
144 # define libc_feupdateenvf libc_feupdateenv_mips
145 # define libc_feupdateenvl libc_feupdateenv_mips
147 # define libc_feresetround libc_feupdateenv_mips
148 # define libc_feresetroundf libc_feupdateenv_mips
149 # define libc_feresetroundl libc_feupdateenv_mips
151 static __always_inline int
152 libc_fetestexcept_mips (int excepts)
154 int cw;
156 /* Get current control word. */
157 _FPU_GETCW (cw);
159 return cw & excepts & FE_ALL_EXCEPT;
161 # define libc_fetestexcept libc_fetestexcept_mips
162 # define libc_fetestexceptf libc_fetestexcept_mips
163 # define libc_fetestexceptl libc_fetestexcept_mips
165 /* Enable support for rounding mode context. */
166 # define HAVE_RM_CTX 1
168 static __always_inline void
169 libc_feholdexcept_setround_mips_ctx (struct rm_ctx *ctx, int round)
171 fpu_control_t old, new;
173 /* Save the current state. */
174 _FPU_GETCW (old);
175 ctx->env.__fp_control_register = old;
177 /* Clear all exception enable bits and flags. */
178 new = old & ~(_FPU_MASK_ALL);
180 /* Set rounding bits. */
181 new = (new & ~_FPU_RC_MASK) | round;
183 if (__glibc_unlikely (new != old))
185 _FPU_SETCW (new);
186 ctx->updated_status = true;
188 else
189 ctx->updated_status = false;
191 # define libc_feholdexcept_setround_ctx libc_feholdexcept_setround_mips_ctx
192 # define libc_feholdexcept_setroundf_ctx libc_feholdexcept_setround_mips_ctx
193 # define libc_feholdexcept_setroundl_ctx libc_feholdexcept_setround_mips_ctx
195 static __always_inline void
196 libc_fesetenv_mips_ctx (struct rm_ctx *ctx)
198 libc_fesetenv_mips (&ctx->env);
200 # define libc_fesetenv_ctx libc_fesetenv_mips_ctx
201 # define libc_fesetenvf_ctx libc_fesetenv_mips_ctx
202 # define libc_fesetenvl_ctx libc_fesetenv_mips_ctx
204 static __always_inline void
205 libc_feupdateenv_mips_ctx (struct rm_ctx *ctx)
207 if (__glibc_unlikely (ctx->updated_status))
208 libc_feupdateenv_test_mips (&ctx->env, 0);
210 # define libc_feupdateenv_ctx libc_feupdateenv_mips_ctx
211 # define libc_feupdateenvf_ctx libc_feupdateenv_mips_ctx
212 # define libc_feupdateenvl_ctx libc_feupdateenv_mips_ctx
213 # define libc_feresetround_ctx libc_feupdateenv_mips_ctx
214 # define libc_feresetroundf_ctx libc_feupdateenv_mips_ctx
215 # define libc_feresetroundl_ctx libc_feupdateenv_mips_ctx
217 static __always_inline void
218 libc_feholdsetround_mips_ctx (struct rm_ctx *ctx, int round)
220 fpu_control_t old, new;
222 /* Save the current state. */
223 _FPU_GETCW (old);
224 ctx->env.__fp_control_register = old;
226 /* Set rounding bits. */
227 new = (old & ~_FPU_RC_MASK) | round;
229 if (__glibc_unlikely (new != old))
231 _FPU_SETCW (new);
232 ctx->updated_status = true;
234 else
235 ctx->updated_status = false;
237 # define libc_feholdsetround_ctx libc_feholdsetround_mips_ctx
238 # define libc_feholdsetroundf_ctx libc_feholdsetround_mips_ctx
239 # define libc_feholdsetroundl_ctx libc_feholdsetround_mips_ctx
241 #endif
243 /* Enable __finitel, __isinfl, and __isnanl for binary compatibility
244 when built without long double support. */
245 #define LDBL_CLASSIFY_COMPAT 1
247 #include_next <math_private.h>
249 #endif