Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / powerpc / fpu / fesetenv.c
blob4ce41a6fd0e59acbc67c13cbe7d6480986127252
1 /* Install given floating-point environment.
2 Copyright (C) 1997-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <fenv_libc.h>
20 #include <fpu_control.h>
22 #define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
24 int
25 __fesetenv (const fenv_t *envp)
27 fenv_union_t old, new;
29 /* get the currently set exceptions. */
30 new.fenv = *envp;
31 old.fenv = fegetenv_register ();
32 if (old.l == new.l)
33 return 0;
35 /* If the old env has no enabled exceptions and the new env has any enabled
36 exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put the
37 hardware into "precise mode" and may cause the FPU to run slower on some
38 hardware. */
39 if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0)
40 (void) __fe_nomask_env_priv ();
42 /* If the old env had any enabled exceptions and the new env has no enabled
43 exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
44 FPU to run faster because it always takes the default action and can not
45 generate SIGFPE. */
46 if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0)
47 (void)__fe_mask_env ();
49 fesetenv_register (*envp);
51 /* Success. */
52 return 0;
55 #include <shlib-compat.h>
56 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
57 strong_alias (__fesetenv, __old_fesetenv)
58 compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
59 #endif
61 libm_hidden_ver (__fesetenv, fesetenv)
62 versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);