feupdateenv.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Install given floating-point environment and raise exceptions.
  2. Copyright (C) 1997,99,2000,01,07 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 <unistd.h>
  18. libm_hidden_proto(fesetenv)
  19. libm_hidden_proto(feraiseexcept)
  20. int
  21. feupdateenv (const fenv_t *envp)
  22. {
  23. fexcept_t temp;
  24. /* unsigned int xtemp = 0; */
  25. /* Save current exceptions. */
  26. __asm__ ("fnstsw %0" : "=m" (*&temp));
  27. #if 0
  28. /* If the CPU supports SSE we test the MXCSR as well. */
  29. if ((GLRO(dl_hwcap) & HWCAP_I386_XMM) != 0)
  30. __asm__ ("stmxcsr %0" : "=m" (*&xtemp));
  31. temp = (temp | xtemp) & FE_ALL_EXCEPT;
  32. #else
  33. temp &= FE_ALL_EXCEPT;
  34. #endif
  35. /* Install new environment. */
  36. fesetenv (envp);
  37. /* Raise the saved exception. Incidently for us the implementation
  38. defined format of the values in objects of type fexcept_t is the
  39. same as the ones specified using the FE_* constants. */
  40. feraiseexcept ((int) temp);
  41. /* Success. */
  42. return 0;
  43. }