1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * IEEE754 floating point
4 * common internal header file
7 * MIPS floating point support
8 * Copyright (C) 1994-2000 Algorithmics Ltd.
10 #ifndef __IEEE754INT_H
11 #define __IEEE754INT_H
15 #define CLPAIR(x, y) ((x)*6+(y))
18 MADDF_NEGATE_PRODUCT
= 1 << 0,
19 MADDF_NEGATE_ADDITION
= 1 << 1,
22 static inline void ieee754_clearcx(void)
27 static inline void ieee754_setcx(const unsigned int flags
)
29 ieee754_csr
.cx
|= flags
;
30 ieee754_csr
.sx
|= flags
;
33 static inline int ieee754_setandtestcx(const unsigned int x
)
37 return ieee754_csr
.mx
& x
;
40 static inline int ieee754_class_nan(int xc
)
42 return xc
>= IEEE754_CLASS_SNAN
;
46 unsigned int xm; int xe; int xs __maybe_unused; int xc
49 unsigned int ym; int ye; int ys; int yc
52 unsigned int zm; int ze; int zs; int zc
54 #define EXPLODESP(v, vc, vs, ve, vm) \
59 if (ve == SP_EMAX+1+SP_EBIAS) { \
61 vc = IEEE754_CLASS_INF; \
62 else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \
63 vc = IEEE754_CLASS_QNAN; \
65 vc = IEEE754_CLASS_SNAN; \
66 } else if (ve == SP_EMIN-1+SP_EBIAS) { \
69 vc = IEEE754_CLASS_DNORM; \
71 vc = IEEE754_CLASS_ZERO; \
74 vm |= SP_HIDDEN_BIT; \
75 vc = IEEE754_CLASS_NORM; \
78 #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
79 #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
80 #define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm)
84 u64 xm; int xe; int xs __maybe_unused; int xc
87 u64 ym; int ye; int ys; int yc
90 u64 zm; int ze; int zs; int zc
92 #define EXPLODEDP(v, vc, vs, ve, vm) \
97 if (ve == DP_EMAX+1+DP_EBIAS) { \
99 vc = IEEE754_CLASS_INF; \
100 else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \
101 vc = IEEE754_CLASS_QNAN; \
103 vc = IEEE754_CLASS_SNAN; \
104 } else if (ve == DP_EMIN-1+DP_EBIAS) { \
107 vc = IEEE754_CLASS_DNORM; \
109 vc = IEEE754_CLASS_ZERO; \
112 vm |= DP_HIDDEN_BIT; \
113 vc = IEEE754_CLASS_NORM; \
116 #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
117 #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
118 #define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm)
120 #define FLUSHDP(v, vc, vs, ve, vm) \
121 if (vc==IEEE754_CLASS_DNORM) { \
122 if (ieee754_csr.nod) { \
123 ieee754_setcx(IEEE754_INEXACT); \
124 vc = IEEE754_CLASS_ZERO; \
125 ve = DP_EMIN-1+DP_EBIAS; \
127 v = ieee754dp_zero(vs); \
131 #define FLUSHSP(v, vc, vs, ve, vm) \
132 if (vc==IEEE754_CLASS_DNORM) { \
133 if (ieee754_csr.nod) { \
134 ieee754_setcx(IEEE754_INEXACT); \
135 vc = IEEE754_CLASS_ZERO; \
136 ve = SP_EMIN-1+SP_EBIAS; \
138 v = ieee754sp_zero(vs); \
142 #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
143 #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
144 #define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm)
145 #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
146 #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
147 #define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm)
149 #endif /* __IEEE754INT_H */