fesetenv.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <fenv.h>
  18. #include <assert.h>
  19. libm_hidden_proto(fesetenv)
  20. int
  21. fesetenv (const fenv_t *envp)
  22. {
  23. fenv_t temp;
  24. /* The memory block used by fstenv/fldenv has a size of 28 bytes. */
  25. assert (sizeof (fenv_t) == 28);
  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. __asm__ ("fnstenv %0" : "=m" (*&temp));
  31. if (envp == FE_DFL_ENV)
  32. {
  33. temp.__control_word |= FE_ALL_EXCEPT;
  34. temp.__control_word &= ~FE_TOWARDZERO;
  35. temp.__status_word &= ~FE_ALL_EXCEPT;
  36. temp.__eip = 0;
  37. temp.__cs_selector = 0;
  38. temp.__opcode = 0;
  39. temp.__data_offset = 0;
  40. temp.__data_selector = 0;
  41. }
  42. else if (envp == FE_NOMASK_ENV)
  43. {
  44. temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
  45. temp.__status_word &= ~FE_ALL_EXCEPT;
  46. temp.__eip = 0;
  47. temp.__cs_selector = 0;
  48. temp.__opcode = 0;
  49. temp.__data_offset = 0;
  50. temp.__data_selector = 0;
  51. }
  52. else
  53. {
  54. temp.__control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDZERO);
  55. temp.__control_word |= (envp->__control_word
  56. & (FE_ALL_EXCEPT | FE_TOWARDZERO));
  57. temp.__status_word &= ~FE_ALL_EXCEPT;
  58. temp.__status_word |= envp->__status_word & FE_ALL_EXCEPT;
  59. temp.__eip = envp->__eip;
  60. temp.__cs_selector = envp->__cs_selector;
  61. temp.__opcode = envp->__opcode;
  62. temp.__data_offset = envp->__data_offset;
  63. temp.__data_selector = envp->__data_selector;
  64. }
  65. __asm__ ("fldenv %0" : : "m" (temp));
  66. /* Success. */
  67. return 0;
  68. }
  69. libm_hidden_def(fesetenv)