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. |
| 4 | * http://www.algor.co.uk |
| 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * This program is free software; you can distribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License (Version 2) as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Nov 7, 2000 |
| 20 | * Modification to allow integration with Linux kernel |
| 21 | * |
| 22 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgard, carstenl@mips.com |
| 23 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 24 | */ |
Ralf Baechle | a663bf9 | 2005-10-23 13:44:31 +0100 | [diff] [blame^] | 25 | #ifndef __ARCH_MIPS_MATH_EMU_IEEE754_H |
| 26 | #define __ARCH_MIPS_MATH_EMU_IEEE754_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 28 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/types.h> |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 30 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Not very pretty, but the Linux kernel's normal va_list definition |
| 34 | * does not allow it to be used as a structure element, as it is here. |
| 35 | */ |
| 36 | #ifndef _STDARG_H |
| 37 | #include <stdarg.h> |
| 38 | #endif |
| 39 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 40 | #ifdef __LITTLE_ENDIAN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | struct ieee754dp_konst { |
| 42 | unsigned mantlo:32; |
| 43 | unsigned manthi:20; |
| 44 | unsigned bexp:11; |
| 45 | unsigned sign:1; |
| 46 | }; |
| 47 | struct ieee754sp_konst { |
| 48 | unsigned mant:23; |
| 49 | unsigned bexp:8; |
| 50 | unsigned sign:1; |
| 51 | }; |
| 52 | |
| 53 | typedef union _ieee754dp { |
| 54 | struct ieee754dp_konst oparts; |
| 55 | struct { |
| 56 | u64 mant:52; |
| 57 | unsigned int bexp:11; |
| 58 | unsigned int sign:1; |
| 59 | } parts; |
| 60 | u64 bits; |
| 61 | double d; |
| 62 | } ieee754dp; |
| 63 | |
| 64 | typedef union _ieee754sp { |
| 65 | struct ieee754sp_konst parts; |
| 66 | float f; |
| 67 | u32 bits; |
| 68 | } ieee754sp; |
| 69 | #endif |
| 70 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 71 | #ifdef __BIG_ENDIAN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct ieee754dp_konst { |
| 73 | unsigned sign:1; |
| 74 | unsigned bexp:11; |
| 75 | unsigned manthi:20; |
| 76 | unsigned mantlo:32; |
| 77 | }; |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | typedef union _ieee754dp { |
| 80 | struct ieee754dp_konst oparts; |
| 81 | struct { |
| 82 | unsigned int sign:1; |
| 83 | unsigned int bexp:11; |
| 84 | u64 mant:52; |
| 85 | } parts; |
| 86 | double d; |
| 87 | u64 bits; |
| 88 | } ieee754dp; |
| 89 | |
| 90 | struct ieee754sp_konst { |
| 91 | unsigned sign:1; |
| 92 | unsigned bexp:8; |
| 93 | unsigned mant:23; |
| 94 | }; |
| 95 | |
| 96 | typedef union _ieee754sp { |
| 97 | struct ieee754sp_konst parts; |
| 98 | float f; |
| 99 | u32 bits; |
| 100 | } ieee754sp; |
| 101 | #endif |
| 102 | |
| 103 | /* |
| 104 | * single precision (often aka float) |
| 105 | */ |
| 106 | int ieee754sp_finite(ieee754sp x); |
| 107 | int ieee754sp_class(ieee754sp x); |
| 108 | |
| 109 | ieee754sp ieee754sp_abs(ieee754sp x); |
| 110 | ieee754sp ieee754sp_neg(ieee754sp x); |
| 111 | ieee754sp ieee754sp_scalb(ieee754sp x, int); |
| 112 | ieee754sp ieee754sp_logb(ieee754sp x); |
| 113 | |
| 114 | /* x with sign of y */ |
| 115 | ieee754sp ieee754sp_copysign(ieee754sp x, ieee754sp y); |
| 116 | |
| 117 | ieee754sp ieee754sp_add(ieee754sp x, ieee754sp y); |
| 118 | ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y); |
| 119 | ieee754sp ieee754sp_mul(ieee754sp x, ieee754sp y); |
| 120 | ieee754sp ieee754sp_div(ieee754sp x, ieee754sp y); |
| 121 | |
| 122 | ieee754sp ieee754sp_fint(int x); |
| 123 | ieee754sp ieee754sp_funs(unsigned x); |
| 124 | ieee754sp ieee754sp_flong(s64 x); |
| 125 | ieee754sp ieee754sp_fulong(u64 x); |
| 126 | ieee754sp ieee754sp_fdp(ieee754dp x); |
| 127 | |
| 128 | int ieee754sp_tint(ieee754sp x); |
| 129 | unsigned int ieee754sp_tuns(ieee754sp x); |
| 130 | s64 ieee754sp_tlong(ieee754sp x); |
| 131 | u64 ieee754sp_tulong(ieee754sp x); |
| 132 | |
| 133 | int ieee754sp_cmp(ieee754sp x, ieee754sp y, int cop, int sig); |
| 134 | /* |
| 135 | * basic sp math |
| 136 | */ |
| 137 | ieee754sp ieee754sp_modf(ieee754sp x, ieee754sp * ip); |
| 138 | ieee754sp ieee754sp_frexp(ieee754sp x, int *exp); |
| 139 | ieee754sp ieee754sp_ldexp(ieee754sp x, int exp); |
| 140 | |
| 141 | ieee754sp ieee754sp_ceil(ieee754sp x); |
| 142 | ieee754sp ieee754sp_floor(ieee754sp x); |
| 143 | ieee754sp ieee754sp_trunc(ieee754sp x); |
| 144 | |
| 145 | ieee754sp ieee754sp_sqrt(ieee754sp x); |
| 146 | |
| 147 | /* |
| 148 | * double precision (often aka double) |
| 149 | */ |
| 150 | int ieee754dp_finite(ieee754dp x); |
| 151 | int ieee754dp_class(ieee754dp x); |
| 152 | |
| 153 | /* x with sign of y */ |
| 154 | ieee754dp ieee754dp_copysign(ieee754dp x, ieee754dp y); |
| 155 | |
| 156 | ieee754dp ieee754dp_add(ieee754dp x, ieee754dp y); |
| 157 | ieee754dp ieee754dp_sub(ieee754dp x, ieee754dp y); |
| 158 | ieee754dp ieee754dp_mul(ieee754dp x, ieee754dp y); |
| 159 | ieee754dp ieee754dp_div(ieee754dp x, ieee754dp y); |
| 160 | |
| 161 | ieee754dp ieee754dp_abs(ieee754dp x); |
| 162 | ieee754dp ieee754dp_neg(ieee754dp x); |
| 163 | ieee754dp ieee754dp_scalb(ieee754dp x, int); |
| 164 | |
| 165 | /* return exponent as integer in floating point format |
| 166 | */ |
| 167 | ieee754dp ieee754dp_logb(ieee754dp x); |
| 168 | |
| 169 | ieee754dp ieee754dp_fint(int x); |
| 170 | ieee754dp ieee754dp_funs(unsigned x); |
| 171 | ieee754dp ieee754dp_flong(s64 x); |
| 172 | ieee754dp ieee754dp_fulong(u64 x); |
| 173 | ieee754dp ieee754dp_fsp(ieee754sp x); |
| 174 | |
| 175 | ieee754dp ieee754dp_ceil(ieee754dp x); |
| 176 | ieee754dp ieee754dp_floor(ieee754dp x); |
| 177 | ieee754dp ieee754dp_trunc(ieee754dp x); |
| 178 | |
| 179 | int ieee754dp_tint(ieee754dp x); |
| 180 | unsigned int ieee754dp_tuns(ieee754dp x); |
| 181 | s64 ieee754dp_tlong(ieee754dp x); |
| 182 | u64 ieee754dp_tulong(ieee754dp x); |
| 183 | |
| 184 | int ieee754dp_cmp(ieee754dp x, ieee754dp y, int cop, int sig); |
| 185 | /* |
| 186 | * basic sp math |
| 187 | */ |
| 188 | ieee754dp ieee754dp_modf(ieee754dp x, ieee754dp * ip); |
| 189 | ieee754dp ieee754dp_frexp(ieee754dp x, int *exp); |
| 190 | ieee754dp ieee754dp_ldexp(ieee754dp x, int exp); |
| 191 | |
| 192 | ieee754dp ieee754dp_ceil(ieee754dp x); |
| 193 | ieee754dp ieee754dp_floor(ieee754dp x); |
| 194 | ieee754dp ieee754dp_trunc(ieee754dp x); |
| 195 | |
| 196 | ieee754dp ieee754dp_sqrt(ieee754dp x); |
| 197 | |
| 198 | |
| 199 | |
| 200 | /* 5 types of floating point number |
| 201 | */ |
| 202 | #define IEEE754_CLASS_NORM 0x00 |
| 203 | #define IEEE754_CLASS_ZERO 0x01 |
| 204 | #define IEEE754_CLASS_DNORM 0x02 |
| 205 | #define IEEE754_CLASS_INF 0x03 |
| 206 | #define IEEE754_CLASS_SNAN 0x04 |
| 207 | #define IEEE754_CLASS_QNAN 0x05 |
| 208 | extern const char *const ieee754_cname[]; |
| 209 | |
| 210 | /* exception numbers */ |
| 211 | #define IEEE754_INEXACT 0x01 |
| 212 | #define IEEE754_UNDERFLOW 0x02 |
| 213 | #define IEEE754_OVERFLOW 0x04 |
| 214 | #define IEEE754_ZERO_DIVIDE 0x08 |
| 215 | #define IEEE754_INVALID_OPERATION 0x10 |
| 216 | |
| 217 | /* cmp operators |
| 218 | */ |
| 219 | #define IEEE754_CLT 0x01 |
| 220 | #define IEEE754_CEQ 0x02 |
| 221 | #define IEEE754_CGT 0x04 |
| 222 | #define IEEE754_CUN 0x08 |
| 223 | |
| 224 | /* rounding mode |
| 225 | */ |
| 226 | #define IEEE754_RN 0 /* round to nearest */ |
| 227 | #define IEEE754_RZ 1 /* round toward zero */ |
| 228 | #define IEEE754_RD 2 /* round toward -Infinity */ |
| 229 | #define IEEE754_RU 3 /* round toward +Infinity */ |
| 230 | |
| 231 | /* other naming */ |
| 232 | #define IEEE754_RM IEEE754_RD |
| 233 | #define IEEE754_RP IEEE754_RU |
| 234 | |
| 235 | /* "normal" comparisons |
| 236 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 237 | static inline int ieee754sp_eq(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | return ieee754sp_cmp(x, y, IEEE754_CEQ, 0); |
| 240 | } |
| 241 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 242 | static inline int ieee754sp_ne(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | return ieee754sp_cmp(x, y, |
| 245 | IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0); |
| 246 | } |
| 247 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 248 | static inline int ieee754sp_lt(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | return ieee754sp_cmp(x, y, IEEE754_CLT, 0); |
| 251 | } |
| 252 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 253 | static inline int ieee754sp_le(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | return ieee754sp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0); |
| 256 | } |
| 257 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 258 | static inline int ieee754sp_gt(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | return ieee754sp_cmp(x, y, IEEE754_CGT, 0); |
| 261 | } |
| 262 | |
| 263 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 264 | static inline int ieee754sp_ge(ieee754sp x, ieee754sp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | return ieee754sp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0); |
| 267 | } |
| 268 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 269 | static inline int ieee754dp_eq(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
| 271 | return ieee754dp_cmp(x, y, IEEE754_CEQ, 0); |
| 272 | } |
| 273 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 274 | static inline int ieee754dp_ne(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
| 276 | return ieee754dp_cmp(x, y, |
| 277 | IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0); |
| 278 | } |
| 279 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 280 | static inline int ieee754dp_lt(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | return ieee754dp_cmp(x, y, IEEE754_CLT, 0); |
| 283 | } |
| 284 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 285 | static inline int ieee754dp_le(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | return ieee754dp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0); |
| 288 | } |
| 289 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 290 | static inline int ieee754dp_gt(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | return ieee754dp_cmp(x, y, IEEE754_CGT, 0); |
| 293 | } |
| 294 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 295 | static inline int ieee754dp_ge(ieee754dp x, ieee754dp y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | return ieee754dp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0); |
| 298 | } |
| 299 | |
| 300 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 301 | /* |
| 302 | * Like strtod |
| 303 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | ieee754dp ieee754dp_fstr(const char *s, char **endp); |
| 305 | char *ieee754dp_tstr(ieee754dp x, int prec, int fmt, int af); |
| 306 | |
| 307 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 308 | /* |
| 309 | * The control status register |
| 310 | */ |
| 311 | struct _ieee754_csr { |
| 312 | #ifdef __BIG_ENDIAN |
| 313 | unsigned pad0:7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | unsigned nod:1; /* set 1 for no denormalised numbers */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 315 | unsigned c:1; /* condition */ |
| 316 | unsigned pad1:5; |
| 317 | unsigned cx:6; /* exceptions this operation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | unsigned mx:5; /* exception enable mask */ |
| 319 | unsigned sx:5; /* exceptions total */ |
| 320 | unsigned rm:2; /* current rounding mode */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 321 | #endif |
| 322 | #ifdef __LITTLE_ENDIAN |
| 323 | unsigned rm:2; /* current rounding mode */ |
| 324 | unsigned sx:5; /* exceptions total */ |
| 325 | unsigned mx:5; /* exception enable mask */ |
| 326 | unsigned cx:6; /* exceptions this operation */ |
| 327 | unsigned pad1:5; |
| 328 | unsigned c:1; /* condition */ |
| 329 | unsigned nod:1; /* set 1 for no denormalised numbers */ |
| 330 | unsigned pad0:7; |
| 331 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | }; |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 333 | #define ieee754_csr (*(struct _ieee754_csr *)(¤t->thread.fpu.soft.fcr31)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 335 | static inline unsigned ieee754_getrm(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
| 337 | return (ieee754_csr.rm); |
| 338 | } |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 339 | static inline unsigned ieee754_setrm(unsigned rm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
| 341 | return (ieee754_csr.rm = rm); |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * get current exceptions |
| 346 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 347 | static inline unsigned ieee754_getcx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | return (ieee754_csr.cx); |
| 350 | } |
| 351 | |
| 352 | /* test for current exception condition |
| 353 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 354 | static inline int ieee754_cxtest(unsigned n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | return (ieee754_csr.cx & n); |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * get sticky exceptions |
| 361 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 362 | static inline unsigned ieee754_getsx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | return (ieee754_csr.sx); |
| 365 | } |
| 366 | |
| 367 | /* clear sticky conditions |
| 368 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 369 | static inline unsigned ieee754_clrsx(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
| 371 | return (ieee754_csr.sx = 0); |
| 372 | } |
| 373 | |
| 374 | /* test for sticky exception condition |
| 375 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 376 | static inline int ieee754_sxtest(unsigned n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | return (ieee754_csr.sx & n); |
| 379 | } |
| 380 | |
| 381 | /* debugging */ |
| 382 | ieee754sp ieee754sp_dump(char *s, ieee754sp x); |
| 383 | ieee754dp ieee754dp_dump(char *s, ieee754dp x); |
| 384 | |
| 385 | #define IEEE754_SPCVAL_PZERO 0 |
| 386 | #define IEEE754_SPCVAL_NZERO 1 |
| 387 | #define IEEE754_SPCVAL_PONE 2 |
| 388 | #define IEEE754_SPCVAL_NONE 3 |
| 389 | #define IEEE754_SPCVAL_PTEN 4 |
| 390 | #define IEEE754_SPCVAL_NTEN 5 |
| 391 | #define IEEE754_SPCVAL_PINFINITY 6 |
| 392 | #define IEEE754_SPCVAL_NINFINITY 7 |
| 393 | #define IEEE754_SPCVAL_INDEF 8 |
| 394 | #define IEEE754_SPCVAL_PMAX 9 /* +max norm */ |
| 395 | #define IEEE754_SPCVAL_NMAX 10 /* -max norm */ |
| 396 | #define IEEE754_SPCVAL_PMIN 11 /* +min norm */ |
| 397 | #define IEEE754_SPCVAL_NMIN 12 /* +min norm */ |
| 398 | #define IEEE754_SPCVAL_PMIND 13 /* +min denorm */ |
| 399 | #define IEEE754_SPCVAL_NMIND 14 /* +min denorm */ |
| 400 | #define IEEE754_SPCVAL_P1E31 15 /* + 1.0e31 */ |
| 401 | #define IEEE754_SPCVAL_P1E63 16 /* + 1.0e63 */ |
| 402 | |
| 403 | extern const struct ieee754dp_konst __ieee754dp_spcvals[]; |
| 404 | extern const struct ieee754sp_konst __ieee754sp_spcvals[]; |
| 405 | #define ieee754dp_spcvals ((const ieee754dp *)__ieee754dp_spcvals) |
| 406 | #define ieee754sp_spcvals ((const ieee754sp *)__ieee754sp_spcvals) |
| 407 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 408 | /* |
| 409 | * Return infinity with given sign |
| 410 | */ |
| 411 | #define ieee754dp_inf(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) |
| 412 | #define ieee754dp_zero(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) |
| 413 | #define ieee754dp_one(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PONE+(sn)]) |
| 414 | #define ieee754dp_ten(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PTEN+(sn)]) |
| 415 | #define ieee754dp_indef() (ieee754dp_spcvals[IEEE754_SPCVAL_INDEF]) |
| 416 | #define ieee754dp_max(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMAX+(sn)]) |
| 417 | #define ieee754dp_min(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIN+(sn)]) |
| 418 | #define ieee754dp_mind(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIND+(sn)]) |
| 419 | #define ieee754dp_1e31() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E31]) |
| 420 | #define ieee754dp_1e63() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E63]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 422 | #define ieee754sp_inf(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) |
| 423 | #define ieee754sp_zero(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) |
| 424 | #define ieee754sp_one(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PONE+(sn)]) |
| 425 | #define ieee754sp_ten(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PTEN+(sn)]) |
| 426 | #define ieee754sp_indef() (ieee754sp_spcvals[IEEE754_SPCVAL_INDEF]) |
| 427 | #define ieee754sp_max(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMAX+(sn)]) |
| 428 | #define ieee754sp_min(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIN+(sn)]) |
| 429 | #define ieee754sp_mind(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIND+(sn)]) |
| 430 | #define ieee754sp_1e31() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E31]) |
| 431 | #define ieee754sp_1e63() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E63]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 433 | /* |
| 434 | * Indefinite integer value |
| 435 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | #define ieee754si_indef() INT_MAX |
| 437 | #ifdef LONG_LONG_MAX |
| 438 | #define ieee754di_indef() LONG_LONG_MAX |
| 439 | #else |
| 440 | #define ieee754di_indef() ((s64)(~0ULL>>1)) |
| 441 | #endif |
| 442 | |
| 443 | /* IEEE exception context, passed to handler */ |
| 444 | struct ieee754xctx { |
| 445 | const char *op; /* operation name */ |
| 446 | int rt; /* result type */ |
| 447 | union { |
| 448 | ieee754sp sp; /* single precision */ |
| 449 | ieee754dp dp; /* double precision */ |
| 450 | #ifdef IEEE854_XP |
| 451 | ieee754xp xp; /* extended precision */ |
| 452 | #endif |
| 453 | int si; /* standard signed integer (32bits) */ |
| 454 | s64 di; /* extended signed integer (64bits) */ |
| 455 | } rv; /* default result format implied by op */ |
| 456 | va_list ap; |
| 457 | }; |
| 458 | |
| 459 | /* result types for xctx.rt */ |
| 460 | #define IEEE754_RT_SP 0 |
| 461 | #define IEEE754_RT_DP 1 |
| 462 | #define IEEE754_RT_XP 2 |
| 463 | #define IEEE754_RT_SI 3 |
| 464 | #define IEEE754_RT_DI 4 |
| 465 | |
| 466 | extern void ieee754_xcpt(struct ieee754xctx *xcp); |
| 467 | |
| 468 | /* compat */ |
| 469 | #define ieee754dp_fix(x) ieee754dp_tint(x) |
| 470 | #define ieee754sp_fix(x) ieee754sp_tint(x) |
Ralf Baechle | a663bf9 | 2005-10-23 13:44:31 +0100 | [diff] [blame^] | 471 | |
| 472 | #endif /* __ARCH_MIPS_MATH_EMU_IEEE754_H */ |