blob: 52b20119e315eebb4910ecafb0777a50333434c8 [file] [log] [blame]
Thomas Gleixner9d5a6342019-05-31 01:09:55 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * IEEE754 floating point
4 * common internal header file
5 */
6/*
7 * MIPS floating point support
8 * Copyright (C) 1994-2000 Algorithmics Ltd.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Ralf Baechlebee16532014-04-19 00:15:40 +020010#ifndef __IEEE754INT_H
11#define __IEEE754INT_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include "ieee754.h"
14
Ralf Baechle21a151d2007-10-11 23:46:15 +010015#define CLPAIR(x, y) ((x)*6+(y))
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Aleksandar Markovicae11c062017-07-27 18:08:57 +020017enum maddf_flags {
18 MADDF_NEGATE_PRODUCT = 1 << 0,
19};
20
Ralf Baechle9e8bad12014-04-19 00:36:32 +020021static inline void ieee754_clearcx(void)
22{
23 ieee754_csr.cx = 0;
24}
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Ralf Baechle9e8bad12014-04-19 00:36:32 +020026static inline void ieee754_setcx(const unsigned int flags)
27{
28 ieee754_csr.cx |= flags;
29 ieee754_csr.sx |= flags;
30}
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ralf Baechle9e8bad12014-04-19 00:36:32 +020032static inline int ieee754_setandtestcx(const unsigned int x)
33{
34 ieee754_setcx(x);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Ralf Baechle9e8bad12014-04-19 00:36:32 +020036 return ieee754_csr.mx & x;
37}
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Maciej W. Rozyckic9a10842015-04-03 23:25:38 +010039static inline int ieee754_class_nan(int xc)
40{
41 return xc >= IEEE754_CLASS_SNAN;
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define COMPXSP \
Aleksandar Markovica58f85b2017-11-02 12:13:59 +010045 unsigned int xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#define COMPYSP \
Aleksandar Markovica58f85b2017-11-02 12:13:59 +010048 unsigned int ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Paul Burtone2d11e12016-04-21 14:04:51 +010050#define COMPZSP \
Aleksandar Markovica58f85b2017-11-02 12:13:59 +010051 unsigned int zm; int ze; int zs; int zc
Paul Burtone2d11e12016-04-21 14:04:51 +010052
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; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000061 else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \
Markos Chandras16645742015-07-16 16:43:33 +010062 vc = IEEE754_CLASS_QNAN; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000063 else \
64 vc = IEEE754_CLASS_SNAN; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020065 } 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)
Paul Burtone2d11e12016-04-21 14:04:51 +010079#define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81
82#define COMPXDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020083 u64 xm; int xe; int xs __maybe_unused; int xc
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85#define COMPYDP \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020086 u64 ym; int ye; int ys; int yc
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Paul Burtone2d11e12016-04-21 14:04:51 +010088#define COMPZDP \
89 u64 zm; int ze; int zs; int zc
90
Ralf Baechle47fa0c02014-04-16 11:00:12 +020091#define EXPLODEDP(v, vc, vs, ve, vm) \
92{ \
93 vm = DPMANT(v); \
94 vs = DPSIGN(v); \
95 ve = DPBEXP(v); \
96 if (ve == DP_EMAX+1+DP_EBIAS) { \
97 if (vm == 0) \
98 vc = IEEE754_CLASS_INF; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000099 else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200100 vc = IEEE754_CLASS_QNAN; \
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +0000101 else \
102 vc = IEEE754_CLASS_SNAN; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200103 } else if (ve == DP_EMIN-1+DP_EBIAS) { \
104 if (vm) { \
105 ve = DP_EMIN; \
106 vc = IEEE754_CLASS_DNORM; \
Markos Chandras16645742015-07-16 16:43:33 +0100107 } else \
108 vc = IEEE754_CLASS_ZERO; \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200109 } else { \
110 ve -= DP_EBIAS; \
111 vm |= DP_HIDDEN_BIT; \
112 vc = IEEE754_CLASS_NORM; \
113 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
Ralf Baechle21a151d2007-10-11 23:46:15 +0100115#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
116#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100117#define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200119#define FLUSHDP(v, vc, vs, ve, vm) \
120 if (vc==IEEE754_CLASS_DNORM) { \
121 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200122 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200123 vc = IEEE754_CLASS_ZERO; \
124 ve = DP_EMIN-1+DP_EBIAS; \
125 vm = 0; \
126 v = ieee754dp_zero(vs); \
127 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200130#define FLUSHSP(v, vc, vs, ve, vm) \
131 if (vc==IEEE754_CLASS_DNORM) { \
132 if (ieee754_csr.nod) { \
Ralf Baechle9e8bad12014-04-19 00:36:32 +0200133 ieee754_setcx(IEEE754_INEXACT); \
Ralf Baechle47fa0c02014-04-16 11:00:12 +0200134 vc = IEEE754_CLASS_ZERO; \
135 ve = SP_EMIN-1+SP_EBIAS; \
136 vm = 0; \
137 v = ieee754sp_zero(vs); \
138 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
140
Ralf Baechle21a151d2007-10-11 23:46:15 +0100141#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
142#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100143#define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm)
Ralf Baechle21a151d2007-10-11 23:46:15 +0100144#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
145#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
Paul Burtone2d11e12016-04-21 14:04:51 +0100146#define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm)
Ralf Baechlebee16532014-04-19 00:15:40 +0200147
148#endif /* __IEEE754INT_H */