gsl_ieee-utils__fp-gnusparc.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* ieee-utils/fp-gnusparc.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include <stdio.h>
  20. #include <fpu_control.h>
  21. #include "gsl_errno.h"
  22. #include "gsl_ieee_utils.h"
  23. int
  24. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  25. {
  26. unsigned short mode = 0 ;
  27. switch (precision)
  28. {
  29. case GSL_IEEE_SINGLE_PRECISION:
  30. mode |= _FPU_SINGLE ;
  31. break ;
  32. case GSL_IEEE_DOUBLE_PRECISION:
  33. mode |= _FPU_DOUBLE ;
  34. break ;
  35. case GSL_IEEE_EXTENDED_PRECISION:
  36. mode |= _FPU_EXTENDED ;
  37. break ;
  38. default:
  39. mode |= _FPU_EXTENDED ;
  40. }
  41. switch (rounding)
  42. {
  43. case GSL_IEEE_ROUND_TO_NEAREST:
  44. mode |= _FPU_RC_NEAREST ;
  45. break ;
  46. case GSL_IEEE_ROUND_DOWN:
  47. mode |= _FPU_RC_DOWN ;
  48. break ;
  49. case GSL_IEEE_ROUND_UP:
  50. mode |= _FPU_RC_UP ;
  51. break ;
  52. case GSL_IEEE_ROUND_TO_ZERO:
  53. mode |= _FPU_RC_ZERO ;
  54. break ;
  55. default:
  56. mode |= _FPU_RC_NEAREST ;
  57. }
  58. if (exception_mask & GSL_IEEE_MASK_INVALID)
  59. mode |= _FPU_MASK_IM ;
  60. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  61. {
  62. /* do nothing */
  63. }
  64. else
  65. {
  66. GSL_ERROR ("sparc does not support the denormalized operand exception. "
  67. "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  68. }
  69. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  70. mode |= _FPU_MASK_ZM ;
  71. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  72. mode |= _FPU_MASK_OM ;
  73. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  74. mode |= _FPU_MASK_UM ;
  75. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  76. {
  77. mode &= ~ _FPU_MASK_PM ;
  78. }
  79. else
  80. {
  81. mode |= _FPU_MASK_PM ;
  82. }
  83. _FPU_SETCW(mode) ;
  84. return GSL_SUCCESS ;
  85. }