fedisblxcpt.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Disable floating-point exceptions.
  2. Copyright (C) 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Aldy Hernandez <aldyh@redhat.com>, 2004.
  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_libc.h"
  17. #include <syscall.h>
  18. #include <sys/prctl.h>
  19. int
  20. fedisableexcept (int excepts)
  21. {
  22. unsigned int result = 0, pflags, r;
  23. INTERNAL_SYSCALL_DECL (err);
  24. INTERNAL_SYSCALL (prctl, err, 2, PR_GET_FPEXC, &pflags);
  25. /* Save old enable bits. */
  26. if (pflags & PR_FP_EXC_OVF)
  27. result |= FE_OVERFLOW;
  28. if (pflags & PR_FP_EXC_UND)
  29. result |= FE_UNDERFLOW;
  30. if (pflags & PR_FP_EXC_INV)
  31. result |= FE_INVALID;
  32. if (pflags & PR_FP_EXC_DIV)
  33. result |= FE_DIVBYZERO;
  34. if (pflags & PR_FP_EXC_RES)
  35. result |= FE_INEXACT;
  36. if (excepts & FE_INEXACT)
  37. pflags &= ~PR_FP_EXC_RES;
  38. if (excepts & FE_DIVBYZERO)
  39. pflags &= ~PR_FP_EXC_DIV;
  40. if (excepts & FE_UNDERFLOW)
  41. pflags &= ~PR_FP_EXC_UND;
  42. if (excepts & FE_OVERFLOW)
  43. pflags &= ~PR_FP_EXC_OVF;
  44. if (excepts & FE_INVALID)
  45. pflags &= ~PR_FP_EXC_INV;
  46. r = INTERNAL_SYSCALL (prctl, err, 2, PR_SET_FPEXC, pflags);
  47. if (INTERNAL_SYSCALL_ERROR_P (r, err))
  48. return -1;
  49. return result;
  50. }