Linux Audio

Check our new training course

Loading...
v3.1
  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 * ########################################################################
 14 *
 15 *  This program is free software; you can distribute it and/or modify it
 16 *  under the terms of the GNU General Public License (Version 2) as
 17 *  published by the Free Software Foundation.
 18 *
 19 *  This program is distributed in the hope it will be useful, but WITHOUT
 20 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 21 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 22 *  for more details.
 23 *
 24 *  You should have received a copy of the GNU General Public License along
 25 *  with this program; if not, write to the Free Software Foundation, Inc.,
 26 *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 27 *
 28 * ########################################################################
 29 */
 30
 
 31
 32#include "ieee754int.h"
 33#include "ieee754sp.h"
 34#include "ieee754dp.h"
 35
 36#define DP_EBIAS	1023
 37#define DP_EMIN		(-1022)
 38#define DP_EMAX		1023
 39
 40#define SP_EBIAS	127
 41#define SP_EMIN		(-126)
 42#define SP_EMAX		127
 43
 44/* special constants
 45*/
 46
 47
 48#if (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) || defined(__MIPSEL__)
 49#define SPSTR(s, b, m) {m, b, s}
 50#define DPSTR(s, b, mh, ml) {ml, mh, b, s}
 51#endif
 52
 53#ifdef __MIPSEB__
 54#define SPSTR(s, b, m) {s, b, m}
 55#define DPSTR(s, b, mh, ml) {s, b, mh, ml}
 56#endif
 57
 58const struct ieee754dp_konst __ieee754dp_spcvals[] = {
 59	DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 0),	/* + zero   */
 60	DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 0),	/* - zero   */
 61	DPSTR(0, DP_EBIAS, 0, 0),	/* + 1.0   */
 62	DPSTR(1, DP_EBIAS, 0, 0),	/* - 1.0   */
 63	DPSTR(0, 3 + DP_EBIAS, 0x40000, 0),	/* + 10.0   */
 64	DPSTR(1, 3 + DP_EBIAS, 0x40000, 0),	/* - 10.0   */
 65	DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0, 0),	/* + infinity */
 66	DPSTR(1, DP_EMAX + 1 + DP_EBIAS, 0, 0),	/* - infinity */
 67	DPSTR(0, DP_EMAX+1+DP_EBIAS, 0x7FFFF, 0xFFFFFFFF), /* + indef quiet Nan */
 68	DPSTR(0, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),	/* + max */
 69	DPSTR(1, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),	/* - max */
 70	DPSTR(0, DP_EMIN + DP_EBIAS, 0, 0),	/* + min normal */
 71	DPSTR(1, DP_EMIN + DP_EBIAS, 0, 0),	/* - min normal */
 72	DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 1),	/* + min denormal */
 73	DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 1),	/* - min denormal */
 74	DPSTR(0, 31 + DP_EBIAS, 0, 0),	/* + 1.0e31 */
 75	DPSTR(0, 63 + DP_EBIAS, 0, 0),	/* + 1.0e63 */
 76};
 77
 78const struct ieee754sp_konst __ieee754sp_spcvals[] = {
 79	SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 0),	/* + zero   */
 80	SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 0),	/* - zero   */
 81	SPSTR(0, SP_EBIAS, 0),	/* + 1.0   */
 82	SPSTR(1, SP_EBIAS, 0),	/* - 1.0   */
 83	SPSTR(0, 3 + SP_EBIAS, 0x200000),	/* + 10.0   */
 84	SPSTR(1, 3 + SP_EBIAS, 0x200000),	/* - 10.0   */
 85	SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0),	/* + infinity */
 86	SPSTR(1, SP_EMAX + 1 + SP_EBIAS, 0),	/* - infinity */
 87	SPSTR(0, SP_EMAX+1+SP_EBIAS, 0x3FFFFF),     /* + indef quiet Nan  */
 88	SPSTR(0, SP_EMAX + SP_EBIAS, 0x7FFFFF),	/* + max normal */
 89	SPSTR(1, SP_EMAX + SP_EBIAS, 0x7FFFFF),	/* - max normal */
 90	SPSTR(0, SP_EMIN + SP_EBIAS, 0),	/* + min normal */
 91	SPSTR(1, SP_EMIN + SP_EBIAS, 0),	/* - min normal */
 92	SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 1),	/* + min denormal */
 93	SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 1),	/* - min denormal */
 94	SPSTR(0, 31 + SP_EBIAS, 0),	/* + 1.0e31 */
 95	SPSTR(0, 63 + SP_EBIAS, 0),	/* + 1.0e63 */
 96};
 97
 
 
 98
 99int ieee754si_xcpt(int r, const char *op, ...)
100{
101	struct ieee754xctx ax;
102
103	if (!TSTX())
104		return r;
105	ax.op = op;
106	ax.rt = IEEE754_RT_SI;
107	ax.rv.si = r;
108	va_start(ax.ap, op);
109	ieee754_xcpt(&ax);
110	va_end(ax.ap);
111	return ax.rv.si;
112}
 
 
 
 
 
 
113
114s64 ieee754di_xcpt(s64 r, const char *op, ...)
115{
116	struct ieee754xctx ax;
117
118	if (!TSTX())
119		return r;
120	ax.op = op;
121	ax.rt = IEEE754_RT_DI;
122	ax.rv.di = r;
123	va_start(ax.ap, op);
124	ieee754_xcpt(&ax);
125	va_end(ax.ap);
126	return ax.rv.di;
127}
 
 
 
 
 
 
 
 
 
v4.17
 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
53const 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
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 */
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};