Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / i386 / fpu / fesetenv.c
blob95b2f0a1ab9907c383a2b8c20b05e412e7e400d0
1 /* Install given floating-point environment.
2 Copyright (C) 1997-2014 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>
24 int
25 __fesetenv (const fenv_t *envp)
27 fenv_t temp;
29 /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
30 assert (sizeof (fenv_t) == 28);
32 /* Install the environment specified by ENVP. But there are a few
33 values which we do not want to come from the saved environment.
34 Therefore, we get the current environment and replace the values
35 we want to use from the environment specified by the parameter. */
36 __asm__ ("fnstenv %0" : "=m" (*&temp));
38 if (envp == FE_DFL_ENV)
40 temp.__control_word |= FE_ALL_EXCEPT;
41 temp.__control_word &= ~FE_TOWARDZERO;
42 temp.__status_word &= ~FE_ALL_EXCEPT;
43 temp.__eip = 0;
44 temp.__cs_selector = 0;
45 temp.__opcode = 0;
46 temp.__data_offset = 0;
47 temp.__data_selector = 0;
49 else if (envp == FE_NOMASK_ENV)
51 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
52 temp.__status_word &= ~FE_ALL_EXCEPT;
53 temp.__eip = 0;
54 temp.__cs_selector = 0;
55 temp.__opcode = 0;
56 temp.__data_offset = 0;
57 temp.__data_selector = 0;
59 else
61 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
62 temp.__control_word |= (envp->__control_word
63 & (FE_ALL_EXCEPT | FE_TOWARDZERO));
64 temp.__status_word &= ~FE_ALL_EXCEPT;
65 temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
66 temp.__eip = envp->__eip;
67 temp.__cs_selector = envp->__cs_selector;
68 temp.__opcode = envp->__opcode;
69 temp.__data_offset = envp->__data_offset;
70 temp.__data_selector = envp->__data_selector;
73 __asm__ ("fldenv %0" : : "m" (temp));
75 /* Success. */
76 return 0;
79 #include <shlib-compat.h>
80 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
81 strong_alias (__fesetenv, __old_fesetenv)
82 compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
83 #endif
85 libm_hidden_ver (__fesetenv, fesetenv)
86 versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);