gsl_ieee-utils__fp-darwin.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* ieee-utils/fp-darwin.c
  2. *
  3. * Copyright (C) 2001 Rodney Sparapani <rsparapa@mcw.edu>
  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 <architecture/ppc/fp_regs.h>
  20. #include "gsl_ieee_utils.h"
  21. #include "gsl_errno.h"
  22. int
  23. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  24. {
  25. ppc_fp_scr_t fp_scr = get_fp_scr() ;
  26. switch (precision)
  27. {
  28. case GSL_IEEE_SINGLE_PRECISION:
  29. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  30. break ;
  31. case GSL_IEEE_DOUBLE_PRECISION:
  32. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  33. break ;
  34. case GSL_IEEE_EXTENDED_PRECISION:
  35. GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  36. break ;
  37. }
  38. switch (rounding)
  39. {
  40. case GSL_IEEE_ROUND_TO_NEAREST:
  41. fp_scr.rn = RN_NEAREST ;
  42. break ;
  43. case GSL_IEEE_ROUND_DOWN:
  44. fp_scr.rn = RN_TOWARD_MINUS ;
  45. break ;
  46. case GSL_IEEE_ROUND_UP:
  47. fp_scr.rn = RN_TOWARD_PLUS ;
  48. break ;
  49. case GSL_IEEE_ROUND_TO_ZERO:
  50. fp_scr.rn = RN_TOWARD_ZERO ;
  51. break ;
  52. default:
  53. fp_scr.rn = RN_NEAREST ;
  54. }
  55. if (exception_mask & GSL_IEEE_MASK_INVALID)
  56. fp_scr.ve = 0 ; //ve bit: invalid op exception enable
  57. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  58. {
  59. /* do nothing */
  60. }
  61. else
  62. {
  63. GSL_ERROR ("powerpc does not support the denormalized operand exception. "
  64. "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  65. }
  66. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  67. fp_scr.ze = 0 ; //ze bit: zero divide exception enable
  68. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  69. fp_scr.oe = 0 ; //oe bit: overflow exception enable
  70. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  71. fp_scr.ue = 0 ; //ue bit: underflow exception enable
  72. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  73. {
  74. fp_scr.xe = 1 ; //xe bit: inexact exception enable
  75. }
  76. else
  77. {
  78. fp_scr.xe = 01 ;
  79. }
  80. set_fp_scr(fp_scr);
  81. return GSL_SUCCESS ;
  82. }