spe-raise.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "fpu/fenv_libc.h"
  16. int
  17. __FERAISEEXCEPT_INTERNAL (int excepts)
  18. {
  19. unsigned long f;
  20. f = fegetenv_register ();
  21. f |= (excepts & FE_ALL_EXCEPT);
  22. fesetenv_register (f);
  23. /* Force the operations that cause the exceptions. */
  24. if ((FE_INVALID & excepts) != 0)
  25. {
  26. /* ?? Does not set sticky bit ?? */
  27. /* 0 / 0 */
  28. __asm__ __volatile__ ("efsdiv %0,%0,%1" : : "r" (0), "r" (0));
  29. }
  30. if ((FE_DIVBYZERO & excepts) != 0)
  31. {
  32. /* 1.0 / 0.0 */
  33. __asm__ __volatile__ ("efsdiv %0,%0,%1" : : "r" (1.0F), "r" (0));
  34. }
  35. if ((FE_OVERFLOW & excepts) != 0)
  36. {
  37. /* ?? Does not set sticky bit ?? */
  38. /* Largest normalized number plus itself. */
  39. __asm__ __volatile__ ("efsadd %0,%0,%1" : : "r" (0x7f7fffff), "r" (0x7f7fffff));
  40. }
  41. if ((FE_UNDERFLOW & excepts) != 0)
  42. {
  43. /* ?? Does not set sticky bit ?? */
  44. /* Smallest normalized number times itself. */
  45. __asm__ __volatile__ ("efsmul %0,%0,%1" : : "r" (0x800000), "r" (0x800000));
  46. }
  47. if ((FE_INEXACT & excepts) != 0)
  48. {
  49. /* Smallest normalized minus 1.0 raises the inexact flag. */
  50. __asm__ __volatile__ ("efssub %0,%0,%1" : : "r" (0x00800000), "r" (1.0F));
  51. }
  52. /* Success. */
  53. return 0;
  54. }