blob: 8bc2f6963324de776a3ab66ec33638e2b8598211 [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
Maciej W. Rozyckic9a10842015-04-03 23:25:38 +010047static inline int ieee754_class_nan(int xc)
48{
49 return xc >= IEEE754_CLASS_SNAN;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define COMPXSP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020053 unsigned xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define COMPYSP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020056 unsigned ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Paul Burtone2d11e12016-04-21 14:04:51 +010058#define COMPZSP \
59 unsigned zm; int ze; int zs; int zc
60
Ralf Baechle47fa0c02014-04-16 11:00:12 +020061#define EXPLODESP(v, vc, vs, ve, vm) \
62{ \
63 vs = SPSIGN(v); \
64 ve = SPBEXP(v); \
65 vm = SPMANT(v); \
66 if (ve == SP_EMAX+1+SP_EBIAS) { \
67 if (vm == 0) \
68 vc = IEEE754_CLASS_INF; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000069 else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \
Markos Chandras16645742015-07-16 16:43:33 +010070 vc = IEEE754_CLASS_QNAN; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000071 else \
72 vc = IEEE754_CLASS_SNAN; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020073 } else if (ve == SP_EMIN-1+SP_EBIAS) { \
74 if (vm) { \
75 ve = SP_EMIN; \
76 vc = IEEE754_CLASS_DNORM; \
77 } else \
78 vc = IEEE754_CLASS_ZERO; \
79 } else { \
80 ve -= SP_EBIAS; \
81 vm |= SP_HIDDEN_BIT; \
82 vc = IEEE754_CLASS_NORM; \
83 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
Ralf Baechle21a151d2007-10-11 23:46:15 +010085#define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
86#define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +010087#define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89
90#define COMPXDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020091 u64 xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#define COMPYDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020094 u64 ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Paul Burtone2d11e12016-04-21 14:04:51 +010096#define COMPZDP \
97 u64 zm; int ze; int zs; int zc
98
Ralf Baechle47fa0c02014-04-16 11:00:12 +020099#define EXPLODEDP(v, vc, vs, ve, vm) \
100{ \
101 vm = DPMANT(v); \
102 vs = DPSIGN(v); \
103 ve = DPBEXP(v); \
104 if (ve == DP_EMAX+1+DP_EBIAS) { \
105 if (vm == 0) \
106 vc = IEEE754_CLASS_INF; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +0000107 else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200108 vc = IEEE754_CLASS_QNAN; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +0000109 else \
110 vc = IEEE754_CLASS_SNAN; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200111 } else if (ve == DP_EMIN-1+DP_EBIAS) { \
112 if (vm) { \
113 ve = DP_EMIN; \
114 vc = IEEE754_CLASS_DNORM; \
Markos Chandras16645742015-07-16 16:43:33 +0100115 } else \
116 vc = IEEE754_CLASS_ZERO; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200117 } else { \
118 ve -= DP_EBIAS; \
119 vm |= DP_HIDDEN_BIT; \
120 vc = IEEE754_CLASS_NORM; \
121 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
Ralf Baechle21a151d2007-10-11 23:46:15 +0100123#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
124#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100125#define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200127#define FLUSHDP(v, vc, vs, ve, vm) \
128 if (vc==IEEE754_CLASS_DNORM) { \
129 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200130 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200131 vc = IEEE754_CLASS_ZERO; \
132 ve = DP_EMIN-1+DP_EBIAS; \
133 vm = 0; \
134 v = ieee754dp_zero(vs); \
135 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
137
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200138#define FLUSHSP(v, vc, vs, ve, vm) \
139 if (vc==IEEE754_CLASS_DNORM) { \
140 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200141 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200142 vc = IEEE754_CLASS_ZERO; \
143 ve = SP_EMIN-1+SP_EBIAS; \
144 vm = 0; \
145 v = ieee754sp_zero(vs); \
146 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Ralf Baechle21a151d2007-10-11 23:46:15 +0100149#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
150#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100151#define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm)
Ralf Baechle21a151d2007-10-11 23:46:15 +0100152#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
153#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100154#define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm)
Ralf Baechlebee16532014-04-19 00:15:40 +0200155
156#endif /* __IEEE754INT_H */