xref: /openbmc/linux/arch/mips/math-emu/ieee754.c (revision feac8c8b)
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  *  This program is free software; you can distribute it and/or modify it
14  *  under the terms of the GNU General Public License (Version 2) as
15  *  published by the Free Software Foundation.
16  *
17  *  This program is distributed in the hope it will be useful, but WITHOUT
18  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20  *  for more details.
21  *
22  *  You should have received a copy of the GNU General Public License along
23  *  with this program; if not, write to the Free Software Foundation, Inc.,
24  *  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
25  */
26 
27 #include <linux/compiler.h>
28 
29 #include "ieee754.h"
30 #include "ieee754sp.h"
31 #include "ieee754dp.h"
32 
33 /*
34  * Special constants
35  */
36 
37 /*
38  * Older GCC requires the inner braces for initialization of union ieee754dp's
39  * anonymous struct member.  Without an error will result.
40  */
41 #define xPCNST(s, b, m, ebias)						\
42 {									\
43 	{								\
44 		.sign	= (s),						\
45 		.bexp	= (b) + ebias,					\
46 		.mant	= (m)						\
47 	}								\
48 }
49 
50 #define DPCNST(s, b, m)							\
51 	xPCNST(s, b, m, DP_EBIAS)
52 
53 const union ieee754dp __ieee754dp_spcvals[] = {
54 	DPCNST(0, DP_EMIN - 1, 0x0000000000000ULL),	/* + zero   */
55 	DPCNST(1, DP_EMIN - 1, 0x0000000000000ULL),	/* - zero   */
56 	DPCNST(0, 0,	       0x0000000000000ULL),	/* + 1.0   */
57 	DPCNST(1, 0,	       0x0000000000000ULL),	/* - 1.0   */
58 	DPCNST(0, 3,           0x4000000000000ULL),	/* + 10.0   */
59 	DPCNST(1, 3,           0x4000000000000ULL),	/* - 10.0   */
60 	DPCNST(0, DP_EMAX + 1, 0x0000000000000ULL),	/* + infinity */
61 	DPCNST(1, DP_EMAX + 1, 0x0000000000000ULL),	/* - infinity */
62 	DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL),	/* + ind legacy qNaN */
63 	DPCNST(0, DP_EMAX + 1, 0x8000000000000ULL),	/* + indef 2008 qNaN */
64 	DPCNST(0, DP_EMAX,     0xFFFFFFFFFFFFFULL),	/* + max */
65 	DPCNST(1, DP_EMAX,     0xFFFFFFFFFFFFFULL),	/* - max */
66 	DPCNST(0, DP_EMIN,     0x0000000000000ULL),	/* + min normal */
67 	DPCNST(1, DP_EMIN,     0x0000000000000ULL),	/* - min normal */
68 	DPCNST(0, DP_EMIN - 1, 0x0000000000001ULL),	/* + min denormal */
69 	DPCNST(1, DP_EMIN - 1, 0x0000000000001ULL),	/* - min denormal */
70 	DPCNST(0, 31,          0x0000000000000ULL),	/* + 1.0e31 */
71 	DPCNST(0, 63,          0x0000000000000ULL),	/* + 1.0e63 */
72 };
73 
74 #define SPCNST(s, b, m)							\
75 	xPCNST(s, b, m, SP_EBIAS)
76 
77 const union ieee754sp __ieee754sp_spcvals[] = {
78 	SPCNST(0, SP_EMIN - 1, 0x000000),	/* + zero   */
79 	SPCNST(1, SP_EMIN - 1, 0x000000),	/* - zero   */
80 	SPCNST(0, 0,	       0x000000),	/* + 1.0   */
81 	SPCNST(1, 0,	       0x000000),	/* - 1.0   */
82 	SPCNST(0, 3,	       0x200000),	/* + 10.0   */
83 	SPCNST(1, 3,	       0x200000),	/* - 10.0   */
84 	SPCNST(0, SP_EMAX + 1, 0x000000),	/* + infinity */
85 	SPCNST(1, SP_EMAX + 1, 0x000000),	/* - infinity */
86 	SPCNST(0, SP_EMAX + 1, 0x3FFFFF),	/* + indef legacy quiet NaN */
87 	SPCNST(0, SP_EMAX + 1, 0x400000),	/* + indef 2008 quiet NaN */
88 	SPCNST(0, SP_EMAX,     0x7FFFFF),	/* + max normal */
89 	SPCNST(1, SP_EMAX,     0x7FFFFF),	/* - max normal */
90 	SPCNST(0, SP_EMIN,     0x000000),	/* + min normal */
91 	SPCNST(1, SP_EMIN,     0x000000),	/* - min normal */
92 	SPCNST(0, SP_EMIN - 1, 0x000001),	/* + min denormal */
93 	SPCNST(1, SP_EMIN - 1, 0x000001),	/* - min denormal */
94 	SPCNST(0, 31,	       0x000000),	/* + 1.0e31 */
95 	SPCNST(0, 63,	       0x000000),	/* + 1.0e63 */
96 };
97