Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IEEE754 floating point |
| 3 | * common internal header file |
| 4 | */ |
| 5 | /* |
| 6 | * MIPS floating point support |
| 7 | * Copyright (C) 1994-2000 Algorithmics Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * 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 Baechle | 3f7cac4 | 2014-04-26 01:49:14 +0200 | [diff] [blame] | 20 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
Ralf Baechle | bee1653 | 2014-04-19 00:15:40 +0200 | [diff] [blame] | 22 | #ifndef __IEEE754INT_H |
| 23 | #define __IEEE754INT_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include "ieee754.h" |
| 26 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 27 | #define CLPAIR(x, y) ((x)*6+(y)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Ralf Baechle | 9e8bad1 | 2014-04-19 00:36:32 +0200 | [diff] [blame] | 29 | static inline void ieee754_clearcx(void) |
| 30 | { |
| 31 | ieee754_csr.cx = 0; |
| 32 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Ralf Baechle | 9e8bad1 | 2014-04-19 00:36:32 +0200 | [diff] [blame] | 34 | static inline void ieee754_setcx(const unsigned int flags) |
| 35 | { |
| 36 | ieee754_csr.cx |= flags; |
| 37 | ieee754_csr.sx |= flags; |
| 38 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Ralf Baechle | 9e8bad1 | 2014-04-19 00:36:32 +0200 | [diff] [blame] | 40 | static inline int ieee754_setandtestcx(const unsigned int x) |
| 41 | { |
| 42 | ieee754_setcx(x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Ralf Baechle | 9e8bad1 | 2014-04-19 00:36:32 +0200 | [diff] [blame] | 44 | return ieee754_csr.mx & x; |
| 45 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Maciej W. Rozycki | c9a1084 | 2015-04-03 23:25:38 +0100 | [diff] [blame] | 47 | static inline int ieee754_class_nan(int xc) |
| 48 | { |
| 49 | return xc >= IEEE754_CLASS_SNAN; |
| 50 | } |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define COMPXSP \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 53 | unsigned xm; int xe; int xs __maybe_unused; int xc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define COMPYSP \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 56 | unsigned ym; int ye; int ys; int yc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 58 | #define EXPLODESP(v, vc, vs, ve, vm) \ |
| 59 | { \ |
| 60 | vs = SPSIGN(v); \ |
| 61 | ve = SPBEXP(v); \ |
| 62 | vm = SPMANT(v); \ |
| 63 | if (ve == SP_EMAX+1+SP_EBIAS) { \ |
| 64 | if (vm == 0) \ |
| 65 | vc = IEEE754_CLASS_INF; \ |
Ralf Baechle | ad8fb553 | 2014-04-22 15:51:55 +0200 | [diff] [blame] | 66 | else if (vm & SP_MBIT(SP_FBITS-1)) \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 67 | vc = IEEE754_CLASS_SNAN; \ |
Markos Chandras | 1664574 | 2015-07-16 16:43:33 +0100 | [diff] [blame^] | 68 | else \ |
| 69 | vc = IEEE754_CLASS_QNAN; \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 70 | } else if (ve == SP_EMIN-1+SP_EBIAS) { \ |
| 71 | if (vm) { \ |
| 72 | ve = SP_EMIN; \ |
| 73 | vc = IEEE754_CLASS_DNORM; \ |
| 74 | } else \ |
| 75 | vc = IEEE754_CLASS_ZERO; \ |
| 76 | } else { \ |
| 77 | ve -= SP_EBIAS; \ |
| 78 | vm |= SP_HIDDEN_BIT; \ |
| 79 | vc = IEEE754_CLASS_NORM; \ |
| 80 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 82 | #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm) |
| 83 | #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | |
| 86 | #define COMPXDP \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 87 | u64 xm; int xe; int xs __maybe_unused; int xc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | #define COMPYDP \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 90 | u64 ym; int ye; int ys; int yc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 92 | #define EXPLODEDP(v, vc, vs, ve, vm) \ |
| 93 | { \ |
| 94 | vm = DPMANT(v); \ |
| 95 | vs = DPSIGN(v); \ |
| 96 | ve = DPBEXP(v); \ |
| 97 | if (ve == DP_EMAX+1+DP_EBIAS) { \ |
| 98 | if (vm == 0) \ |
| 99 | vc = IEEE754_CLASS_INF; \ |
Ralf Baechle | ad8fb553 | 2014-04-22 15:51:55 +0200 | [diff] [blame] | 100 | else if (vm & DP_MBIT(DP_FBITS-1)) \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 101 | vc = IEEE754_CLASS_SNAN; \ |
| 102 | else \ |
| 103 | vc = IEEE754_CLASS_QNAN; \ |
| 104 | } else if (ve == DP_EMIN-1+DP_EBIAS) { \ |
| 105 | if (vm) { \ |
| 106 | ve = DP_EMIN; \ |
| 107 | vc = IEEE754_CLASS_DNORM; \ |
Markos Chandras | 1664574 | 2015-07-16 16:43:33 +0100 | [diff] [blame^] | 108 | } else \ |
| 109 | vc = IEEE754_CLASS_ZERO; \ |
Ralf Baechle | 47fa0c0 | 2014-04-16 11:00:12 +0200 | [diff] [blame] | 110 | } else { \ |
| 111 | ve -= DP_EBIAS; \ |
| 112 | vm |= DP_HIDDEN_BIT; \ |
| 113 | vc = IEEE754_CLASS_NORM; \ |
| 114 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 116 | #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm) |
| 117 | #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym) |
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) |
| 143 | #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm) |
| 144 | #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym) |
Ralf Baechle | bee1653 | 2014-04-19 00:15:40 +0200 | [diff] [blame] | 145 | |
| 146 | #endif /* __IEEE754INT_H */ |