2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / fpu / feupdateenv.c
blob5a4000f599491eb3901ff59c037b8f7e6b072b8e
1 /* Install given floating-point environment and raise exceptions.
2 Copyright (C) 1997,99,2000,01,07 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <fenv_libc.h>
22 #include <bp-sym.h>
24 int
25 __feupdateenv (const fenv_t *envp)
27 fenv_union_t old, new;
29 /* Save the currently set exceptions. */
30 new.fenv = *envp;
31 old.fenv = fegetenv_register ();
33 /* Restore rounding mode and exception enable from *envp and merge
34 exceptions. Leave fraction rounded/inexact and FP result/CC bits
35 unchanged. */
36 new.l[1] = (old.l[1] & 0x1FFFFF00) | (new.l[1] & 0x1FF80FFF);
38 /* If the old env has no eabled exceptions and the new env has any enabled
39 exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put
40 the hardware into "precise mode" and may cause the FPU to run slower on
41 some hardware. */
42 if ((old.l[1] & 0x000000F8) == 0 && (new.l[1] & 0x000000F8) != 0)
43 (void)__fe_nomask_env ();
45 /* If the old env had any eabled exceptions and the new env has no enabled
46 exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
47 FPU to run faster because it always takes the default action and can not
48 generate SIGFPE. */
49 if ((old.l[1] & 0x000000F8) != 0 && (new.l[1] & 0x000000F8) == 0)
50 (void)__fe_mask_env ();
52 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
53 fesetenv_register (new.fenv);
55 /* Success. */
56 return 0;
59 #include <shlib-compat.h>
60 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
61 strong_alias (__feupdateenv, __old_feupdateenv)
62 compat_symbol (libm, BP_SYM (__old_feupdateenv), BP_SYM (feupdateenv), GLIBC_2_1);
63 #endif
65 versioned_symbol (libm, BP_SYM (__feupdateenv), BP_SYM (feupdateenv), GLIBC_2_2);