Update.
[glibc.git] / sysdeps / i386 / fpu / fesetenv.c
blob4a9cbed43f5bab23c0e8635400a02e7737af7b4b
1 /* Install given floating-point environment.
2 Copyright (C) 1997, 1998, 1999 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <fenv.h>
23 #include <assert.h>
26 void
27 fesetenv (const fenv_t *envp)
29 fenv_t temp;
31 /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
32 assert (sizeof (fenv_t) == 28);
34 /* Install the environment specified by ENVP. But there are a few
35 values which we do not want to come from the saved environment.
36 Therefore, we get the current environment and replace the values
37 we want to use from the environment specified by the parameter. */
38 __asm__ ("fnstenv %0" : "=m" (*&temp));
40 if (envp == FE_DFL_ENV)
42 temp.__control_word |= FE_ALL_EXCEPT;
43 temp.__control_word &= ~FE_TOWARDZERO;
44 temp.__status_word &= ~FE_ALL_EXCEPT;
45 temp.__eip = 0;
46 temp.__cs_selector = 0;
47 temp.__opcode = 0;
48 temp.__data_offset = 0;
49 temp.__data_selector = 0;
51 else if (envp == FE_NOMASK_ENV)
53 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
54 temp.__status_word &= ~FE_ALL_EXCEPT;
55 temp.__eip = 0;
56 temp.__cs_selector = 0;
57 temp.__opcode = 0;
58 temp.__data_offset = 0;
59 temp.__data_selector = 0;
61 else
63 temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
64 temp.__control_word |= (envp->__control_word
65 & (FE_ALL_EXCEPT | FE_TOWARDZERO));
66 temp.__status_word &= ~FE_ALL_EXCEPT;
67 temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
68 temp.__eip = envp->__eip;
69 temp.__cs_selector = envp->__cs_selector;
70 temp.__opcode = envp->__opcode;
71 temp.__data_offset = envp->__data_offset;
72 temp.__data_selector = envp->__data_selector;
75 __asm__ ("fldenv %0" : : "m" (temp));