1 /* Install given floating-point environment.
2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
21 #include <fpu_control.h>
25 #include <dl-procinfo.h>
28 /* All exceptions, including the x86-specific "denormal operand"
30 #define FE_ALL_EXCEPT_X86 (FE_ALL_EXCEPT | __FE_DENORM)
34 __fesetenv (const fenv_t
*envp
)
38 /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
39 assert (sizeof (fenv_t
) == 28);
41 /* Install the environment specified by ENVP. But there are a few
42 values which we do not want to come from the saved environment.
43 Therefore, we get the current environment and replace the values
44 we want to use from the environment specified by the parameter. */
45 __asm__ ("fnstenv %0" : "=m" (*&temp
));
47 if (envp
== FE_DFL_ENV
)
49 temp
.__control_word
|= FE_ALL_EXCEPT_X86
;
50 temp
.__control_word
&= ~FE_TOWARDZERO
;
51 temp
.__control_word
|= _FPU_EXTENDED
;
52 temp
.__status_word
&= ~FE_ALL_EXCEPT_X86
;
54 else if (envp
== FE_NOMASK_ENV
)
56 temp
.__control_word
&= ~(FE_ALL_EXCEPT
| FE_TOWARDZERO
);
57 /* Keep the "denormal operand" exception masked. */
58 temp
.__control_word
|= __FE_DENORM
;
59 temp
.__control_word
|= _FPU_EXTENDED
;
60 temp
.__status_word
&= ~FE_ALL_EXCEPT_X86
;
64 temp
.__control_word
&= ~(FE_ALL_EXCEPT_X86
67 temp
.__control_word
|= (envp
->__control_word
71 temp
.__status_word
&= ~FE_ALL_EXCEPT_X86
;
72 temp
.__status_word
|= envp
->__status_word
& FE_ALL_EXCEPT_X86
;
75 temp
.__cs_selector
= 0;
77 temp
.__data_offset
= 0;
78 temp
.__data_selector
= 0;
80 __asm__ ("fldenv %0" : : "m" (temp
));
82 if (HAS_CPU_FEATURE (SSE
))
85 __asm__ ("stmxcsr %0" : "=m" (mxcsr
));
87 if (envp
== FE_DFL_ENV
)
89 /* Clear SSE exceptions. */
90 mxcsr
&= ~FE_ALL_EXCEPT_X86
;
91 /* Set mask for SSE MXCSR. */
92 mxcsr
|= (FE_ALL_EXCEPT_X86
<< 7);
93 /* Set rounding to FE_TONEAREST. */
95 mxcsr
|= (FE_TONEAREST
<< 3);
96 /* Clear the FZ and DAZ bits. */
99 else if (envp
== FE_NOMASK_ENV
)
101 /* Clear SSE exceptions. */
102 mxcsr
&= ~FE_ALL_EXCEPT_X86
;
103 /* Do not mask exceptions. */
104 mxcsr
&= ~(FE_ALL_EXCEPT
<< 7);
105 /* Keep the "denormal operand" exception masked. */
106 mxcsr
|= (__FE_DENORM
<< 7);
107 /* Set rounding to FE_TONEAREST. */
109 mxcsr
|= (FE_TONEAREST
<< 3);
110 /* Clear the FZ and DAZ bits. */
116 __asm__ ("ldmxcsr %0" : : "m" (mxcsr
));
123 #include <shlib-compat.h>
124 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
125 strong_alias (__fesetenv
, __old_fesetenv
)
126 compat_symbol (libm
, __old_fesetenv
, fesetenv
, GLIBC_2_1
);
129 libm_hidden_def (__fesetenv
)
130 libm_hidden_ver (__fesetenv
, fesetenv
)
131 versioned_symbol (libm
, __fesetenv
, fesetenv
, GLIBC_2_2
);