Add Changelog ...
[jlayton/glibc.git] / sysdeps / hppa / fpu / fesetenv.c
1 /* Install given floating-point environment.
2    Copyright (C) 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by David Huggins-Daines <dhd@debian.org>, 2000
5    Based on the m68k version by
6    Andreas Schwab <schwab@suse.de>
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 2.1 of the License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library.  If not, see
20    <http://www.gnu.org/licenses/>.  */
21
22 #include <fenv.h>
23
24 int
25 fesetenv (const fenv_t *envp)
26 {
27   union { unsigned long long buf[4]; fenv_t env; } temp;
28   unsigned long long *bufptr;
29
30   /* Install the environment specified by ENVP.  But there are a few
31      values which we do not want to come from the saved environment.
32      Therefore, we get the current environment and replace the values
33      we want to use from the environment specified by the parameter.  */
34   bufptr = temp.buf;
35   __asm__ (
36            "fstd,ma %%fr0,8(%1)\n"
37            : "=m" (temp) : "r" (bufptr) : "%r0");
38
39   temp.env.__status_word &= ~(FE_ALL_EXCEPT
40                             | (FE_ALL_EXCEPT << 27)
41                             | FE_DOWNWARD);
42   if (envp == FE_DFL_ENV)
43     ;
44   else if (envp == FE_NOMASK_ENV)
45     temp.env.__status_word |= FE_ALL_EXCEPT;
46   else
47     temp.env.__status_word |= (envp->__status_word
48                                & (FE_ALL_EXCEPT
49                                   | FE_DOWNWARD
50                                   | (FE_ALL_EXCEPT << 27)));
51
52   /* Load the new environment. We use bufptr again since the 
53      initial asm has modified the value of the register and here
54      we take advantage of that to load in reverse order so fr0
55      is loaded last and T-Bit is enabled. */
56   __asm__ (
57            "fldd,mb -8(%1),%%fr0\n"
58            : : "m" (temp), "r" (bufptr) : "%r0" );
59
60   /* Success.  */
61   return 0;
62 }
63 libm_hidden_def (fesetenv)