ieee754d.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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/types.h>
  28. #include <linux/printk.h>
  29. #include "ieee754.h"
  30. #include "ieee754sp.h"
  31. #include "ieee754dp.h"
  32. union ieee754dp ieee754dp_dump(char *m, union ieee754dp x)
  33. {
  34. int i;
  35. printk("%s", m);
  36. printk("<%08x,%08x>\n", (unsigned) (x.bits >> 32),
  37. (unsigned) x.bits);
  38. printk("\t=");
  39. switch (ieee754dp_class(x)) {
  40. case IEEE754_CLASS_QNAN:
  41. case IEEE754_CLASS_SNAN:
  42. printk("Nan %c", DPSIGN(x) ? '-' : '+');
  43. for (i = DP_FBITS - 1; i >= 0; i--)
  44. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  45. break;
  46. case IEEE754_CLASS_INF:
  47. printk("%cInfinity", DPSIGN(x) ? '-' : '+');
  48. break;
  49. case IEEE754_CLASS_ZERO:
  50. printk("%cZero", DPSIGN(x) ? '-' : '+');
  51. break;
  52. case IEEE754_CLASS_DNORM:
  53. printk("%c0.", DPSIGN(x) ? '-' : '+');
  54. for (i = DP_FBITS - 1; i >= 0; i--)
  55. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  56. printk("e%d", DPBEXP(x) - DP_EBIAS);
  57. break;
  58. case IEEE754_CLASS_NORM:
  59. printk("%c1.", DPSIGN(x) ? '-' : '+');
  60. for (i = DP_FBITS - 1; i >= 0; i--)
  61. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  62. printk("e%d", DPBEXP(x) - DP_EBIAS);
  63. break;
  64. default:
  65. printk("Illegal/Unknown IEEE754 value class");
  66. }
  67. printk("\n");
  68. return x;
  69. }
  70. union ieee754sp ieee754sp_dump(char *m, union ieee754sp x)
  71. {
  72. int i;
  73. printk("%s=", m);
  74. printk("<%08x>\n", (unsigned) x.bits);
  75. printk("\t=");
  76. switch (ieee754sp_class(x)) {
  77. case IEEE754_CLASS_QNAN:
  78. case IEEE754_CLASS_SNAN:
  79. printk("Nan %c", SPSIGN(x) ? '-' : '+');
  80. for (i = SP_FBITS - 1; i >= 0; i--)
  81. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  82. break;
  83. case IEEE754_CLASS_INF:
  84. printk("%cInfinity", SPSIGN(x) ? '-' : '+');
  85. break;
  86. case IEEE754_CLASS_ZERO:
  87. printk("%cZero", SPSIGN(x) ? '-' : '+');
  88. break;
  89. case IEEE754_CLASS_DNORM:
  90. printk("%c0.", SPSIGN(x) ? '-' : '+');
  91. for (i = SP_FBITS - 1; i >= 0; i--)
  92. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  93. printk("e%d", SPBEXP(x) - SP_EBIAS);
  94. break;
  95. case IEEE754_CLASS_NORM:
  96. printk("%c1.", SPSIGN(x) ? '-' : '+');
  97. for (i = SP_FBITS - 1; i >= 0; i--)
  98. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  99. printk("e%d", SPBEXP(x) - SP_EBIAS);
  100. break;
  101. default:
  102. printk("Illegal/Unknown IEEE754 value class");
  103. }
  104. printk("\n");
  105. return x;
  106. }