Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / i386 / fpu / fesetenv.c
blobd692a9378fb23c76e8fa7a8ee3eaa5b23b9c3d30
1 /* Install given floating-point environment.
2 Copyright (C) 1997-2015 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/>. */
20 #include <fenv.h>
21 #include <assert.h>
22 #include <unistd.h>
23 #include <ldsodefs.h>
24 #include <dl-procinfo.h>
27 int
28 __fesetenv (const fenv_t *envp)
30 fenv_t temp;
32 /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
33 assert (sizeof (fenv_t) == 28);
35 /* Install the environment specified by ENVP. But there are a few
36 values which we do not want to come from the saved environment.
37 Therefore, we get the current environment and replace the values
38 we want to use from the environment specified by the parameter. */
39 __asm__ ("fnstenv %0" : "=m" (*&temp));
41 if (envp == FE_DFL_ENV)
43 temp.__control_word |= FE_ALL_EXCEPT;
44 temp.__control_word &= ~FE_TOWARDZERO;
45 temp.__status_word &= ~FE_ALL_EXCEPT;
47 else if (envp == FE_NOMASK_ENV)
49 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
50 temp.__status_word &= ~FE_ALL_EXCEPT;
52 else
54 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
55 temp.__control_word |= (envp->__control_word
56 & (FE_ALL_EXCEPT | FE_TOWARDZERO));
57 temp.__status_word &= ~FE_ALL_EXCEPT;
58 temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
60 temp.__eip = 0;
61 temp.__cs_selector = 0;
62 temp.__opcode = 0;
63 temp.__data_offset = 0;
64 temp.__data_selector = 0;
66 __asm__ ("fldenv %0" : : "m" (temp));
68 if ((GLRO(dl_hwcap) & HWCAP_I386_XMM) != 0)
70 unsigned int mxcsr;
71 __asm__ ("stmxcsr %0" : "=m" (mxcsr));
73 if (envp == FE_DFL_ENV)
75 /* Set mask for SSE MXCSR. */
76 mxcsr |= (FE_ALL_EXCEPT << 7);
77 /* Set rounding to FE_TONEAREST. */
78 mxcsr &= ~0x6000;
79 mxcsr |= (FE_TONEAREST << 3);
81 else if (envp == FE_NOMASK_ENV)
83 /* Do not mask exceptions. */
84 mxcsr &= ~(FE_ALL_EXCEPT << 7);
85 /* Set rounding to FE_TONEAREST. */
86 mxcsr &= ~0x6000;
87 mxcsr |= (FE_TONEAREST << 3);
89 else
90 mxcsr = envp->__eip;
92 __asm__ ("ldmxcsr %0" : : "m" (mxcsr));
95 /* Success. */
96 return 0;
99 #include <shlib-compat.h>
100 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
101 strong_alias (__fesetenv, __old_fesetenv)
102 compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
103 #endif
105 libm_hidden_ver (__fesetenv, fesetenv)
106 versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);