]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/fpu/feupdateenv.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / powerpc / fpu / feupdateenv.c
CommitLineData
6d4752d8 1/* Install given floating-point environment and raise exceptions.
b168057a 2 Copyright (C) 1997-2015 Free Software Foundation, Inc.
6d4752d8 3 This file is part of the GNU C Library.
7210de33 4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6d4752d8
UD
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
6d4752d8
UD
10
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
41bdb6e2 14 Lesser General Public License for more details.
6d4752d8 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
6d4752d8 19
7210de33 20#include <fenv_libc.h>
edba7a54 21#include <fpu_control.h>
6d4752d8 22
edba7a54
UD
23#define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
24
63ae7b63
UD
25int
26__feupdateenv (const fenv_t *envp)
6d4752d8 27{
7210de33 28 fenv_union_t old, new;
6d4752d8 29
7210de33
UD
30 /* Save the currently set exceptions. */
31 new.fenv = *envp;
32 old.fenv = fegetenv_register ();
6d4752d8 33
4a59e9ad
UD
34 /* Restore rounding mode and exception enable from *envp and merge
35 exceptions. Leave fraction rounded/inexact and FP result/CC bits
36 unchanged. */
4a28b3ca 37 new.l = (old.l & 0xffffffff1fffff00LL) | (new.l & 0x1ff80fff);
9c84384c 38
2ccdea26 39 /* If the old env has no enabled exceptions and the new env has any enabled
4a59e9ad
UD
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
42 some hardware. */
4a28b3ca 43 if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0)
bd12ab55 44 (void) __fe_nomask_env_priv ();
9c84384c 45
2ccdea26 46 /* If the old env had any enabled exceptions and the new env has no enabled
4a59e9ad 47 exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
9c84384c 48 FPU to run faster because it always takes the default action and can not
4a59e9ad 49 generate SIGFPE. */
4a28b3ca 50 if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0)
4a59e9ad 51 (void)__fe_mask_env ();
6d4752d8 52
7210de33
UD
53 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
54 fesetenv_register (new.fenv);
63ae7b63
UD
55
56 /* Success. */
57 return 0;
6d4752d8 58}
4eb8a862
RM
59
60#include <shlib-compat.h>
61#if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
63ae7b63 62strong_alias (__feupdateenv, __old_feupdateenv)
e97ed6dd 63compat_symbol (libm, __old_feupdateenv, feupdateenv, GLIBC_2_1);
4eb8a862
RM
64#endif
65
9ff8d36f 66libm_hidden_ver (__feupdateenv, feupdateenv)
e97ed6dd 67versioned_symbol (libm, __feupdateenv, feupdateenv, GLIBC_2_2);