blob: e16ae7b75dbb775c9af078994e785c257a454f39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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.,
Ralf Baechle3f7cac42014-04-26 01:49:14 +020024 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 */
26
Ralf Baechlecae55062014-04-16 00:47:59 +020027#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Ralf Baechle49548b02014-04-25 15:48:40 +020029#include "ieee754.h"
Ralf Baechleefec3c42005-10-23 13:46:25 +010030#include "ieee754sp.h"
31#include "ieee754dp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ralf Baechle3f7cac42014-04-26 01:49:14 +020033/*
34 * Special constants
35 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Ralf Baechle91496ea2014-06-13 15:26:14 +010037/*
38 * Older GCC requires the inner braces for initialization of union ieee754dp's
39 * anonymous struct member. Without an error will result.
40 */
Ralf Baechlefb738f82014-06-13 15:36:45 +010041#define xPCNST(s, b, m, ebias) \
Ralf Baechle90efba32014-04-25 03:19:57 +020042{ \
Ralf Baechle91496ea2014-06-13 15:26:14 +010043 { \
44 .sign = (s), \
Ralf Baechlefb738f82014-06-13 15:36:45 +010045 .bexp = (b) + ebias, \
Ralf Baechle91496ea2014-06-13 15:26:14 +010046 .mant = (m) \
47 } \
Ralf Baechle90efba32014-04-25 03:19:57 +020048}
49
Ralf Baechlefb738f82014-06-13 15:36:45 +010050#define DPCNST(s, b, m) \
51 xPCNST(s, b, m, DP_EBIAS)
52
Ralf Baechle49548b02014-04-25 15:48:40 +020053const 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 */
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000062 DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL), /* + ind legacy qNaN */
63 DPCNST(0, DP_EMAX + 1, 0x8000000000000ULL), /* + indef 2008 qNaN */
Ralf Baechle49548b02014-04-25 15:48:40 +020064 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) \
Ralf Baechlefb738f82014-06-13 15:36:45 +010075 xPCNST(s, b, m, SP_EBIAS)
Ralf Baechle49548b02014-04-25 15:48:40 +020076
77const 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 */
Maciej W. Rozycki90d53a92015-11-13 00:47:28 +000086 SPCNST(0, SP_EMAX + 1, 0x3FFFFF), /* + indef legacy quiet NaN */
87 SPCNST(0, SP_EMAX + 1, 0x400000), /* + indef 2008 quiet NaN */
Ralf Baechle49548b02014-04-25 15:48:40 +020088 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};