mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-03 18:31:04 +00:00
fec2bd2c2d
fesetenv() reads the current value of the Floating-Point Status and Control Register (FPSCR) to determine the difference between the current state of exception enables and the newly requested state. All of these bits are also returned by the lighter weight 'mffsl' instruction used by fegetenv_status(). Use that instead. Also, remove a local macro _FPU_MASK_ALL in favor of a common macro, FPU_ENABLES_MASK from fenv_libc.h. Finally, use a local variable ('new') in favor of a pointer dereference ('*envp').
60 lines
2.1 KiB
C
60 lines
2.1 KiB
C
/* Install given floating-point environment.
|
|
Copyright (C) 1997-2019 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include <fenv_libc.h>
|
|
#include <fpu_control.h>
|
|
|
|
int
|
|
__fesetenv (const fenv_t *envp)
|
|
{
|
|
fenv_union_t old, new;
|
|
|
|
/* get the currently set exceptions. */
|
|
new.fenv = *envp;
|
|
old.fenv = fegetenv_status ();
|
|
|
|
/* If the old env has no enabled exceptions and the new env has any enabled
|
|
exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put the
|
|
hardware into "precise mode" and may cause the FPU to run slower on some
|
|
hardware. */
|
|
if ((old.l & FPSCR_ENABLES_MASK) == 0 && (new.l & FPSCR_ENABLES_MASK) != 0)
|
|
(void) __fe_nomask_env_priv ();
|
|
|
|
/* If the old env had any enabled exceptions and the new env has no enabled
|
|
exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
|
|
FPU to run faster because it always takes the default action and can not
|
|
generate SIGFPE. */
|
|
if ((old.l & FPSCR_ENABLES_MASK) != 0 && (new.l & FPSCR_ENABLES_MASK) == 0)
|
|
(void)__fe_mask_env ();
|
|
|
|
fesetenv_register (new.fenv);
|
|
|
|
/* Success. */
|
|
return 0;
|
|
}
|
|
|
|
#include <shlib-compat.h>
|
|
#if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
|
|
strong_alias (__fesetenv, __old_fesetenv)
|
|
compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
|
|
#endif
|
|
|
|
libm_hidden_def (__fesetenv)
|
|
libm_hidden_ver (__fesetenv, fesetenv)
|
|
versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);
|