f3b5fa0adbbbd86cdab8204554ab89be5504c6bf
[pandora-kernel.git] / arch / mips / math-emu / ieee754.c
1 /* ieee754 floating point arithmetic
2  * single and double precision
3  *
4  * BUGS
5  * not much dp done
6  * doesn't generate IEEE754_INEXACT
7  *
8  */
9 /*
10  * MIPS floating point support
11  * Copyright (C) 1994-2000 Algorithmics Ltd.
12  *
13  * ########################################################################
14  *
15  *  This program is free software; you can distribute it and/or modify it
16  *  under the terms of the GNU General Public License (Version 2) as
17  *  published by the Free Software Foundation.
18  *
19  *  This program is distributed in the hope it will be useful, but WITHOUT
20  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22  *  for more details.
23  *
24  *  You should have received a copy of the GNU General Public License along
25  *  with this program; if not, write to the Free Software Foundation, Inc.,
26  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
27  *
28  * ########################################################################
29  */
30
31 #include <stdarg.h>
32 #include <linux/compiler.h>
33
34 #include "ieee754int.h"
35 #include "ieee754sp.h"
36 #include "ieee754dp.h"
37
38 /* special constants
39 */
40
41 #ifdef __MIPSEB__
42 #define SPSTR(s, b, m) {s, b, m}
43 #define DPSTR(s, b, mh, ml) {s, b, mh, ml}
44 #elif defined(__MIPSEL__)
45 #define SPSTR(s, b, m) {m, b, s}
46 #define DPSTR(s, b, mh, ml) {ml, mh, b, s}
47 #else /* !defined (__MIPSEB__) && !defined (__MIPSEL__) */
48 #error "MIPS but neither __MIPSEB__ nor __MIPSEL__?"
49 #endif
50
51 const struct ieee754dp_const __ieee754dp_spcvals[] = {
52         DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* + zero   */
53         DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* - zero   */
54         DPSTR(0, DP_EBIAS, 0, 0),       /* + 1.0   */
55         DPSTR(1, DP_EBIAS, 0, 0),       /* - 1.0   */
56         DPSTR(0, 3 + DP_EBIAS, 0x40000, 0),     /* + 10.0   */
57         DPSTR(1, 3 + DP_EBIAS, 0x40000, 0),     /* - 10.0   */
58         DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* + infinity */
59         DPSTR(1, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* - infinity */
60         DPSTR(0, DP_EMAX+1+DP_EBIAS, 0x7FFFF, 0xFFFFFFFF), /* + indef quiet Nan */
61         DPSTR(0, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),      /* + max */
62         DPSTR(1, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),      /* - max */
63         DPSTR(0, DP_EMIN + DP_EBIAS, 0, 0),     /* + min normal */
64         DPSTR(1, DP_EMIN + DP_EBIAS, 0, 0),     /* - min normal */
65         DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* + min denormal */
66         DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* - min denormal */
67         DPSTR(0, 31 + DP_EBIAS, 0, 0),  /* + 1.0e31 */
68         DPSTR(0, 63 + DP_EBIAS, 0, 0),  /* + 1.0e63 */
69 };
70
71 const struct ieee754sp_const __ieee754sp_spcvals[] = {
72         SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 0),    /* + zero   */
73         SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 0),    /* - zero   */
74         SPSTR(0, SP_EBIAS, 0),  /* + 1.0   */
75         SPSTR(1, SP_EBIAS, 0),  /* - 1.0   */
76         SPSTR(0, 3 + SP_EBIAS, 0x200000),       /* + 10.0   */
77         SPSTR(1, 3 + SP_EBIAS, 0x200000),       /* - 10.0   */
78         SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0),    /* + infinity */
79         SPSTR(1, SP_EMAX + 1 + SP_EBIAS, 0),    /* - infinity */
80         SPSTR(0, SP_EMAX+1+SP_EBIAS, 0x3FFFFF),     /* + indef quiet Nan  */
81         SPSTR(0, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* + max normal */
82         SPSTR(1, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* - max normal */
83         SPSTR(0, SP_EMIN + SP_EBIAS, 0),        /* + min normal */
84         SPSTR(1, SP_EMIN + SP_EBIAS, 0),        /* - min normal */
85         SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 1),    /* + min denormal */
86         SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 1),    /* - min denormal */
87         SPSTR(0, 31 + SP_EBIAS, 0),     /* + 1.0e31 */
88         SPSTR(0, 63 + SP_EBIAS, 0),     /* + 1.0e63 */
89 };
90
91
92 int __cold ieee754si_xcpt(int r, const char *op, ...)
93 {
94         struct ieee754xctx ax;
95
96         if (!ieee754_tstx())
97                 return r;
98         ax.op = op;
99         ax.rt = IEEE754_RT_SI;
100         ax.rv.si = r;
101         va_start(ax.ap, op);
102         ieee754_xcpt(&ax);
103         va_end(ax.ap);
104         return ax.rv.si;
105 }
106
107 s64 __cold ieee754di_xcpt(s64 r, const char *op, ...)
108 {
109         struct ieee754xctx ax;
110
111         if (!ieee754_tstx())
112                 return r;
113         ax.op = op;
114         ax.rt = IEEE754_RT_DI;
115         ax.rv.di = r;
116         va_start(ax.ap, op);
117         ieee754_xcpt(&ax);
118         va_end(ax.ap);
119         return ax.rv.di;
120 }