.
[glibc/history.git] / sysdeps / powerpc / fpu / feupdateenv.c
blob5fca301fe5137d0805ccdd2b1282c911e4e05dd0
1 /* Install given floating-point environment and raise exceptions.
2 Copyright (C) 1997, 1999, 2000, 2001, 2007, 2008
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <fenv_libc.h>
23 #include <fpu_control.h>
24 #include <bp-sym.h>
26 #define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
28 int
29 __feupdateenv (const fenv_t *envp)
31 fenv_union_t old, new;
33 /* Save the currently set exceptions. */
34 new.fenv = *envp;
35 old.fenv = fegetenv_register ();
37 /* Restore rounding mode and exception enable from *envp and merge
38 exceptions. Leave fraction rounded/inexact and FP result/CC bits
39 unchanged. */
40 new.l[1] = (old.l[1] & 0x1FFFFF00) | (new.l[1] & 0x1FF80FFF);
42 /* If the old env has no eabled exceptions and the new env has any enabled
43 exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put
44 the hardware into "precise mode" and may cause the FPU to run slower on
45 some hardware. */
46 if ((old.l[1] & _FPU_MASK_ALL) == 0 && (new.l[1] & _FPU_MASK_ALL) != 0)
47 (void)__fe_nomask_env ();
49 /* If the old env had any eabled exceptions and the new env has no enabled
50 exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
51 FPU to run faster because it always takes the default action and can not
52 generate SIGFPE. */
53 if ((old.l[1] & _FPU_MASK_ALL) != 0 && (new.l[1] & _FPU_MASK_ALL) == 0)
54 (void)__fe_mask_env ();
56 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
57 fesetenv_register (new.fenv);
59 /* Success. */
60 return 0;
63 #include <shlib-compat.h>
64 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
65 strong_alias (__feupdateenv, __old_feupdateenv)
66 compat_symbol (libm, BP_SYM (__old_feupdateenv), BP_SYM (feupdateenv), GLIBC_2_1);
67 #endif
69 versioned_symbol (libm, BP_SYM (__feupdateenv), BP_SYM (feupdateenv), GLIBC_2_2);