spe-raise.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Raise given exceptions.
  2. Copyright (C) 1997,99,2000,01,02,04 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include "fpu/fenv_libc.h"
  17. int
  18. __FERAISEEXCEPT_INTERNAL (int excepts)
  19. {
  20. unsigned long f;
  21. f = fegetenv_register ();
  22. f |= (excepts & FE_ALL_EXCEPT);
  23. fesetenv_register (f);
  24. /* Force the operations that cause the exceptions. */
  25. if ((FE_INVALID & excepts) != 0)
  26. {
  27. /* ?? Does not set sticky bit ?? */
  28. /* 0 / 0 */
  29. asm volatile ("efsdiv %0,%0,%1" : : "r" (0), "r" (0));
  30. }
  31. if ((FE_DIVBYZERO & excepts) != 0)
  32. {
  33. /* 1.0 / 0.0 */
  34. asm volatile ("efsdiv %0,%0,%1" : : "r" (1.0F), "r" (0));
  35. }
  36. if ((FE_OVERFLOW & excepts) != 0)
  37. {
  38. /* ?? Does not set sticky bit ?? */
  39. /* Largest normalized number plus itself. */
  40. asm volatile ("efsadd %0,%0,%1" : : "r" (0x7f7fffff), "r" (0x7f7fffff));
  41. }
  42. if ((FE_UNDERFLOW & excepts) != 0)
  43. {
  44. /* ?? Does not set sticky bit ?? */
  45. /* Smallest normalized number times itself. */
  46. asm volatile ("efsmul %0,%0,%1" : : "r" (0x800000), "r" (0x800000));
  47. }
  48. if ((FE_INEXACT & excepts) != 0)
  49. {
  50. /* Smallest normalized minus 1.0 raises the inexact flag. */
  51. asm volatile ("efssub %0,%0,%1" : : "r" (0x00800000), "r" (1.0F));
  52. }
  53. /* Success. */
  54. return 0;
  55. }