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