fesetenv.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Install given floating-point environment.
  2. Copyright (C) 1997,98,99,2000,01,02 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  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. #include <assert.h>
  18. libm_hidden_proto(fesetenv)
  19. int
  20. fesetenv (const fenv_t *envp)
  21. {
  22. fenv_t temp;
  23. /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
  24. assert (sizeof (fenv_t) == 28);
  25. /* Install the environment specified by ENVP. But there are a few
  26. values which we do not want to come from the saved environment.
  27. Therefore, we get the current environment and replace the values
  28. we want to use from the environment specified by the parameter. */
  29. __asm__ ("fnstenv %0" : "=m" (*&temp));
  30. if (envp == FE_DFL_ENV)
  31. {
  32. temp.__control_word |= FE_ALL_EXCEPT;
  33. temp.__control_word &= ~FE_TOWARDZERO;
  34. temp.__status_word &= ~FE_ALL_EXCEPT;
  35. temp.__eip = 0;
  36. temp.__cs_selector = 0;
  37. temp.__opcode = 0;
  38. temp.__data_offset = 0;
  39. temp.__data_selector = 0;
  40. }
  41. else if (envp == FE_NOMASK_ENV)
  42. {
  43. temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
  44. temp.__status_word &= ~FE_ALL_EXCEPT;
  45. temp.__eip = 0;
  46. temp.__cs_selector = 0;
  47. temp.__opcode = 0;
  48. temp.__data_offset = 0;
  49. temp.__data_selector = 0;
  50. }
  51. else
  52. {
  53. temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
  54. temp.__control_word |= (envp->__control_word
  55. & (FE_ALL_EXCEPT | FE_TOWARDZERO));
  56. temp.__status_word &= ~FE_ALL_EXCEPT;
  57. temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
  58. temp.__eip = envp->__eip;
  59. temp.__cs_selector = envp->__cs_selector;
  60. temp.__opcode = envp->__opcode;
  61. temp.__data_offset = envp->__data_offset;
  62. temp.__data_selector = envp->__data_selector;
  63. }
  64. __asm__ ("fldenv %0" : : "m" (temp));
  65. /* Success. */
  66. return 0;
  67. }
  68. libm_hidden_def(fesetenv)