]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libm/i386/fesetenv.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libm / i386 / fesetenv.c
1 /* Install given floating-point environment.
2    Copyright (C) 1997,98,99,2000,01,02 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
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.
10
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.
15
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/>.  */
19
20 #include <fenv.h>
21 #include <assert.h>
22
23 libm_hidden_proto(fesetenv)
24
25 int
26 fesetenv (const fenv_t *envp)
27 {
28   fenv_t temp;
29
30   /* The memory block used by fstenv/fldenv has a size of 28 bytes.  */
31   assert (sizeof (fenv_t) == 28);
32
33   /* Install the environment specified by ENVP.  But there are a few
34      values which we do not want to come from the saved environment.
35      Therefore, we get the current environment and replace the values
36      we want to use from the environment specified by the parameter.  */
37   __asm__ ("fnstenv %0" : "=m" (*&temp));
38
39   if (envp == FE_DFL_ENV)
40     {
41       temp.__control_word |= FE_ALL_EXCEPT;
42       temp.__control_word &= ~FE_TOWARDZERO;
43       temp.__status_word &= ~FE_ALL_EXCEPT;
44       temp.__eip = 0;
45       temp.__cs_selector = 0;
46       temp.__opcode = 0;
47       temp.__data_offset = 0;
48       temp.__data_selector = 0;
49     }
50   else if (envp == FE_NOMASK_ENV)
51     {
52       temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
53       temp.__status_word &= ~FE_ALL_EXCEPT;
54       temp.__eip = 0;
55       temp.__cs_selector = 0;
56       temp.__opcode = 0;
57       temp.__data_offset = 0;
58       temp.__data_selector = 0;
59     }
60   else
61     {
62       temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
63       temp.__control_word |= (envp->__control_word
64                               & (FE_ALL_EXCEPT | FE_TOWARDZERO));
65       temp.__status_word &= ~FE_ALL_EXCEPT;
66       temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
67       temp.__eip = envp->__eip;
68       temp.__cs_selector = envp->__cs_selector;
69       temp.__opcode = envp->__opcode;
70       temp.__data_offset = envp->__data_offset;
71       temp.__data_selector = envp->__data_selector;
72     }
73
74   __asm__ ("fldenv %0" : : "m" (temp));
75
76   /* Success.  */
77   return 0;
78 }
79 libm_hidden_def(fesetenv)