]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/fpu/fesetenv.c
138bde0685f0564ce828e68f719aad16bc307ad8
[thirdparty/glibc.git] / sysdeps / powerpc / fpu / fesetenv.c
1 /* Install given floating-point environment.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <fenv_libc.h>
20 #include <fpu_control.h>
21
22 #define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
23
24 int
25 __fesetenv (const fenv_t *envp)
26 {
27 fenv_union_t old, new;
28
29 /* get the currently set exceptions. */
30 new.fenv = *envp;
31 old.fenv = fegetenv_register ();
32 if (old.l == new.l)
33 return 0;
34
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 ();
41
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 ();
48
49 fesetenv_register (*envp);
50
51 /* Success. */
52 return 0;
53 }
54
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
60
61 libm_hidden_ver (__fesetenv, fesetenv)
62 versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);