Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / mips / math_private.h
blob95f438581b2b4998dcb4a074a839af1bd389bcd0
1 /* Internal math stuff. MIPS version.
2 Copyright (C) 2013-2014 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 static __always_inline void
41 libc_feholdexcept_mips (fenv_t *envp)
43 fpu_control_t cw;
45 /* Save the current state. */
46 _FPU_GETCW (cw);
47 envp->__fp_control_register = cw;
49 /* Clear all exception enable bits and flags. */
50 cw &= ~(_FPU_MASK_V|_FPU_MASK_Z|_FPU_MASK_O|_FPU_MASK_U|_FPU_MASK_I|FE_ALL_EXCEPT);
51 _FPU_SETCW (cw);
53 # define libc_feholdexcept libc_feholdexcept_mips
54 # define libc_feholdexceptf libc_feholdexcept_mips
55 # define libc_feholdexceptl libc_feholdexcept_mips
57 static __always_inline void
58 libc_fesetround_mips (int round)
60 fpu_control_t cw;
62 /* Get current state. */
63 _FPU_GETCW (cw);
65 /* Set rounding bits. */
66 cw &= ~_FPU_RC_MASK;
67 cw |= round;
69 /* Set new state. */
70 _FPU_SETCW (cw);
72 # define libc_fesetround libc_fesetround_mips
73 # define libc_fesetroundf libc_fesetround_mips
74 # define libc_fesetroundl libc_fesetround_mips
76 static __always_inline void
77 libc_feholdexcept_setround_mips (fenv_t *envp, int round)
79 fpu_control_t cw;
81 /* Save the current state. */
82 _FPU_GETCW (cw);
83 envp->__fp_control_register = cw;
85 /* Clear all exception enable bits and flags. */
86 cw &= ~(_FPU_MASK_V|_FPU_MASK_Z|_FPU_MASK_O|_FPU_MASK_U|_FPU_MASK_I|FE_ALL_EXCEPT);
88 /* Set rounding bits. */
89 cw &= ~_FPU_RC_MASK;
90 cw |= round;
92 /* Set new state. */
93 _FPU_SETCW (cw);
95 # define libc_feholdexcept_setround libc_feholdexcept_setround_mips
96 # define libc_feholdexcept_setroundf libc_feholdexcept_setround_mips
97 # define libc_feholdexcept_setroundl libc_feholdexcept_setround_mips
99 static __always_inline void
100 libc_fesetenv_mips (fenv_t *envp)
102 fpu_control_t cw;
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 void
114 libc_feupdateenv_mips (fenv_t *envp)
116 int temp;
118 /* Save current exceptions. */
119 _FPU_GETCW (temp);
121 /* Set flag bits (which are accumulative), and *also* set the
122 cause bits. The setting of the cause bits is what actually causes
123 the hardware to generate the exception, if the corresponding enable
124 bit is set as well. */
125 temp &= FE_ALL_EXCEPT;
126 temp |= envp->__fp_control_register | (temp << CAUSE_SHIFT);
128 /* Set new state. */
129 _FPU_SETCW (temp);
131 # define libc_feupdateenv libc_feupdateenv_mips
132 # define libc_feupdateenvf libc_feupdateenv_mips
133 # define libc_feupdateenvl libc_feupdateenv_mips
135 #endif
137 #include_next <math_private.h>
139 #endif