ieee754d.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Some debug functions
  3. *
  4. * MIPS floating point support
  5. *
  6. * Copyright (C) 1994-2000 Algorithmics Ltd.
  7. *
  8. * This program is free software; you can distribute it and/or modify it
  9. * under the terms of the GNU General Public License (Version 2) as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  20. *
  21. * Nov 7, 2000
  22. * Modified to build and operate in Linux kernel environment.
  23. *
  24. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  25. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  26. */
  27. #include <linux/kernel.h>
  28. #include "ieee754.h"
  29. #define DP_EBIAS 1023
  30. #define DP_EMIN (-1022)
  31. #define DP_EMAX 1023
  32. #define DP_FBITS 52
  33. #define SP_EBIAS 127
  34. #define SP_EMIN (-126)
  35. #define SP_EMAX 127
  36. #define SP_FBITS 23
  37. #define DP_MBIT(x) ((u64)1 << (x))
  38. #define DP_HIDDEN_BIT DP_MBIT(DP_FBITS)
  39. #define DP_SIGN_BIT DP_MBIT(63)
  40. #define SP_MBIT(x) ((u32)1 << (x))
  41. #define SP_HIDDEN_BIT SP_MBIT(SP_FBITS)
  42. #define SP_SIGN_BIT SP_MBIT(31)
  43. #define SPSIGN(sp) (sp.parts.sign)
  44. #define SPBEXP(sp) (sp.parts.bexp)
  45. #define SPMANT(sp) (sp.parts.mant)
  46. #define DPSIGN(dp) (dp.parts.sign)
  47. #define DPBEXP(dp) (dp.parts.bexp)
  48. #define DPMANT(dp) (dp.parts.mant)
  49. ieee754dp ieee754dp_dump(char *m, ieee754dp x)
  50. {
  51. int i;
  52. printk("%s", m);
  53. printk("<%08x,%08x>\n", (unsigned) (x.bits >> 32),
  54. (unsigned) x.bits);
  55. printk("\t=");
  56. switch (ieee754dp_class(x)) {
  57. case IEEE754_CLASS_QNAN:
  58. case IEEE754_CLASS_SNAN:
  59. printk("Nan %c", DPSIGN(x) ? '-' : '+');
  60. for (i = DP_FBITS - 1; i >= 0; i--)
  61. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  62. break;
  63. case IEEE754_CLASS_INF:
  64. printk("%cInfinity", DPSIGN(x) ? '-' : '+');
  65. break;
  66. case IEEE754_CLASS_ZERO:
  67. printk("%cZero", DPSIGN(x) ? '-' : '+');
  68. break;
  69. case IEEE754_CLASS_DNORM:
  70. printk("%c0.", DPSIGN(x) ? '-' : '+');
  71. for (i = DP_FBITS - 1; i >= 0; i--)
  72. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  73. printk("e%d", DPBEXP(x) - DP_EBIAS);
  74. break;
  75. case IEEE754_CLASS_NORM:
  76. printk("%c1.", DPSIGN(x) ? '-' : '+');
  77. for (i = DP_FBITS - 1; i >= 0; i--)
  78. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  79. printk("e%d", DPBEXP(x) - DP_EBIAS);
  80. break;
  81. default:
  82. printk("Illegal/Unknown IEEE754 value class");
  83. }
  84. printk("\n");
  85. return x;
  86. }
  87. ieee754sp ieee754sp_dump(char *m, ieee754sp x)
  88. {
  89. int i;
  90. printk("%s=", m);
  91. printk("<%08x>\n", (unsigned) x.bits);
  92. printk("\t=");
  93. switch (ieee754sp_class(x)) {
  94. case IEEE754_CLASS_QNAN:
  95. case IEEE754_CLASS_SNAN:
  96. printk("Nan %c", SPSIGN(x) ? '-' : '+');
  97. for (i = SP_FBITS - 1; i >= 0; i--)
  98. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  99. break;
  100. case IEEE754_CLASS_INF:
  101. printk("%cInfinity", SPSIGN(x) ? '-' : '+');
  102. break;
  103. case IEEE754_CLASS_ZERO:
  104. printk("%cZero", SPSIGN(x) ? '-' : '+');
  105. break;
  106. case IEEE754_CLASS_DNORM:
  107. printk("%c0.", SPSIGN(x) ? '-' : '+');
  108. for (i = SP_FBITS - 1; i >= 0; i--)
  109. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  110. printk("e%d", SPBEXP(x) - SP_EBIAS);
  111. break;
  112. case IEEE754_CLASS_NORM:
  113. printk("%c1.", SPSIGN(x) ? '-' : '+');
  114. for (i = SP_FBITS - 1; i >= 0; i--)
  115. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  116. printk("e%d", SPBEXP(x) - SP_EBIAS);
  117. break;
  118. default:
  119. printk("Illegal/Unknown IEEE754 value class");
  120. }
  121. printk("\n");
  122. return x;
  123. }