aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/math-emu/ieee754.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/math-emu/ieee754.h')
-rw-r--r--arch/mips/math-emu/ieee754.h180
1 files changed, 81 insertions, 99 deletions
diff --git a/arch/mips/math-emu/ieee754.h b/arch/mips/math-emu/ieee754.h
index b8772f46972d..171f177c0f88 100644
--- a/arch/mips/math-emu/ieee754.h
+++ b/arch/mips/math-emu/ieee754.h
@@ -1,13 +1,8 @@
1/* single and double precision fp ops
2 * missing extended precision.
3*/
4/* 1/*
5 * MIPS floating point support 2 * MIPS floating point support
6 * Copyright (C) 1994-2000 Algorithmics Ltd. 3 * Copyright (C) 1994-2000 Algorithmics Ltd.
7 * http://www.algor.co.uk 4 * http://www.algor.co.uk
8 * 5 *
9 * ########################################################################
10 *
11 * This program is free software; you can distribute it and/or modify it 6 * This program is free software; you can distribute it and/or modify it
12 * under the terms of the GNU General Public License (Version 2) as 7 * under the terms of the GNU General Public License (Version 2) as
13 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
@@ -21,20 +16,18 @@
21 * with this program; if not, write to the Free Software Foundation, Inc., 16 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 17 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * 18 *
24 * ########################################################################
25 */
26
27/**************************************************************************
28 * Nov 7, 2000 19 * Nov 7, 2000
29 * Modification to allow integration with Linux kernel 20 * Modification to allow integration with Linux kernel
30 * 21 *
31 * Kevin D. Kissell, kevink@mips.com and Carsten Langgard, carstenl@mips.com 22 * Kevin D. Kissell, kevink@mips.com and Carsten Langgard, carstenl@mips.com
32 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. 23 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
33 *************************************************************************/ 24 */
25#ifndef __ARCH_MIPS_MATH_EMU_IEEE754_H
26#define __ARCH_MIPS_MATH_EMU_IEEE754_H
34 27
35#ifdef __KERNEL__ 28#include <asm/byteorder.h>
36/* Going from Algorithmics to Linux native environment, add this */
37#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/sched.h>
38 31
39/* 32/*
40 * Not very pretty, but the Linux kernel's normal va_list definition 33 * Not very pretty, but the Linux kernel's normal va_list definition
@@ -44,18 +37,7 @@
44#include <stdarg.h> 37#include <stdarg.h>
45#endif 38#endif
46 39
47#else 40#ifdef __LITTLE_ENDIAN
48
49/* Note that __KERNEL__ is taken to mean Linux kernel */
50
51#if #system(OpenBSD)
52#include <machine/types.h>
53#endif
54#include <machine/endian.h>
55
56#endif /* __KERNEL__ */
57
58#if (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) || defined(__MIPSEL__)
59struct ieee754dp_konst { 41struct ieee754dp_konst {
60 unsigned mantlo:32; 42 unsigned mantlo:32;
61 unsigned manthi:20; 43 unsigned manthi:20;
@@ -86,13 +68,14 @@ typedef union _ieee754sp {
86} ieee754sp; 68} ieee754sp;
87#endif 69#endif
88 70
89#if (defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN) || defined(__MIPSEB__) 71#ifdef __BIG_ENDIAN
90struct ieee754dp_konst { 72struct ieee754dp_konst {
91 unsigned sign:1; 73 unsigned sign:1;
92 unsigned bexp:11; 74 unsigned bexp:11;
93 unsigned manthi:20; 75 unsigned manthi:20;
94 unsigned mantlo:32; 76 unsigned mantlo:32;
95}; 77};
78
96typedef union _ieee754dp { 79typedef union _ieee754dp {
97 struct ieee754dp_konst oparts; 80 struct ieee754dp_konst oparts;
98 struct { 81 struct {
@@ -222,7 +205,6 @@ ieee754dp ieee754dp_sqrt(ieee754dp x);
222#define IEEE754_CLASS_INF 0x03 205#define IEEE754_CLASS_INF 0x03
223#define IEEE754_CLASS_SNAN 0x04 206#define IEEE754_CLASS_SNAN 0x04
224#define IEEE754_CLASS_QNAN 0x05 207#define IEEE754_CLASS_QNAN 0x05
225extern const char *const ieee754_cname[];
226 208
227/* exception numbers */ 209/* exception numbers */
228#define IEEE754_INEXACT 0x01 210#define IEEE754_INEXACT 0x01
@@ -251,93 +233,109 @@ extern const char *const ieee754_cname[];
251 233
252/* "normal" comparisons 234/* "normal" comparisons
253*/ 235*/
254static __inline int ieee754sp_eq(ieee754sp x, ieee754sp y) 236static inline int ieee754sp_eq(ieee754sp x, ieee754sp y)
255{ 237{
256 return ieee754sp_cmp(x, y, IEEE754_CEQ, 0); 238 return ieee754sp_cmp(x, y, IEEE754_CEQ, 0);
257} 239}
258 240
259static __inline int ieee754sp_ne(ieee754sp x, ieee754sp y) 241static inline int ieee754sp_ne(ieee754sp x, ieee754sp y)
260{ 242{
261 return ieee754sp_cmp(x, y, 243 return ieee754sp_cmp(x, y,
262 IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0); 244 IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0);
263} 245}
264 246
265static __inline int ieee754sp_lt(ieee754sp x, ieee754sp y) 247static inline int ieee754sp_lt(ieee754sp x, ieee754sp y)
266{ 248{
267 return ieee754sp_cmp(x, y, IEEE754_CLT, 0); 249 return ieee754sp_cmp(x, y, IEEE754_CLT, 0);
268} 250}
269 251
270static __inline int ieee754sp_le(ieee754sp x, ieee754sp y) 252static inline int ieee754sp_le(ieee754sp x, ieee754sp y)
271{ 253{
272 return ieee754sp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0); 254 return ieee754sp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0);
273} 255}
274 256
275static __inline int ieee754sp_gt(ieee754sp x, ieee754sp y) 257static inline int ieee754sp_gt(ieee754sp x, ieee754sp y)
276{ 258{
277 return ieee754sp_cmp(x, y, IEEE754_CGT, 0); 259 return ieee754sp_cmp(x, y, IEEE754_CGT, 0);
278} 260}
279 261
280 262
281static __inline int ieee754sp_ge(ieee754sp x, ieee754sp y) 263static inline int ieee754sp_ge(ieee754sp x, ieee754sp y)
282{ 264{
283 return ieee754sp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0); 265 return ieee754sp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0);
284} 266}
285 267
286static __inline int ieee754dp_eq(ieee754dp x, ieee754dp y) 268static inline int ieee754dp_eq(ieee754dp x, ieee754dp y)
287{ 269{
288 return ieee754dp_cmp(x, y, IEEE754_CEQ, 0); 270 return ieee754dp_cmp(x, y, IEEE754_CEQ, 0);
289} 271}
290 272
291static __inline int ieee754dp_ne(ieee754dp x, ieee754dp y) 273static inline int ieee754dp_ne(ieee754dp x, ieee754dp y)
292{ 274{
293 return ieee754dp_cmp(x, y, 275 return ieee754dp_cmp(x, y,
294 IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0); 276 IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0);
295} 277}
296 278
297static __inline int ieee754dp_lt(ieee754dp x, ieee754dp y) 279static inline int ieee754dp_lt(ieee754dp x, ieee754dp y)
298{ 280{
299 return ieee754dp_cmp(x, y, IEEE754_CLT, 0); 281 return ieee754dp_cmp(x, y, IEEE754_CLT, 0);
300} 282}
301 283
302static __inline int ieee754dp_le(ieee754dp x, ieee754dp y) 284static inline int ieee754dp_le(ieee754dp x, ieee754dp y)
303{ 285{
304 return ieee754dp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0); 286 return ieee754dp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0);
305} 287}
306 288
307static __inline int ieee754dp_gt(ieee754dp x, ieee754dp y) 289static inline int ieee754dp_gt(ieee754dp x, ieee754dp y)
308{ 290{
309 return ieee754dp_cmp(x, y, IEEE754_CGT, 0); 291 return ieee754dp_cmp(x, y, IEEE754_CGT, 0);
310} 292}
311 293
312static __inline int ieee754dp_ge(ieee754dp x, ieee754dp y) 294static inline int ieee754dp_ge(ieee754dp x, ieee754dp y)
313{ 295{
314 return ieee754dp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0); 296 return ieee754dp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0);
315} 297}
316 298
317 299
318/* like strtod 300/*
319*/ 301 * Like strtod
302 */
320ieee754dp ieee754dp_fstr(const char *s, char **endp); 303ieee754dp ieee754dp_fstr(const char *s, char **endp);
321char *ieee754dp_tstr(ieee754dp x, int prec, int fmt, int af); 304char *ieee754dp_tstr(ieee754dp x, int prec, int fmt, int af);
322 305
323 306
324/* the control status register 307/*
325*/ 308 * The control status register
326struct ieee754_csr { 309 */
327 unsigned pad:13; 310struct _ieee754_csr {
311#ifdef __BIG_ENDIAN
312 unsigned pad0:7;
328 unsigned nod:1; /* set 1 for no denormalised numbers */ 313 unsigned nod:1; /* set 1 for no denormalised numbers */
329 unsigned cx:5; /* exceptions this operation */ 314 unsigned c:1; /* condition */
315 unsigned pad1:5;
316 unsigned cx:6; /* exceptions this operation */
330 unsigned mx:5; /* exception enable mask */ 317 unsigned mx:5; /* exception enable mask */
331 unsigned sx:5; /* exceptions total */ 318 unsigned sx:5; /* exceptions total */
332 unsigned rm:2; /* current rounding mode */ 319 unsigned rm:2; /* current rounding mode */
320#endif
321#ifdef __LITTLE_ENDIAN
322 unsigned rm:2; /* current rounding mode */
323 unsigned sx:5; /* exceptions total */
324 unsigned mx:5; /* exception enable mask */
325 unsigned cx:6; /* exceptions this operation */
326 unsigned pad1:5;
327 unsigned c:1; /* condition */
328 unsigned nod:1; /* set 1 for no denormalised numbers */
329 unsigned pad0:7;
330#endif
333}; 331};
334extern struct ieee754_csr ieee754_csr; 332#define ieee754_csr (*(struct _ieee754_csr *)(&current->thread.fpu.soft.fcr31))
335 333
336static __inline unsigned ieee754_getrm(void) 334static inline unsigned ieee754_getrm(void)
337{ 335{
338 return (ieee754_csr.rm); 336 return (ieee754_csr.rm);
339} 337}
340static __inline unsigned ieee754_setrm(unsigned rm) 338static inline unsigned ieee754_setrm(unsigned rm)
341{ 339{
342 return (ieee754_csr.rm = rm); 340 return (ieee754_csr.rm = rm);
343} 341}
@@ -345,14 +343,14 @@ static __inline unsigned ieee754_setrm(unsigned rm)
345/* 343/*
346 * get current exceptions 344 * get current exceptions
347 */ 345 */
348static __inline unsigned ieee754_getcx(void) 346static inline unsigned ieee754_getcx(void)
349{ 347{
350 return (ieee754_csr.cx); 348 return (ieee754_csr.cx);
351} 349}
352 350
353/* test for current exception condition 351/* test for current exception condition
354 */ 352 */
355static __inline int ieee754_cxtest(unsigned n) 353static inline int ieee754_cxtest(unsigned n)
356{ 354{
357 return (ieee754_csr.cx & n); 355 return (ieee754_csr.cx & n);
358} 356}
@@ -360,21 +358,21 @@ static __inline int ieee754_cxtest(unsigned n)
360/* 358/*
361 * get sticky exceptions 359 * get sticky exceptions
362 */ 360 */
363static __inline unsigned ieee754_getsx(void) 361static inline unsigned ieee754_getsx(void)
364{ 362{
365 return (ieee754_csr.sx); 363 return (ieee754_csr.sx);
366} 364}
367 365
368/* clear sticky conditions 366/* clear sticky conditions
369*/ 367*/
370static __inline unsigned ieee754_clrsx(void) 368static inline unsigned ieee754_clrsx(void)
371{ 369{
372 return (ieee754_csr.sx = 0); 370 return (ieee754_csr.sx = 0);
373} 371}
374 372
375/* test for sticky exception condition 373/* test for sticky exception condition
376 */ 374 */
377static __inline int ieee754_sxtest(unsigned n) 375static inline int ieee754_sxtest(unsigned n)
378{ 376{
379 return (ieee754_csr.sx & n); 377 return (ieee754_csr.sx & n);
380} 378}
@@ -406,52 +404,34 @@ extern const struct ieee754sp_konst __ieee754sp_spcvals[];
406#define ieee754dp_spcvals ((const ieee754dp *)__ieee754dp_spcvals) 404#define ieee754dp_spcvals ((const ieee754dp *)__ieee754dp_spcvals)
407#define ieee754sp_spcvals ((const ieee754sp *)__ieee754sp_spcvals) 405#define ieee754sp_spcvals ((const ieee754sp *)__ieee754sp_spcvals)
408 406
409/* return infinity with given sign 407/*
410*/ 408 * Return infinity with given sign
411#define ieee754dp_inf(sn) \ 409 */
412 (ieee754dp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) 410#define ieee754dp_inf(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)])
413#define ieee754dp_zero(sn) \ 411#define ieee754dp_zero(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PZERO+(sn)])
414 (ieee754dp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) 412#define ieee754dp_one(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PONE+(sn)])
415#define ieee754dp_one(sn) \ 413#define ieee754dp_ten(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PTEN+(sn)])
416 (ieee754dp_spcvals[IEEE754_SPCVAL_PONE+(sn)]) 414#define ieee754dp_indef() (ieee754dp_spcvals[IEEE754_SPCVAL_INDEF])
417#define ieee754dp_ten(sn) \ 415#define ieee754dp_max(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMAX+(sn)])
418 (ieee754dp_spcvals[IEEE754_SPCVAL_PTEN+(sn)]) 416#define ieee754dp_min(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIN+(sn)])
419#define ieee754dp_indef() \ 417#define ieee754dp_mind(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIND+(sn)])
420 (ieee754dp_spcvals[IEEE754_SPCVAL_INDEF]) 418#define ieee754dp_1e31() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E31])
421#define ieee754dp_max(sn) \ 419#define ieee754dp_1e63() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E63])
422 (ieee754dp_spcvals[IEEE754_SPCVAL_PMAX+(sn)]) 420
423#define ieee754dp_min(sn) \ 421#define ieee754sp_inf(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)])
424 (ieee754dp_spcvals[IEEE754_SPCVAL_PMIN+(sn)]) 422#define ieee754sp_zero(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PZERO+(sn)])
425#define ieee754dp_mind(sn) \ 423#define ieee754sp_one(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PONE+(sn)])
426 (ieee754dp_spcvals[IEEE754_SPCVAL_PMIND+(sn)]) 424#define ieee754sp_ten(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PTEN+(sn)])
427#define ieee754dp_1e31() \ 425#define ieee754sp_indef() (ieee754sp_spcvals[IEEE754_SPCVAL_INDEF])
428 (ieee754dp_spcvals[IEEE754_SPCVAL_P1E31]) 426#define ieee754sp_max(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMAX+(sn)])
429#define ieee754dp_1e63() \ 427#define ieee754sp_min(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIN+(sn)])
430 (ieee754dp_spcvals[IEEE754_SPCVAL_P1E63]) 428#define ieee754sp_mind(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIND+(sn)])
431 429#define ieee754sp_1e31() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E31])
432#define ieee754sp_inf(sn) \ 430#define ieee754sp_1e63() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E63])
433 (ieee754sp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)]) 431
434#define ieee754sp_zero(sn) \ 432/*
435 (ieee754sp_spcvals[IEEE754_SPCVAL_PZERO+(sn)]) 433 * Indefinite integer value
436#define ieee754sp_one(sn) \ 434 */
437 (ieee754sp_spcvals[IEEE754_SPCVAL_PONE+(sn)])
438#define ieee754sp_ten(sn) \
439 (ieee754sp_spcvals[IEEE754_SPCVAL_PTEN+(sn)])
440#define ieee754sp_indef() \
441 (ieee754sp_spcvals[IEEE754_SPCVAL_INDEF])
442#define ieee754sp_max(sn) \
443 (ieee754sp_spcvals[IEEE754_SPCVAL_PMAX+(sn)])
444#define ieee754sp_min(sn) \
445 (ieee754sp_spcvals[IEEE754_SPCVAL_PMIN+(sn)])
446#define ieee754sp_mind(sn) \
447 (ieee754sp_spcvals[IEEE754_SPCVAL_PMIND+(sn)])
448#define ieee754sp_1e31() \
449 (ieee754sp_spcvals[IEEE754_SPCVAL_P1E31])
450#define ieee754sp_1e63() \
451 (ieee754sp_spcvals[IEEE754_SPCVAL_P1E63])
452
453/* indefinite integer value
454*/
455#define ieee754si_indef() INT_MAX 435#define ieee754si_indef() INT_MAX
456#ifdef LONG_LONG_MAX 436#ifdef LONG_LONG_MAX
457#define ieee754di_indef() LONG_LONG_MAX 437#define ieee754di_indef() LONG_LONG_MAX
@@ -487,3 +467,5 @@ extern void ieee754_xcpt(struct ieee754xctx *xcp);
487/* compat */ 467/* compat */
488#define ieee754dp_fix(x) ieee754dp_tint(x) 468#define ieee754dp_fix(x) ieee754dp_tint(x)
489#define ieee754sp_fix(x) ieee754sp_tint(x) 469#define ieee754sp_fix(x) ieee754sp_tint(x)
470
471#endif /* __ARCH_MIPS_MATH_EMU_IEEE754_H */