1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * IEEE754 floating point 4 * common internal header file 5 */ 6 /* 7 * MIPS floating point support 8 * Copyright (C) 1994-2000 Algorithmics Ltd. 9 */ 10 #ifndef __IEEE754INT_H 11 #define __IEEE754INT_H 12 13 #include "ieee754.h" 14 15 #define CLPAIR(x, y) ((x)*6+(y)) 16 17 enum maddf_flags { 18 MADDF_NEGATE_PRODUCT = 1 << 0, 19 }; 20 21 static inline void ieee754_clearcx(void) 22 { 23 ieee754_csr.cx = 0; 24 } 25 26 static inline void ieee754_setcx(const unsigned int flags) 27 { 28 ieee754_csr.cx |= flags; 29 ieee754_csr.sx |= flags; 30 } 31 32 static inline int ieee754_setandtestcx(const unsigned int x) 33 { 34 ieee754_setcx(x); 35 36 return ieee754_csr.mx & x; 37 } 38 39 static inline int ieee754_class_nan(int xc) 40 { 41 return xc >= IEEE754_CLASS_SNAN; 42 } 43 44 #define COMPXSP \ 45 unsigned int xm; int xe; int xs __maybe_unused; int xc 46 47 #define COMPYSP \ 48 unsigned int ym; int ye; int ys; int yc 49 50 #define COMPZSP \ 51 unsigned int zm; int ze; int zs; int zc 52 53 #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; \ 61 else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \ 62 vc = IEEE754_CLASS_QNAN; \ 63 else \ 64 vc = IEEE754_CLASS_SNAN; \ 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 } \ 76 } 77 #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm) 78 #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym) 79 #define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm) 80 81 82 #define COMPXDP \ 83 u64 xm; int xe; int xs __maybe_unused; int xc 84 85 #define COMPYDP \ 86 u64 ym; int ye; int ys; int yc 87 88 #define COMPZDP \ 89 u64 zm; int ze; int zs; int zc 90 91 #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; \ 99 else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \ 100 vc = IEEE754_CLASS_QNAN; \ 101 else \ 102 vc = IEEE754_CLASS_SNAN; \ 103 } else if (ve == DP_EMIN-1+DP_EBIAS) { \ 104 if (vm) { \ 105 ve = DP_EMIN; \ 106 vc = IEEE754_CLASS_DNORM; \ 107 } else \ 108 vc = IEEE754_CLASS_ZERO; \ 109 } else { \ 110 ve -= DP_EBIAS; \ 111 vm |= DP_HIDDEN_BIT; \ 112 vc = IEEE754_CLASS_NORM; \ 113 } \ 114 } 115 #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm) 116 #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym) 117 #define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm) 118 119 #define FLUSHDP(v, vc, vs, ve, vm) \ 120 if (vc==IEEE754_CLASS_DNORM) { \ 121 if (ieee754_csr.nod) { \ 122 ieee754_setcx(IEEE754_INEXACT); \ 123 vc = IEEE754_CLASS_ZERO; \ 124 ve = DP_EMIN-1+DP_EBIAS; \ 125 vm = 0; \ 126 v = ieee754dp_zero(vs); \ 127 } \ 128 } 129 130 #define FLUSHSP(v, vc, vs, ve, vm) \ 131 if (vc==IEEE754_CLASS_DNORM) { \ 132 if (ieee754_csr.nod) { \ 133 ieee754_setcx(IEEE754_INEXACT); \ 134 vc = IEEE754_CLASS_ZERO; \ 135 ve = SP_EMIN-1+SP_EBIAS; \ 136 vm = 0; \ 137 v = ieee754sp_zero(vs); \ 138 } \ 139 } 140 141 #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm) 142 #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym) 143 #define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm) 144 #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm) 145 #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym) 146 #define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm) 147 148 #endif /* __IEEE754INT_H */ 149