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