Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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., |
Ralf Baechle | 3f7cac4 | 2014-04-26 01:49:14 +0200 | [diff] [blame] | 24 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
Ralf Baechle | cae5506 | 2014-04-16 00:47:59 +0200 | [diff] [blame] | 27 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 29 | #include "ieee754.h" |
Ralf Baechle | efec3c4 | 2005-10-23 13:46:25 +0100 | [diff] [blame] | 30 | #include "ieee754sp.h" |
| 31 | #include "ieee754dp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Ralf Baechle | 3f7cac4 | 2014-04-26 01:49:14 +0200 | [diff] [blame] | 33 | /* |
| 34 | * Special constants |
| 35 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Ralf Baechle | 91496ea | 2014-06-13 15:26:14 +0100 | [diff] [blame] | 37 | /* |
| 38 | * Older GCC requires the inner braces for initialization of union ieee754dp's |
| 39 | * anonymous struct member. Without an error will result. |
| 40 | */ |
Ralf Baechle | fb738f8 | 2014-06-13 15:36:45 +0100 | [diff] [blame] | 41 | #define xPCNST(s, b, m, ebias) \ |
Ralf Baechle | 90efba3 | 2014-04-25 03:19:57 +0200 | [diff] [blame] | 42 | { \ |
Ralf Baechle | 91496ea | 2014-06-13 15:26:14 +0100 | [diff] [blame] | 43 | { \ |
| 44 | .sign = (s), \ |
Ralf Baechle | fb738f8 | 2014-06-13 15:36:45 +0100 | [diff] [blame] | 45 | .bexp = (b) + ebias, \ |
Ralf Baechle | 91496ea | 2014-06-13 15:26:14 +0100 | [diff] [blame] | 46 | .mant = (m) \ |
| 47 | } \ |
Ralf Baechle | 90efba3 | 2014-04-25 03:19:57 +0200 | [diff] [blame] | 48 | } |
| 49 | |
Ralf Baechle | fb738f8 | 2014-06-13 15:36:45 +0100 | [diff] [blame] | 50 | #define DPCNST(s, b, m) \ |
| 51 | xPCNST(s, b, m, DP_EBIAS) |
| 52 | |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 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 */ |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 62 | DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL), /* + ind legacy qNaN */ |
| 63 | DPCNST(0, DP_EMAX + 1, 0x8000000000000ULL), /* + indef 2008 qNaN */ |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 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) \ |
Ralf Baechle | fb738f8 | 2014-06-13 15:36:45 +0100 | [diff] [blame] | 75 | xPCNST(s, b, m, SP_EBIAS) |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 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 */ |
Maciej W. Rozycki | 90d53a9 | 2015-11-13 00:47:28 +0000 | [diff] [blame] | 86 | SPCNST(0, SP_EMAX + 1, 0x3FFFFF), /* + indef legacy quiet NaN */ |
| 87 | SPCNST(0, SP_EMAX + 1, 0x400000), /* + indef 2008 quiet NaN */ |
Ralf Baechle | 49548b0 | 2014-04-25 15:48:40 +0200 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; |