Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * MIPS floating point support |
| 3 | * Copyright (C) 1994-2000 Algorithmics Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * This program is free software; you can distribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License (Version 2) as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
Ralf Baechle | 3f7cac4 | 2014-04-26 01:49:14 +0200 | [diff] [blame] | 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * Nov 7, 2000 |
| 19 | * Modification to allow integration with Linux kernel |
| 20 | * |
| 21 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgard, carstenl@mips.com |
| 22 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 23 | */ |
Ralf Baechle | a663bf9 | 2005-10-23 13:44:31 +0100 | [diff] [blame] | 24 | #ifndef __ARCH_MIPS_MATH_EMU_IEEE754_H |
| 25 | #define __ARCH_MIPS_MATH_EMU_IEEE754_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Ralf Baechle | cae5506 | 2014-04-16 00:47:59 +0200 | [diff] [blame] | 27 | #include <linux/compiler.h> |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 28 | #include <asm/byteorder.h> |
Ralf Baechle | e812a73 | 2014-04-19 14:20:54 +0200 | [diff] [blame] | 29 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 31 | #include <linux/sched.h> |
Ralf Baechle | f80cc08 | 2014-04-16 00:40:02 +0200 | [diff] [blame] | 32 | #include <asm/bitfield.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 34 | union ieee754dp { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct { |
Ralf Baechle | f80cc08 | 2014-04-16 00:40:02 +0200 | [diff] [blame] | 36 | __BITFIELD_FIELD(unsigned int sign:1, |
| 37 | __BITFIELD_FIELD(unsigned int bexp:11, |
| 38 | __BITFIELD_FIELD(u64 mant:52, |
| 39 | ;))) |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 40 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | u64 bits; |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 42 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 44 | union ieee754sp { |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 45 | struct { |
| 46 | __BITFIELD_FIELD(unsigned sign:1, |
| 47 | __BITFIELD_FIELD(unsigned bexp:8, |
| 48 | __BITFIELD_FIELD(unsigned mant:23, |
| 49 | ;))) |
| 50 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | u32 bits; |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 52 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * single precision (often aka float) |
| 56 | */ |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 57 | int ieee754sp_class(union ieee754sp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 59 | union ieee754sp ieee754sp_abs(union ieee754sp x); |
| 60 | union ieee754sp ieee754sp_neg(union ieee754sp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 62 | union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y); |
| 63 | union ieee754sp ieee754sp_sub(union ieee754sp x, union ieee754sp y); |
| 64 | union ieee754sp ieee754sp_mul(union ieee754sp x, union ieee754sp y); |
| 65 | union ieee754sp ieee754sp_div(union ieee754sp x, union ieee754sp y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 67 | union ieee754sp ieee754sp_fint(int x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 68 | union ieee754sp ieee754sp_flong(s64 x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 69 | union ieee754sp ieee754sp_fdp(union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 71 | int ieee754sp_tint(union ieee754sp x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 72 | s64 ieee754sp_tlong(union ieee754sp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 74 | int ieee754sp_cmp(union ieee754sp x, union ieee754sp y, int cop, int sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 76 | union ieee754sp ieee754sp_sqrt(union ieee754sp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Markos Chandras | e24c3be | 2015-08-13 09:56:31 +0200 | [diff] [blame] | 78 | union ieee754sp ieee754sp_maddf(union ieee754sp z, union ieee754sp x, |
| 79 | union ieee754sp y); |
Markos Chandras | 83d4330 | 2015-08-13 09:56:32 +0200 | [diff] [blame] | 80 | union ieee754sp ieee754sp_msubf(union ieee754sp z, union ieee754sp x, |
| 81 | union ieee754sp y); |
Markos Chandras | 38db37b | 2015-08-13 09:56:34 +0200 | [diff] [blame] | 82 | int ieee754sp_2008class(union ieee754sp x); |
Markos Chandras | 4e9561b | 2015-08-13 09:56:35 +0200 | [diff] [blame] | 83 | union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y); |
| 84 | union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y); |
Markos Chandras | a79f5f9 | 2015-08-13 09:56:36 +0200 | [diff] [blame] | 85 | union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y); |
| 86 | union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y); |
Markos Chandras | e24c3be | 2015-08-13 09:56:31 +0200 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
| 89 | * double precision (often aka double) |
| 90 | */ |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 91 | int ieee754dp_class(union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 93 | union ieee754dp ieee754dp_add(union ieee754dp x, union ieee754dp y); |
| 94 | union ieee754dp ieee754dp_sub(union ieee754dp x, union ieee754dp y); |
| 95 | union ieee754dp ieee754dp_mul(union ieee754dp x, union ieee754dp y); |
| 96 | union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 98 | union ieee754dp ieee754dp_abs(union ieee754dp x); |
| 99 | union ieee754dp ieee754dp_neg(union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 101 | union ieee754dp ieee754dp_fint(int x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 102 | union ieee754dp ieee754dp_flong(s64 x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 103 | union ieee754dp ieee754dp_fsp(union ieee754sp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 105 | int ieee754dp_tint(union ieee754dp x); |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 106 | s64 ieee754dp_tlong(union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 108 | int ieee754dp_cmp(union ieee754dp x, union ieee754dp y, int cop, int sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 110 | union ieee754dp ieee754dp_sqrt(union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Markos Chandras | e24c3be | 2015-08-13 09:56:31 +0200 | [diff] [blame] | 112 | union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x, |
| 113 | union ieee754dp y); |
Markos Chandras | 83d4330 | 2015-08-13 09:56:32 +0200 | [diff] [blame] | 114 | union ieee754dp ieee754dp_msubf(union ieee754dp z, union ieee754dp x, |
| 115 | union ieee754dp y); |
Markos Chandras | 38db37b | 2015-08-13 09:56:34 +0200 | [diff] [blame] | 116 | int ieee754dp_2008class(union ieee754dp x); |
Markos Chandras | 4e9561b | 2015-08-13 09:56:35 +0200 | [diff] [blame] | 117 | union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y); |
| 118 | union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y); |
Markos Chandras | a79f5f9 | 2015-08-13 09:56:36 +0200 | [diff] [blame] | 119 | union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y); |
| 120 | union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | |
| 123 | /* 5 types of floating point number |
| 124 | */ |
Ralf Baechle | 9e8bad1 | 2014-04-19 00:36:32 +0200 | [diff] [blame] | 125 | enum { |
| 126 | IEEE754_CLASS_NORM = 0x00, |
| 127 | IEEE754_CLASS_ZERO = 0x01, |
| 128 | IEEE754_CLASS_DNORM = 0x02, |
| 129 | IEEE754_CLASS_INF = 0x03, |
| 130 | IEEE754_CLASS_SNAN = 0x04, |
| 131 | IEEE754_CLASS_QNAN = 0x05, |
| 132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* exception numbers */ |
| 135 | #define IEEE754_INEXACT 0x01 |
| 136 | #define IEEE754_UNDERFLOW 0x02 |
| 137 | #define IEEE754_OVERFLOW 0x04 |
| 138 | #define IEEE754_ZERO_DIVIDE 0x08 |
| 139 | #define IEEE754_INVALID_OPERATION 0x10 |
| 140 | |
| 141 | /* cmp operators |
| 142 | */ |
| 143 | #define IEEE754_CLT 0x01 |
| 144 | #define IEEE754_CEQ 0x02 |
| 145 | #define IEEE754_CGT 0x04 |
| 146 | #define IEEE754_CUN 0x08 |
| 147 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 148 | /* |
| 149 | * The control status register |
| 150 | */ |
| 151 | struct _ieee754_csr { |
Maciej W. Rozycki | f1f3b7e | 2015-04-03 23:27:38 +0100 | [diff] [blame] | 152 | __BITFIELD_FIELD(unsigned fcc:7, /* condition[7:1] */ |
| 153 | __BITFIELD_FIELD(unsigned nod:1, /* set 1 for no denormals */ |
| 154 | __BITFIELD_FIELD(unsigned c:1, /* condition[0] */ |
| 155 | __BITFIELD_FIELD(unsigned pad0:3, |
| 156 | __BITFIELD_FIELD(unsigned abs2008:1, /* IEEE 754-2008 ABS/NEG.fmt */ |
| 157 | __BITFIELD_FIELD(unsigned nan2008:1, /* IEEE 754-2008 NaN mode */ |
Ralf Baechle | f80cc08 | 2014-04-16 00:40:02 +0200 | [diff] [blame] | 158 | __BITFIELD_FIELD(unsigned cx:6, /* exceptions this operation */ |
| 159 | __BITFIELD_FIELD(unsigned mx:5, /* exception enable mask */ |
| 160 | __BITFIELD_FIELD(unsigned sx:5, /* exceptions total */ |
| 161 | __BITFIELD_FIELD(unsigned rm:2, /* current rounding mode */ |
Maciej W. Rozycki | f1f3b7e | 2015-04-03 23:27:38 +0100 | [diff] [blame] | 162 | ;)))))))))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | }; |
Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 164 | #define ieee754_csr (*(struct _ieee754_csr *)(¤t->thread.fpu.fcr31)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 166 | static inline unsigned ieee754_getrm(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | return (ieee754_csr.rm); |
| 169 | } |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 170 | static inline unsigned ieee754_setrm(unsigned rm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | return (ieee754_csr.rm = rm); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * get current exceptions |
| 177 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 178 | static inline unsigned ieee754_getcx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
| 180 | return (ieee754_csr.cx); |
| 181 | } |
| 182 | |
| 183 | /* test for current exception condition |
| 184 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 185 | static inline int ieee754_cxtest(unsigned n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
| 187 | return (ieee754_csr.cx & n); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * get sticky exceptions |
| 192 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 193 | static inline unsigned ieee754_getsx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | return (ieee754_csr.sx); |
| 196 | } |
| 197 | |
| 198 | /* clear sticky conditions |
| 199 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 200 | static inline unsigned ieee754_clrsx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | return (ieee754_csr.sx = 0); |
| 203 | } |
| 204 | |
| 205 | /* test for sticky exception condition |
| 206 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 207 | static inline int ieee754_sxtest(unsigned n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | return (ieee754_csr.sx & n); |
| 210 | } |
| 211 | |
| 212 | /* debugging */ |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 213 | union ieee754sp ieee754sp_dump(char *s, union ieee754sp x); |
| 214 | union ieee754dp ieee754dp_dump(char *s, union ieee754dp x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Maciej W. Rozycki | 1796ec7 | 2015-04-03 23:24:09 +0100 | [diff] [blame] | 216 | #define IEEE754_SPCVAL_PZERO 0 /* +0.0 */ |
| 217 | #define IEEE754_SPCVAL_NZERO 1 /* -0.0 */ |
| 218 | #define IEEE754_SPCVAL_PONE 2 /* +1.0 */ |
| 219 | #define IEEE754_SPCVAL_NONE 3 /* -1.0 */ |
| 220 | #define IEEE754_SPCVAL_PTEN 4 /* +10.0 */ |
| 221 | #define IEEE754_SPCVAL_NTEN 5 /* -10.0 */ |
| 222 | #define IEEE754_SPCVAL_PINFINITY 6 /* +inf */ |
| 223 | #define IEEE754_SPCVAL_NINFINITY 7 /* -inf */ |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 224 | #define IEEE754_SPCVAL_INDEF_LEG 8 /* legacy quiet NaN */ |
| 225 | #define IEEE754_SPCVAL_INDEF_2008 9 /* IEEE 754-2008 quiet NaN */ |
| 226 | #define IEEE754_SPCVAL_PMAX 10 /* +max norm */ |
| 227 | #define IEEE754_SPCVAL_NMAX 11 /* -max norm */ |
| 228 | #define IEEE754_SPCVAL_PMIN 12 /* +min norm */ |
| 229 | #define IEEE754_SPCVAL_NMIN 13 /* -min norm */ |
| 230 | #define IEEE754_SPCVAL_PMIND 14 /* +min denorm */ |
| 231 | #define IEEE754_SPCVAL_NMIND 15 /* -min denorm */ |
| 232 | #define IEEE754_SPCVAL_P1E31 16 /* + 1.0e31 */ |
| 233 | #define IEEE754_SPCVAL_P1E63 17 /* + 1.0e63 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 235 | extern const union ieee754dp __ieee754dp_spcvals[]; |
| 236 | extern const union ieee754sp __ieee754sp_spcvals[]; |
Ralf Baechle | 2209bcb | 2014-04-16 01:31:11 +0200 | [diff] [blame] | 237 | #define ieee754dp_spcvals ((const union ieee754dp *)__ieee754dp_spcvals) |
| 238 | #define ieee754sp_spcvals ((const union ieee754sp *)__ieee754sp_spcvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 240 | /* |
| 241 | * Return infinity with given sign |
| 242 | */ |
| 243 | #define ieee754dp_inf(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) |
| 244 | #define ieee754dp_zero(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) |
| 245 | #define ieee754dp_one(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PONE+(sn)]) |
| 246 | #define ieee754dp_ten(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PTEN+(sn)]) |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 247 | #define ieee754dp_indef() (ieee754dp_spcvals[IEEE754_SPCVAL_INDEF_LEG + \ |
| 248 | ieee754_csr.nan2008]) |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 249 | #define ieee754dp_max(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMAX+(sn)]) |
| 250 | #define ieee754dp_min(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIN+(sn)]) |
| 251 | #define ieee754dp_mind(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIND+(sn)]) |
| 252 | #define ieee754dp_1e31() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E31]) |
| 253 | #define ieee754dp_1e63() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E63]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 255 | #define ieee754sp_inf(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) |
| 256 | #define ieee754sp_zero(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) |
| 257 | #define ieee754sp_one(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PONE+(sn)]) |
| 258 | #define ieee754sp_ten(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PTEN+(sn)]) |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 259 | #define ieee754sp_indef() (ieee754sp_spcvals[IEEE754_SPCVAL_INDEF_LEG + \ |
| 260 | ieee754_csr.nan2008]) |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 261 | #define ieee754sp_max(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMAX+(sn)]) |
| 262 | #define ieee754sp_min(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIN+(sn)]) |
| 263 | #define ieee754sp_mind(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIND+(sn)]) |
| 264 | #define ieee754sp_1e31() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E31]) |
| 265 | #define ieee754sp_1e63() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E63]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 267 | /* |
| 268 | * Indefinite integer value |
| 269 | */ |
Ralf Baechle | e812a73 | 2014-04-19 14:20:54 +0200 | [diff] [blame] | 270 | static inline int ieee754si_indef(void) |
| 271 | { |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 272 | return ieee754_csr.nan2008 ? 0 : INT_MAX; |
Ralf Baechle | e812a73 | 2014-04-19 14:20:54 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static inline s64 ieee754di_indef(void) |
| 276 | { |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 277 | return ieee754_csr.nan2008 ? 0 : S64_MAX; |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * Overflow integer value |
| 282 | */ |
| 283 | static inline int ieee754si_overflow(int xs) |
| 284 | { |
| 285 | return ieee754_csr.nan2008 && xs ? INT_MIN : INT_MAX; |
| 286 | } |
| 287 | |
| 288 | static inline s64 ieee754di_overflow(int xs) |
| 289 | { |
| 290 | return ieee754_csr.nan2008 && xs ? S64_MIN : S64_MAX; |
Ralf Baechle | e812a73 | 2014-04-19 14:20:54 +0200 | [diff] [blame] | 291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* result types for xctx.rt */ |
| 294 | #define IEEE754_RT_SP 0 |
| 295 | #define IEEE754_RT_DP 1 |
| 296 | #define IEEE754_RT_XP 2 |
| 297 | #define IEEE754_RT_SI 3 |
| 298 | #define IEEE754_RT_DI 4 |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | /* compat */ |
| 301 | #define ieee754dp_fix(x) ieee754dp_tint(x) |
| 302 | #define ieee754sp_fix(x) ieee754sp_tint(x) |
Ralf Baechle | a663bf9 | 2005-10-23 13:44:31 +0100 | [diff] [blame] | 303 | |
| 304 | #endif /* __ARCH_MIPS_MATH_EMU_IEEE754_H */ |