Loading...
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
28#include <linux/kernel.h>
29#include "ieee754.h"
30
31#define DP_EBIAS 1023
32#define DP_EMIN (-1022)
33#define DP_EMAX 1023
34#define DP_FBITS 52
35
36#define SP_EBIAS 127
37#define SP_EMIN (-126)
38#define SP_EMAX 127
39#define SP_FBITS 23
40
41#define DP_MBIT(x) ((u64)1 << (x))
42#define DP_HIDDEN_BIT DP_MBIT(DP_FBITS)
43#define DP_SIGN_BIT DP_MBIT(63)
44
45
46#define SP_MBIT(x) ((u32)1 << (x))
47#define SP_HIDDEN_BIT SP_MBIT(SP_FBITS)
48#define SP_SIGN_BIT SP_MBIT(31)
49
50
51#define SPSIGN(sp) (sp.parts.sign)
52#define SPBEXP(sp) (sp.parts.bexp)
53#define SPMANT(sp) (sp.parts.mant)
54
55#define DPSIGN(dp) (dp.parts.sign)
56#define DPBEXP(dp) (dp.parts.bexp)
57#define DPMANT(dp) (dp.parts.mant)
58
59ieee754dp ieee754dp_dump(char *m, ieee754dp x)
60{
61 int i;
62
63 printk("%s", m);
64 printk("<%08x,%08x>\n", (unsigned) (x.bits >> 32),
65 (unsigned) x.bits);
66 printk("\t=");
67 switch (ieee754dp_class(x)) {
68 case IEEE754_CLASS_QNAN:
69 case IEEE754_CLASS_SNAN:
70 printk("Nan %c", DPSIGN(x) ? '-' : '+');
71 for (i = DP_FBITS - 1; i >= 0; i--)
72 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
73 break;
74 case IEEE754_CLASS_INF:
75 printk("%cInfinity", DPSIGN(x) ? '-' : '+');
76 break;
77 case IEEE754_CLASS_ZERO:
78 printk("%cZero", DPSIGN(x) ? '-' : '+');
79 break;
80 case IEEE754_CLASS_DNORM:
81 printk("%c0.", DPSIGN(x) ? '-' : '+');
82 for (i = DP_FBITS - 1; i >= 0; i--)
83 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
84 printk("e%d", DPBEXP(x) - DP_EBIAS);
85 break;
86 case IEEE754_CLASS_NORM:
87 printk("%c1.", DPSIGN(x) ? '-' : '+');
88 for (i = DP_FBITS - 1; i >= 0; i--)
89 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
90 printk("e%d", DPBEXP(x) - DP_EBIAS);
91 break;
92 default:
93 printk("Illegal/Unknown IEEE754 value class");
94 }
95 printk("\n");
96 return x;
97}
98
99ieee754sp ieee754sp_dump(char *m, ieee754sp x)
100{
101 int i;
102
103 printk("%s=", m);
104 printk("<%08x>\n", (unsigned) x.bits);
105 printk("\t=");
106 switch (ieee754sp_class(x)) {
107 case IEEE754_CLASS_QNAN:
108 case IEEE754_CLASS_SNAN:
109 printk("Nan %c", SPSIGN(x) ? '-' : '+');
110 for (i = SP_FBITS - 1; i >= 0; i--)
111 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
112 break;
113 case IEEE754_CLASS_INF:
114 printk("%cInfinity", SPSIGN(x) ? '-' : '+');
115 break;
116 case IEEE754_CLASS_ZERO:
117 printk("%cZero", SPSIGN(x) ? '-' : '+');
118 break;
119 case IEEE754_CLASS_DNORM:
120 printk("%c0.", SPSIGN(x) ? '-' : '+');
121 for (i = SP_FBITS - 1; i >= 0; i--)
122 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
123 printk("e%d", SPBEXP(x) - SP_EBIAS);
124 break;
125 case IEEE754_CLASS_NORM:
126 printk("%c1.", SPSIGN(x) ? '-' : '+');
127 for (i = SP_FBITS - 1; i >= 0; i--)
128 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
129 printk("e%d", SPBEXP(x) - SP_EBIAS);
130 break;
131 default:
132 printk("Illegal/Unknown IEEE754 value class");
133 }
134 printk("\n");
135 return x;
136}
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, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
13 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
14 */
15
16#include <linux/types.h>
17#include <linux/printk.h>
18#include "ieee754.h"
19#include "ieee754sp.h"
20#include "ieee754dp.h"
21
22union ieee754dp ieee754dp_dump(char *m, union ieee754dp x)
23{
24 int i;
25
26 printk("%s", m);
27 printk("<%08x,%08x>\n", (unsigned) (x.bits >> 32),
28 (unsigned) x.bits);
29 printk("\t=");
30 switch (ieee754dp_class(x)) {
31 case IEEE754_CLASS_QNAN:
32 case IEEE754_CLASS_SNAN:
33 printk("Nan %c", DPSIGN(x) ? '-' : '+');
34 for (i = DP_FBITS - 1; i >= 0; i--)
35 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
36 break;
37 case IEEE754_CLASS_INF:
38 printk("%cInfinity", DPSIGN(x) ? '-' : '+');
39 break;
40 case IEEE754_CLASS_ZERO:
41 printk("%cZero", DPSIGN(x) ? '-' : '+');
42 break;
43 case IEEE754_CLASS_DNORM:
44 printk("%c0.", DPSIGN(x) ? '-' : '+');
45 for (i = DP_FBITS - 1; i >= 0; i--)
46 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
47 printk("e%d", DPBEXP(x) - DP_EBIAS);
48 break;
49 case IEEE754_CLASS_NORM:
50 printk("%c1.", DPSIGN(x) ? '-' : '+');
51 for (i = DP_FBITS - 1; i >= 0; i--)
52 printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
53 printk("e%d", DPBEXP(x) - DP_EBIAS);
54 break;
55 default:
56 printk("Illegal/Unknown IEEE754 value class");
57 }
58 printk("\n");
59 return x;
60}
61
62union ieee754sp ieee754sp_dump(char *m, union ieee754sp x)
63{
64 int i;
65
66 printk("%s=", m);
67 printk("<%08x>\n", (unsigned) x.bits);
68 printk("\t=");
69 switch (ieee754sp_class(x)) {
70 case IEEE754_CLASS_QNAN:
71 case IEEE754_CLASS_SNAN:
72 printk("Nan %c", SPSIGN(x) ? '-' : '+');
73 for (i = SP_FBITS - 1; i >= 0; i--)
74 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
75 break;
76 case IEEE754_CLASS_INF:
77 printk("%cInfinity", SPSIGN(x) ? '-' : '+');
78 break;
79 case IEEE754_CLASS_ZERO:
80 printk("%cZero", SPSIGN(x) ? '-' : '+');
81 break;
82 case IEEE754_CLASS_DNORM:
83 printk("%c0.", SPSIGN(x) ? '-' : '+');
84 for (i = SP_FBITS - 1; i >= 0; i--)
85 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
86 printk("e%d", SPBEXP(x) - SP_EBIAS);
87 break;
88 case IEEE754_CLASS_NORM:
89 printk("%c1.", SPSIGN(x) ? '-' : '+');
90 for (i = SP_FBITS - 1; i >= 0; i--)
91 printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
92 printk("e%d", SPBEXP(x) - SP_EBIAS);
93 break;
94 default:
95 printk("Illegal/Unknown IEEE754 value class");
96 }
97 printk("\n");
98 return x;
99}