Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / alpha / fpu / fesetenv.c
blob72618dee9174d4c769da88c23fd289f5279c986d
1 /* Install given floating-point environment.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 #include <fenv_libc.h>
21 int
22 __fesetenv (const fenv_t *envp)
24 unsigned long int fpcr;
25 fenv_t env;
27 /* Magic encoding of default values: high bit set (never possible for a
28 user-space address) is not indirect. And we don't even have to get
29 rid of it since we mask things around just below. */
30 if ((long int) envp >= 0)
31 env = *envp;
32 else
33 env = (unsigned long int) envp;
35 /* Reset the rounding mode with the hardware fpcr. Note that the following
36 system call is an implied trap barrier for our modification. */
37 __asm__ __volatile__ ("excb; mf_fpcr %0" : "=f" (fpcr));
38 fpcr = (fpcr & ~FPCR_ROUND_MASK) | (env & FPCR_ROUND_MASK);
39 __asm__ __volatile__ ("mt_fpcr %0" : : "f" (fpcr));
41 /* Reset the exception status and mask with the kernel's FP code. */
42 __ieee_set_fp_control (env & SWCR_ALL_MASK);
44 /* Success. */
45 return 0;
48 #include <shlib-compat.h>
49 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
50 strong_alias (__fesetenv, __old_fesetenv)
51 compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
52 #endif
54 libm_hidden_def (__fesetenv)
55 libm_hidden_ver (__fesetenv, fesetenv)
56 versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);