fesetenv.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Install given floating-point environment.
  2. Copyright (C) 1997-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <fenv_libc.h>
  16. int
  17. __fesetenv (const fenv_t *envp)
  18. {
  19. unsigned long int fpcr;
  20. fenv_t env;
  21. /* Magic encoding of default values: high bit set (never possible for a
  22. user-space address) is not indirect. And we don't even have to get
  23. rid of it since we mask things around just below. */
  24. if ((long int) envp >= 0)
  25. env = *envp;
  26. else
  27. env = (unsigned long int) envp;
  28. /* Reset the rounding mode with the hardware fpcr. Note that the following
  29. system call is an implied trap barrier for our modification. */
  30. __asm__ __volatile__ ("excb; mf_fpcr %0" : "=f" (fpcr));
  31. fpcr = (fpcr & ~FPCR_ROUND_MASK) | (env & FPCR_ROUND_MASK);
  32. __asm__ __volatile__ ("mt_fpcr %0" : : "f" (fpcr));
  33. /* Reset the exception status and mask with the kernel's FP code. */
  34. __ieee_set_fp_control (env & SWCR_ALL_MASK);
  35. /* Success. */
  36. return 0;
  37. }
  38. #include <shlib-compat.h>
  39. #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
  40. strong_alias (__fesetenv, __old_fesetenv)
  41. compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
  42. #endif
  43. libm_hidden_def (__fesetenv)
  44. libm_hidden_ver (__fesetenv, fesetenv)
  45. versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);