gsl_ieee-utils__fp-gnuppc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* ieee-utils/fp-gnuppc.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough, John Fisher
  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. /*
  24. * Identical to fp-gnux86.c, except with references to
  25. * _FPU_SINGLE, _FPU_DOUBLE, _FPU_EXTENDED, _FPU_MASK_DM
  26. * and _FPU_MASK_PM converted to errors.
  27. */
  28. int
  29. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  30. {
  31. unsigned short mode = 0 ;
  32. switch (precision)
  33. {
  34. case GSL_IEEE_SINGLE_PRECISION:
  35. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  36. break ;
  37. case GSL_IEEE_DOUBLE_PRECISION:
  38. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  39. break ;
  40. case GSL_IEEE_EXTENDED_PRECISION:
  41. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  42. break ;
  43. }
  44. switch (rounding)
  45. {
  46. case GSL_IEEE_ROUND_TO_NEAREST:
  47. mode |= _FPU_RC_NEAREST ;
  48. break ;
  49. case GSL_IEEE_ROUND_DOWN:
  50. mode |= _FPU_RC_DOWN ;
  51. break ;
  52. case GSL_IEEE_ROUND_UP:
  53. mode |= _FPU_RC_UP ;
  54. break ;
  55. case GSL_IEEE_ROUND_TO_ZERO:
  56. mode |= _FPU_RC_ZERO ;
  57. break ;
  58. default:
  59. mode |= _FPU_RC_NEAREST ;
  60. }
  61. if (exception_mask & GSL_IEEE_MASK_INVALID)
  62. mode |= _FPU_MASK_IM ;
  63. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  64. {
  65. /* do nothing */
  66. }
  67. else
  68. {
  69. GSL_ERROR ("powerpc does not support the denormalized operand exception. "
  70. "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  71. }
  72. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  73. mode |= _FPU_MASK_ZM ;
  74. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  75. mode |= _FPU_MASK_OM ;
  76. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  77. mode |= _FPU_MASK_UM ;
  78. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  79. {
  80. GSL_ERROR ("powerpc does not support traps for inexact operations", GSL_EUNSUP) ;
  81. }
  82. _FPU_SETCW(mode) ;
  83. return GSL_SUCCESS ;
  84. }