denormal.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * Floating-point emulation code
  5. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. * BEGIN_DESC
  23. *
  24. * File:
  25. * @(#) pa/fp/denormal.c $ Revision: $
  26. *
  27. * Purpose:
  28. * <<please update with a synopsis of the functionality provided by this file>>
  29. *
  30. * External Interfaces:
  31. * <<the following list was autogenerated, please review>>
  32. * dbl_denormalize(dbl_opndp1,dbl_opndp2,inexactflag,rmode)
  33. * sgl_denormalize(sgl_opnd,inexactflag,rmode)
  34. *
  35. * Internal Interfaces:
  36. * <<please update>>
  37. *
  38. * Theory:
  39. * <<please update with a overview of the operation of this file>>
  40. *
  41. * END_DESC
  42. */
  43. #include "float.h"
  44. #include "sgl_float.h"
  45. #include "dbl_float.h"
  46. #include "hppa.h"
  47. #include <linux/kernel.h>
  48. /* #include <machine/sys/mdep_private.h> */
  49. #undef Fpustatus_register
  50. #define Fpustatus_register Fpu_register[0]
  51. void
  52. sgl_denormalize(unsigned int *sgl_opnd, boolean *inexactflag, int rmode)
  53. {
  54. unsigned int opnd;
  55. int sign, exponent;
  56. boolean guardbit = FALSE, stickybit, inexact;
  57. opnd = *sgl_opnd;
  58. stickybit = *inexactflag;
  59. exponent = Sgl_exponent(opnd) - SGL_WRAP;
  60. sign = Sgl_sign(opnd);
  61. Sgl_denormalize(opnd,exponent,guardbit,stickybit,inexact);
  62. if (inexact) {
  63. switch (rmode) {
  64. case ROUNDPLUS:
  65. if (sign == 0) {
  66. Sgl_increment(opnd);
  67. }
  68. break;
  69. case ROUNDMINUS:
  70. if (sign != 0) {
  71. Sgl_increment(opnd);
  72. }
  73. break;
  74. case ROUNDNEAREST:
  75. if (guardbit && (stickybit ||
  76. Sgl_isone_lowmantissa(opnd))) {
  77. Sgl_increment(opnd);
  78. }
  79. break;
  80. }
  81. }
  82. Sgl_set_sign(opnd,sign);
  83. *sgl_opnd = opnd;
  84. *inexactflag = inexact;
  85. return;
  86. }
  87. void
  88. dbl_denormalize(unsigned int *dbl_opndp1,
  89. unsigned int * dbl_opndp2,
  90. boolean *inexactflag,
  91. int rmode)
  92. {
  93. unsigned int opndp1, opndp2;
  94. int sign, exponent;
  95. boolean guardbit = FALSE, stickybit, inexact;
  96. opndp1 = *dbl_opndp1;
  97. opndp2 = *dbl_opndp2;
  98. stickybit = *inexactflag;
  99. exponent = Dbl_exponent(opndp1) - DBL_WRAP;
  100. sign = Dbl_sign(opndp1);
  101. Dbl_denormalize(opndp1,opndp2,exponent,guardbit,stickybit,inexact);
  102. if (inexact) {
  103. switch (rmode) {
  104. case ROUNDPLUS:
  105. if (sign == 0) {
  106. Dbl_increment(opndp1,opndp2);
  107. }
  108. break;
  109. case ROUNDMINUS:
  110. if (sign != 0) {
  111. Dbl_increment(opndp1,opndp2);
  112. }
  113. break;
  114. case ROUNDNEAREST:
  115. if (guardbit && (stickybit ||
  116. Dbl_isone_lowmantissap2(opndp2))) {
  117. Dbl_increment(opndp1,opndp2);
  118. }
  119. break;
  120. }
  121. }
  122. Dbl_set_sign(opndp1,sign);
  123. *dbl_opndp1 = opndp1;
  124. *dbl_opndp2 = opndp2;
  125. *inexactflag = inexact;
  126. return;
  127. }