1 /* Install given floating-point environment and raise exceptions.
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_libc.h>
21 #include <fpu_control.h>
23 #define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
26 __feupdateenv (const fenv_t
*envp
)
28 fenv_union_t old
, new;
30 /* Save the currently set exceptions. */
32 old
.fenv
= fegetenv_register ();
34 /* Restore rounding mode and exception enable from *envp and merge
35 exceptions. Leave fraction rounded/inexact and FP result/CC bits
37 new.l
= (old
.l
& 0xffffffff1fffff00LL
) | (new.l
& 0x1ff80fff);
39 /* If the old env has no enabled exceptions and the new env has any enabled
40 exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put
41 the hardware into "precise mode" and may cause the FPU to run slower on
43 if ((old
.l
& _FPU_MASK_ALL
) == 0 && (new.l
& _FPU_MASK_ALL
) != 0)
44 (void) __fe_nomask_env_priv ();
46 /* If the old env had any enabled exceptions and the new env has no enabled
47 exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
48 FPU to run faster because it always takes the default action and can not
50 if ((old
.l
& _FPU_MASK_ALL
) != 0 && (new.l
& _FPU_MASK_ALL
) == 0)
51 (void)__fe_mask_env ();
53 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
54 fesetenv_register (new.fenv
);
60 #include <shlib-compat.h>
61 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
62 strong_alias (__feupdateenv
, __old_feupdateenv
)
63 compat_symbol (libm
, __old_feupdateenv
, feupdateenv
, GLIBC_2_1
);
66 libm_hidden_def (__feupdateenv
)
67 libm_hidden_ver (__feupdateenv
, feupdateenv
)
68 versioned_symbol (libm
, __feupdateenv
, feupdateenv
, GLIBC_2_2
);