xref: /openbmc/linux/arch/mips/math-emu/ieee754.c (revision 3f7cac41)
11da177e4SLinus Torvalds /* ieee754 floating point arithmetic
21da177e4SLinus Torvalds  * single and double precision
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * BUGS
51da177e4SLinus Torvalds  * not much dp done
61da177e4SLinus Torvalds  * doesn't generate IEEE754_INEXACT
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds /*
101da177e4SLinus Torvalds  * MIPS floating point support
111da177e4SLinus Torvalds  * Copyright (C) 1994-2000 Algorithmics Ltd.
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  *  This program is free software; you can distribute it and/or modify it
141da177e4SLinus Torvalds  *  under the terms of the GNU General Public License (Version 2) as
151da177e4SLinus Torvalds  *  published by the Free Software Foundation.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  *  This program is distributed in the hope it will be useful, but WITHOUT
181da177e4SLinus Torvalds  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
191da177e4SLinus Torvalds  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
201da177e4SLinus Torvalds  *  for more details.
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  *  You should have received a copy of the GNU General Public License along
231da177e4SLinus Torvalds  *  with this program; if not, write to the Free Software Foundation, Inc.,
243f7cac41SRalf Baechle  *  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
251da177e4SLinus Torvalds  */
261da177e4SLinus Torvalds 
27cae55066SRalf Baechle #include <linux/compiler.h>
281da177e4SLinus Torvalds 
2949548b09SRalf Baechle #include "ieee754.h"
30efec3c4eSRalf Baechle #include "ieee754sp.h"
31efec3c4eSRalf Baechle #include "ieee754dp.h"
321da177e4SLinus Torvalds 
333f7cac41SRalf Baechle /*
343f7cac41SRalf Baechle  * Special constants
351da177e4SLinus Torvalds  */
361da177e4SLinus Torvalds 
3749548b09SRalf Baechle #define DPCNST(s, b, m)							\
3890efba36SRalf Baechle {									\
3990efba36SRalf Baechle 	.sign	= (s),							\
4049548b09SRalf Baechle 	.bexp	= (b) + DP_EBIAS,					\
4190efba36SRalf Baechle 	.mant	= (m)							\
4290efba36SRalf Baechle }
4390efba36SRalf Baechle 
4449548b09SRalf Baechle const union ieee754dp __ieee754dp_spcvals[] = {
4549548b09SRalf Baechle 	DPCNST(0, DP_EMIN - 1, 0x0000000000000ULL),	/* + zero   */
4649548b09SRalf Baechle 	DPCNST(1, DP_EMIN - 1, 0x0000000000000ULL),	/* - zero   */
4749548b09SRalf Baechle 	DPCNST(0, 0,	       0x0000000000000ULL),	/* + 1.0   */
4849548b09SRalf Baechle 	DPCNST(1, 0,	       0x0000000000000ULL),	/* - 1.0   */
4949548b09SRalf Baechle 	DPCNST(0, 3,           0x4000000000000ULL),	/* + 10.0   */
5049548b09SRalf Baechle 	DPCNST(1, 3,           0x4000000000000ULL),	/* - 10.0   */
5149548b09SRalf Baechle 	DPCNST(0, DP_EMAX + 1, 0x0000000000000ULL),	/* + infinity */
5249548b09SRalf Baechle 	DPCNST(1, DP_EMAX + 1, 0x0000000000000ULL),	/* - infinity */
5349548b09SRalf Baechle 	DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL),	/* + indef quiet Nan */
5449548b09SRalf Baechle 	DPCNST(0, DP_EMAX,     0xFFFFFFFFFFFFFULL),	/* + max */
5549548b09SRalf Baechle 	DPCNST(1, DP_EMAX,     0xFFFFFFFFFFFFFULL),	/* - max */
5649548b09SRalf Baechle 	DPCNST(0, DP_EMIN,     0x0000000000000ULL),	/* + min normal */
5749548b09SRalf Baechle 	DPCNST(1, DP_EMIN,     0x0000000000000ULL),	/* - min normal */
5849548b09SRalf Baechle 	DPCNST(0, DP_EMIN - 1, 0x0000000000001ULL),	/* + min denormal */
5949548b09SRalf Baechle 	DPCNST(1, DP_EMIN - 1, 0x0000000000001ULL),	/* - min denormal */
6049548b09SRalf Baechle 	DPCNST(0, 31,          0x0000000000000ULL),	/* + 1.0e31 */
6149548b09SRalf Baechle 	DPCNST(0, 63,          0x0000000000000ULL),	/* + 1.0e63 */
6249548b09SRalf Baechle };
6349548b09SRalf Baechle 
6449548b09SRalf Baechle #define SPCNST(s, b, m)							\
6549548b09SRalf Baechle {									\
6649548b09SRalf Baechle 	.sign	= (s),							\
6749548b09SRalf Baechle 	.bexp	= (b) + SP_EBIAS,					\
6849548b09SRalf Baechle 	.mant	= (m)							\
6949548b09SRalf Baechle }
7049548b09SRalf Baechle 
7149548b09SRalf Baechle const union ieee754sp __ieee754sp_spcvals[] = {
7249548b09SRalf Baechle 	SPCNST(0, SP_EMIN - 1, 0x000000),	/* + zero   */
7349548b09SRalf Baechle 	SPCNST(1, SP_EMIN - 1, 0x000000),	/* - zero   */
7449548b09SRalf Baechle 	SPCNST(0, 0,	       0x000000),	/* + 1.0   */
7549548b09SRalf Baechle 	SPCNST(1, 0,	       0x000000),	/* - 1.0   */
7649548b09SRalf Baechle 	SPCNST(0, 3,	       0x200000),	/* + 10.0   */
7749548b09SRalf Baechle 	SPCNST(1, 3,	       0x200000),	/* - 10.0   */
7849548b09SRalf Baechle 	SPCNST(0, SP_EMAX + 1, 0x000000),	/* + infinity */
7949548b09SRalf Baechle 	SPCNST(1, SP_EMAX + 1, 0x000000),	/* - infinity */
8049548b09SRalf Baechle 	SPCNST(0, SP_EMAX + 1, 0x3FFFFF),	/* + indef quiet Nan  */
8149548b09SRalf Baechle 	SPCNST(0, SP_EMAX,     0x7FFFFF),	/* + max normal */
8249548b09SRalf Baechle 	SPCNST(1, SP_EMAX,     0x7FFFFF),	/* - max normal */
8349548b09SRalf Baechle 	SPCNST(0, SP_EMIN,     0x000000),	/* + min normal */
8449548b09SRalf Baechle 	SPCNST(1, SP_EMIN,     0x000000),	/* - min normal */
8549548b09SRalf Baechle 	SPCNST(0, SP_EMIN - 1, 0x000001),	/* + min denormal */
8649548b09SRalf Baechle 	SPCNST(1, SP_EMIN - 1, 0x000001),	/* - min denormal */
8749548b09SRalf Baechle 	SPCNST(0, 31,	       0x000000),	/* + 1.0e31 */
8849548b09SRalf Baechle 	SPCNST(0, 63,	       0x000000),	/* + 1.0e63 */
891da177e4SLinus Torvalds };
90