fesetenv.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Install given floating-point environment.
  2. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  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. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library. If not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <fenv.h>
  17. int
  18. __fesetenv (const fenv_t *envp)
  19. {
  20. fenv_t temp;
  21. /* Install the environment specified by ENVP. But there are a few
  22. values which we do not want to come from the saved environment.
  23. Therefore, we get the current environment and replace the values
  24. we want to use from the environment specified by the parameter. */
  25. #ifdef __mcoldfire__
  26. __asm__ ("fmove%.l %/fpcr,%0" : "=dm" (temp.__control_register));
  27. __asm__ ("fmove%.l %/fpsr,%0" : "=dm" (temp.__status_register));
  28. __asm__ ("fmove%.l %/fpiar,%0" : "=dm" (temp.__instruction_address));
  29. #else
  30. __asm__ ("fmovem%.l %/fpcr/%/fpsr/%/fpiar,%0" : "=m" (*&temp));
  31. #endif
  32. temp.__status_register &= ~FE_ALL_EXCEPT;
  33. temp.__control_register &= ~((FE_ALL_EXCEPT << 6) | FE_UPWARD);
  34. if (envp == FE_DFL_ENV)
  35. ;
  36. else if (envp == FE_NOMASK_ENV)
  37. temp.__control_register |= FE_ALL_EXCEPT << 6;
  38. else
  39. {
  40. temp.__control_register |= (envp->__control_register
  41. & ((FE_ALL_EXCEPT << 6) | FE_UPWARD));
  42. temp.__status_register |= envp->__status_register & FE_ALL_EXCEPT;
  43. }
  44. #ifdef __mcoldfire__
  45. __asm__ __volatile__ ("fmove%.l %0,%/fpiar"
  46. :: "dm" (temp.__instruction_address));
  47. __asm__ __volatile__ ("fmove%.l %0,%/fpcr"
  48. :: "dm" (temp.__control_register));
  49. __asm__ __volatile__ ("fmove%.l %0,%/fpsr"
  50. :: "dm" (temp.__status_register));
  51. #else
  52. __asm__ __volatile__ ("fmovem%.l %0,%/fpcr/%/fpsr/%/fpiar" : : "m" (*&temp));
  53. #endif
  54. /* Success. */
  55. return 0;
  56. }
  57. #include <shlib-compat.h>
  58. #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
  59. strong_alias (__fesetenv, __old_fesetenv)
  60. compat_symbol (libm, __old_fesetenv, fesetenv, GLIBC_2_1);
  61. #endif
  62. libm_hidden_def (__fesetenv)
  63. libm_hidden_ver (__fesetenv, fesetenv)
  64. versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);