blob: f0365bb86747db8a64ddaff74eb9eb1b90e4cef2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IEEE754 floating point
3 * common internal header file
4 */
5/*
6 * MIPS floating point support
7 * Copyright (C) 1994-2000 Algorithmics Ltd.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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.
12 *
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.
17 *
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.,
Ralf Baechle3f7cac42014-04-26 01:49:14 +020020 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
Ralf Baechlebee16532014-04-19 00:15:40 +020022#ifndef __IEEE754INT_H
23#define __IEEE754INT_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "ieee754.h"
26
Ralf Baechle21a151d2007-10-11 23:46:15 +010027#define CLPAIR(x, y) ((x)*6+(y))
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Ralf Baechle9e8bad12014-04-19 00:36:32 +020029static inline void ieee754_clearcx(void)
30{
31 ieee754_csr.cx = 0;
32}
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Ralf Baechle9e8bad12014-04-19 00:36:32 +020034static inline void ieee754_setcx(const unsigned int flags)
35{
36 ieee754_csr.cx |= flags;
37 ieee754_csr.sx |= flags;
38}
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Ralf Baechle9e8bad12014-04-19 00:36:32 +020040static inline int ieee754_setandtestcx(const unsigned int x)
41{
42 ieee754_setcx(x);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Ralf Baechle9e8bad12014-04-19 00:36:32 +020044 return ieee754_csr.mx & x;
45}
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define COMPXSP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020048 unsigned xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define COMPYSP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020051 unsigned ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Ralf Baechle47fa0c02014-04-16 11:00:12 +020053#define EXPLODESP(v, vc, vs, ve, vm) \
54{ \
55 vs = SPSIGN(v); \
56 ve = SPBEXP(v); \
57 vm = SPMANT(v); \
58 if (ve == SP_EMAX+1+SP_EBIAS) { \
59 if (vm == 0) \
60 vc = IEEE754_CLASS_INF; \
Ralf Baechlead8fb5532014-04-22 15:51:55 +020061 else if (vm & SP_MBIT(SP_FBITS-1)) \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020062 vc = IEEE754_CLASS_SNAN; \
63 else \
64 vc = IEEE754_CLASS_QNAN; \
65 } else if (ve == SP_EMIN-1+SP_EBIAS) { \
66 if (vm) { \
67 ve = SP_EMIN; \
68 vc = IEEE754_CLASS_DNORM; \
69 } else \
70 vc = IEEE754_CLASS_ZERO; \
71 } else { \
72 ve -= SP_EBIAS; \
73 vm |= SP_HIDDEN_BIT; \
74 vc = IEEE754_CLASS_NORM; \
75 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
Ralf Baechle21a151d2007-10-11 23:46:15 +010077#define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
78#define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80
81#define COMPXDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020082 u64 xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84#define COMPYDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020085 u64 ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Ralf Baechle47fa0c02014-04-16 11:00:12 +020087#define EXPLODEDP(v, vc, vs, ve, vm) \
88{ \
89 vm = DPMANT(v); \
90 vs = DPSIGN(v); \
91 ve = DPBEXP(v); \
92 if (ve == DP_EMAX+1+DP_EBIAS) { \
93 if (vm == 0) \
94 vc = IEEE754_CLASS_INF; \
Ralf Baechlead8fb5532014-04-22 15:51:55 +020095 else if (vm & DP_MBIT(DP_FBITS-1)) \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020096 vc = IEEE754_CLASS_SNAN; \
97 else \
98 vc = IEEE754_CLASS_QNAN; \
99 } else if (ve == DP_EMIN-1+DP_EBIAS) { \
100 if (vm) { \
101 ve = DP_EMIN; \
102 vc = IEEE754_CLASS_DNORM; \
103 } else \
104 vc = IEEE754_CLASS_ZERO; \
105 } else { \
106 ve -= DP_EBIAS; \
107 vm |= DP_HIDDEN_BIT; \
108 vc = IEEE754_CLASS_NORM; \
109 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
Ralf Baechle21a151d2007-10-11 23:46:15 +0100111#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
112#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200114#define FLUSHDP(v, vc, vs, ve, vm) \
115 if (vc==IEEE754_CLASS_DNORM) { \
116 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200117 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200118 vc = IEEE754_CLASS_ZERO; \
119 ve = DP_EMIN-1+DP_EBIAS; \
120 vm = 0; \
121 v = ieee754dp_zero(vs); \
122 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200125#define FLUSHSP(v, vc, vs, ve, vm) \
126 if (vc==IEEE754_CLASS_DNORM) { \
127 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200128 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200129 vc = IEEE754_CLASS_ZERO; \
130 ve = SP_EMIN-1+SP_EBIAS; \
131 vm = 0; \
132 v = ieee754sp_zero(vs); \
133 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135
Ralf Baechle21a151d2007-10-11 23:46:15 +0100136#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
137#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
138#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
139#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
Ralf Baechlebee16532014-04-19 00:15:40 +0200140
141#endif /* __IEEE754INT_H */