blob: 9ba023004eb6ff7f03a796a3acae8b609e3faea6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IEEE754 floating point
3 * double precision internal header file
4 */
5/*
6 * MIPS floating point support
7 * Copyright (C) 1994-2000 Algorithmics Ltd.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Baechle3f7cac42014-04-26 01:49:14 +020020 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
Ralf Baechlecae55062014-04-16 00:47:59 +020023#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "ieee754int.h"
26
27#define assert(expr) ((void)0)
28
Ralf Baechleb3a7ad22014-04-22 16:33:07 +020029#define DP_EBIAS 1023
30#define DP_EMIN (-1022)
31#define DP_EMAX 1023
32#define DP_FBITS 52
33#define DP_MBITS 52
34
35#define DP_MBIT(x) ((u64)1 << (x))
36#define DP_HIDDEN_BIT DP_MBIT(DP_FBITS)
37#define DP_SIGN_BIT DP_MBIT(63)
38
Ralf Baechle49548b02014-04-25 15:48:40 +020039#define DPSIGN(dp) (dp.sign)
40#define DPBEXP(dp) (dp.bexp)
41#define DPMANT(dp) (dp.mant)
Ralf Baechleb3a7ad22014-04-22 16:33:07 +020042
Ralf Baechle3a33db22014-04-22 16:52:01 +020043static inline int ieee754dp_finite(union ieee754dp x)
44{
45 return DPBEXP(x) != DP_EMAX + 1 + DP_EBIAS;
46}
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* 3bit extended double precision sticky right shift */
49#define XDPSRS(v,rs) \
Ralf Baechlead8fb552014-04-22 15:51:55 +020050 ((rs > (DP_FBITS+3))?1:((v) >> (rs)) | ((v) << (64-(rs)) != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#define XDPSRSX1() \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020053 (xe++, (xm = (xm >> 1) | (xm & 1)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define XDPSRS1(v) \
Ralf Baechle47fa0c02014-04-16 11:00:12 +020056 (((v) >> 1) | ((v) & 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/* convert denormal to normalized with extended exponent */
59#define DPDNORMx(m,e) \
Ralf Baechlead8fb552014-04-22 15:51:55 +020060 while ((m >> DP_FBITS) == 0) { m <<= 1; e--; }
Ralf Baechle21a151d2007-10-11 23:46:15 +010061#define DPDNORMX DPDNORMx(xm, xe)
62#define DPDNORMY DPDNORMx(ym, ye)
Paul Burtone2d11e12016-04-21 14:04:51 +010063#define DPDNORMZ DPDNORMx(zm, ze)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ralf Baechle2209bcb2014-04-16 01:31:11 +020065static inline union ieee754dp builddp(int s, int bx, u64 m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Ralf Baechle2209bcb2014-04-16 01:31:11 +020067 union ieee754dp r;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 assert((s) == 0 || (s) == 1);
70 assert((bx) >= DP_EMIN - 1 + DP_EBIAS
71 && (bx) <= DP_EMAX + 1 + DP_EBIAS);
Ralf Baechlead8fb552014-04-22 15:51:55 +020072 assert(((m) >> DP_FBITS) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Ralf Baechle49548b02014-04-25 15:48:40 +020074 r.sign = s;
75 r.bexp = bx;
76 r.mant = m;
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return r;
79}
80
Ralf Baechle90efba32014-04-25 03:19:57 +020081extern union ieee754dp __cold ieee754dp_nanxcpt(union ieee754dp);
Ralf Baechle2209bcb2014-04-16 01:31:11 +020082extern union ieee754dp ieee754dp_format(int, int, u64);