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