gsl_ieee-utils__fp-gnum68k.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* ieee-utils/fp-gnum68k.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. /* FIXME: I don't have documentation for the M68K so I'm not sure
  59. about the mapping of the exceptions below. Maybe someone who does
  60. know could correct this. */
  61. if (exception_mask & GSL_IEEE_MASK_INVALID)
  62. mode |= _FPU_MASK_OPERR ;
  63. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  64. {
  65. /* do nothing */
  66. }
  67. else
  68. {
  69. GSL_ERROR ("the denormalized operand exception has not been implemented for m68k yet. Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  70. /*mode |= _FPU_MASK_DM ; ???? */
  71. }
  72. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  73. mode |= _FPU_MASK_DZ ;
  74. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  75. mode |= _FPU_MASK_OVFL ;
  76. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  77. mode |= _FPU_MASK_UNFL ;
  78. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  79. {
  80. mode &= ~ (_FPU_MASK_INEX1 | _FPU_MASK_INEX2) ;
  81. }
  82. else
  83. {
  84. mode |= (_FPU_MASK_INEX1 | _FPU_MASK_INEX2) ;
  85. }
  86. _FPU_SETCW(mode) ;
  87. return GSL_SUCCESS ;
  88. }