ieee754d.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Some debug functions
  4. *
  5. * MIPS floating point support
  6. *
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. *
  9. * Nov 7, 2000
  10. * Modified to build and operate in Linux kernel environment.
  11. *
  12. * Kevin D. Kissell, [email protected] and Carsten Langgaard, [email protected]
  13. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/printk.h>
  17. #include "ieee754.h"
  18. #include "ieee754sp.h"
  19. #include "ieee754dp.h"
  20. union ieee754dp ieee754dp_dump(char *m, union ieee754dp x)
  21. {
  22. int i;
  23. printk("%s", m);
  24. printk("<%08x,%08x>\n", (unsigned) (x.bits >> 32),
  25. (unsigned) x.bits);
  26. printk("\t=");
  27. switch (ieee754dp_class(x)) {
  28. case IEEE754_CLASS_QNAN:
  29. case IEEE754_CLASS_SNAN:
  30. printk("Nan %c", DPSIGN(x) ? '-' : '+');
  31. for (i = DP_FBITS - 1; i >= 0; i--)
  32. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  33. break;
  34. case IEEE754_CLASS_INF:
  35. printk("%cInfinity", DPSIGN(x) ? '-' : '+');
  36. break;
  37. case IEEE754_CLASS_ZERO:
  38. printk("%cZero", DPSIGN(x) ? '-' : '+');
  39. break;
  40. case IEEE754_CLASS_DNORM:
  41. printk("%c0.", DPSIGN(x) ? '-' : '+');
  42. for (i = DP_FBITS - 1; i >= 0; i--)
  43. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  44. printk("e%d", DPBEXP(x) - DP_EBIAS);
  45. break;
  46. case IEEE754_CLASS_NORM:
  47. printk("%c1.", DPSIGN(x) ? '-' : '+');
  48. for (i = DP_FBITS - 1; i >= 0; i--)
  49. printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
  50. printk("e%d", DPBEXP(x) - DP_EBIAS);
  51. break;
  52. default:
  53. printk("Illegal/Unknown IEEE754 value class");
  54. }
  55. printk("\n");
  56. return x;
  57. }
  58. union ieee754sp ieee754sp_dump(char *m, union ieee754sp x)
  59. {
  60. int i;
  61. printk("%s=", m);
  62. printk("<%08x>\n", (unsigned) x.bits);
  63. printk("\t=");
  64. switch (ieee754sp_class(x)) {
  65. case IEEE754_CLASS_QNAN:
  66. case IEEE754_CLASS_SNAN:
  67. printk("Nan %c", SPSIGN(x) ? '-' : '+');
  68. for (i = SP_FBITS - 1; i >= 0; i--)
  69. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  70. break;
  71. case IEEE754_CLASS_INF:
  72. printk("%cInfinity", SPSIGN(x) ? '-' : '+');
  73. break;
  74. case IEEE754_CLASS_ZERO:
  75. printk("%cZero", SPSIGN(x) ? '-' : '+');
  76. break;
  77. case IEEE754_CLASS_DNORM:
  78. printk("%c0.", SPSIGN(x) ? '-' : '+');
  79. for (i = SP_FBITS - 1; i >= 0; i--)
  80. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  81. printk("e%d", SPBEXP(x) - SP_EBIAS);
  82. break;
  83. case IEEE754_CLASS_NORM:
  84. printk("%c1.", SPSIGN(x) ? '-' : '+');
  85. for (i = SP_FBITS - 1; i >= 0; i--)
  86. printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
  87. printk("e%d", SPBEXP(x) - SP_EBIAS);
  88. break;
  89. default:
  90. printk("Illegal/Unknown IEEE754 value class");
  91. }
  92. printk("\n");
  93. return x;
  94. }