1/* Install given floating-point environment.
2 Copyright (C) 1997-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <fenv.h>
20
21int
22__fesetenv (const fenv_t *envp)
23{
24 fenv_t temp;
25
26 /* Install the environment specified by ENVP. But there are a few
27 values which we do not want to come from the saved environment.
28 Therefore, we get the current environment and replace the values
29 we want to use from the environment specified by the parameter. */
30#ifdef __mcoldfire__
31 __asm__ ("fmove%.l %/fpcr,%0" : "=dm" (temp.__control_register));
32 __asm__ ("fmove%.l %/fpsr,%0" : "=dm" (temp.__status_register));
33 __asm__ ("fmove%.l %/fpiar,%0" : "=dm" (temp.__instruction_address));
34#else
35 __asm__ ("fmovem%.l %/fpcr/%/fpsr/%/fpiar,%0" : "=m" (*&temp));
36#endif
37
38 temp.__status_register &= ~FE_ALL_EXCEPT;
39 temp.__control_register &= ~((FE_ALL_EXCEPT << 6) | FE_UPWARD);
40 if (envp == FE_DFL_ENV)
41 ;
42 else if (envp == FE_NOMASK_ENV)
43 temp.__control_register |= FE_ALL_EXCEPT << 6;
44 else
45 {
46 temp.__control_register |= (envp->__control_register
47 & ((FE_ALL_EXCEPT << 6) | FE_UPWARD));
48 temp.__status_register |= envp->__status_register & FE_ALL_EXCEPT;
49 }
50
51#ifdef __mcoldfire__
52 __asm__ __volatile__ ("fmove%.l %0,%/fpiar"
53 :: "dm" (temp.__instruction_address));
54 __asm__ __volatile__ ("fmove%.l %0,%/fpcr"
55 :: "dm" (temp.__control_register));
56 __asm__ __volatile__ ("fmove%.l %0,%/fpsr"
57 :: "dm" (temp.__status_register));
58#else
59 __asm__ __volatile__ ("fmovem%.l %0,%/fpcr/%/fpsr/%/fpiar" : : "m" (*&temp));
60#endif
61
62 /* Success. */
63 return 0;
64}
65
66#include <shlib-compat.h>
67#if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
68strong_alias (__fesetenv, __old_fesetenv)
69compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
70#endif
71
72libm_hidden_def (__fesetenv)
73libm_hidden_ver (__fesetenv, fesetenv)
74versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);
75

source code of glibc/sysdeps/m68k/fpu/fesetenv.c