162306a36Sopenharmony_ci/* Software floating-point emulation.
262306a36Sopenharmony_ci   Definitions for IEEE Double Precision
362306a36Sopenharmony_ci   Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
462306a36Sopenharmony_ci   This file is part of the GNU C Library.
562306a36Sopenharmony_ci   Contributed by Richard Henderson (rth@cygnus.com),
662306a36Sopenharmony_ci		  Jakub Jelinek (jj@ultra.linux.cz),
762306a36Sopenharmony_ci		  David S. Miller (davem@redhat.com) and
862306a36Sopenharmony_ci		  Peter Maydell (pmaydell@chiark.greenend.org.uk).
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci   The GNU C Library is free software; you can redistribute it and/or
1162306a36Sopenharmony_ci   modify it under the terms of the GNU Library General Public License as
1262306a36Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
1362306a36Sopenharmony_ci   License, or (at your option) any later version.
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci   The GNU C Library is distributed in the hope that it will be useful,
1662306a36Sopenharmony_ci   but WITHOUT ANY WARRANTY; without even the implied warranty of
1762306a36Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1862306a36Sopenharmony_ci   Library General Public License for more details.
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci   You should have received a copy of the GNU Library General Public
2162306a36Sopenharmony_ci   License along with the GNU C Library; see the file COPYING.LIB.  If
2262306a36Sopenharmony_ci   not, write to the Free Software Foundation, Inc.,
2362306a36Sopenharmony_ci   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#ifndef    __MATH_EMU_DOUBLE_H__
2662306a36Sopenharmony_ci#define    __MATH_EMU_DOUBLE_H__
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#if _FP_W_TYPE_SIZE < 32
2962306a36Sopenharmony_ci#error "Here's a nickel kid.  Go buy yourself a real computer."
3062306a36Sopenharmony_ci#endif
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#if _FP_W_TYPE_SIZE < 64
3362306a36Sopenharmony_ci#define _FP_FRACTBITS_D		(2 * _FP_W_TYPE_SIZE)
3462306a36Sopenharmony_ci#else
3562306a36Sopenharmony_ci#define _FP_FRACTBITS_D		_FP_W_TYPE_SIZE
3662306a36Sopenharmony_ci#endif
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define _FP_FRACBITS_D		53
3962306a36Sopenharmony_ci#define _FP_FRACXBITS_D		(_FP_FRACTBITS_D - _FP_FRACBITS_D)
4062306a36Sopenharmony_ci#define _FP_WFRACBITS_D		(_FP_WORKBITS + _FP_FRACBITS_D)
4162306a36Sopenharmony_ci#define _FP_WFRACXBITS_D	(_FP_FRACTBITS_D - _FP_WFRACBITS_D)
4262306a36Sopenharmony_ci#define _FP_EXPBITS_D		11
4362306a36Sopenharmony_ci#define _FP_EXPBIAS_D		1023
4462306a36Sopenharmony_ci#define _FP_EXPMAX_D		2047
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define _FP_QNANBIT_D		\
4762306a36Sopenharmony_ci	((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2) % _FP_W_TYPE_SIZE)
4862306a36Sopenharmony_ci#define _FP_IMPLBIT_D		\
4962306a36Sopenharmony_ci	((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1) % _FP_W_TYPE_SIZE)
5062306a36Sopenharmony_ci#define _FP_OVERFLOW_D		\
5162306a36Sopenharmony_ci	((_FP_W_TYPE)1 << _FP_WFRACBITS_D % _FP_W_TYPE_SIZE)
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#if _FP_W_TYPE_SIZE < 64
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciunion _FP_UNION_D
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci  double flt;
5862306a36Sopenharmony_ci  struct {
5962306a36Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
6062306a36Sopenharmony_ci    unsigned sign  : 1;
6162306a36Sopenharmony_ci    unsigned exp   : _FP_EXPBITS_D;
6262306a36Sopenharmony_ci    unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
6362306a36Sopenharmony_ci    unsigned frac0 : _FP_W_TYPE_SIZE;
6462306a36Sopenharmony_ci#else
6562306a36Sopenharmony_ci    unsigned frac0 : _FP_W_TYPE_SIZE;
6662306a36Sopenharmony_ci    unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
6762306a36Sopenharmony_ci    unsigned exp   : _FP_EXPBITS_D;
6862306a36Sopenharmony_ci    unsigned sign  : 1;
6962306a36Sopenharmony_ci#endif
7062306a36Sopenharmony_ci  } bits __attribute__((packed));
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define FP_DECL_D(X)		_FP_DECL(2,X)
7462306a36Sopenharmony_ci#define FP_UNPACK_RAW_D(X,val)	_FP_UNPACK_RAW_2(D,X,val)
7562306a36Sopenharmony_ci#define FP_UNPACK_RAW_DP(X,val)	_FP_UNPACK_RAW_2_P(D,X,val)
7662306a36Sopenharmony_ci#define FP_PACK_RAW_D(val,X)	_FP_PACK_RAW_2(D,val,X)
7762306a36Sopenharmony_ci#define FP_PACK_RAW_DP(val,X)		\
7862306a36Sopenharmony_ci  do {					\
7962306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
8062306a36Sopenharmony_ci      _FP_PACK_RAW_2_P(D,val,X);	\
8162306a36Sopenharmony_ci  } while (0)
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define FP_UNPACK_D(X,val)		\
8462306a36Sopenharmony_ci  do {					\
8562306a36Sopenharmony_ci    _FP_UNPACK_RAW_2(D,X,val);		\
8662306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(D,2,X);	\
8762306a36Sopenharmony_ci  } while (0)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define FP_UNPACK_DP(X,val)		\
9062306a36Sopenharmony_ci  do {					\
9162306a36Sopenharmony_ci    _FP_UNPACK_RAW_2_P(D,X,val);	\
9262306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(D,2,X);	\
9362306a36Sopenharmony_ci  } while (0)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define FP_PACK_D(val,X)		\
9662306a36Sopenharmony_ci  do {					\
9762306a36Sopenharmony_ci    _FP_PACK_CANONICAL(D,2,X);		\
9862306a36Sopenharmony_ci    _FP_PACK_RAW_2(D,val,X);		\
9962306a36Sopenharmony_ci  } while (0)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define FP_PACK_DP(val,X)		\
10262306a36Sopenharmony_ci  do {					\
10362306a36Sopenharmony_ci    _FP_PACK_CANONICAL(D,2,X);		\
10462306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
10562306a36Sopenharmony_ci      _FP_PACK_RAW_2_P(D,val,X);	\
10662306a36Sopenharmony_ci  } while (0)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#define FP_ISSIGNAN_D(X)		_FP_ISSIGNAN(D,2,X)
10962306a36Sopenharmony_ci#define FP_NEG_D(R,X)			_FP_NEG(D,2,R,X)
11062306a36Sopenharmony_ci#define FP_ADD_D(R,X,Y)			_FP_ADD(D,2,R,X,Y)
11162306a36Sopenharmony_ci#define FP_SUB_D(R,X,Y)			_FP_SUB(D,2,R,X,Y)
11262306a36Sopenharmony_ci#define FP_MUL_D(R,X,Y)			_FP_MUL(D,2,R,X,Y)
11362306a36Sopenharmony_ci#define FP_DIV_D(R,X,Y)			_FP_DIV(D,2,R,X,Y)
11462306a36Sopenharmony_ci#define FP_SQRT_D(R,X)			_FP_SQRT(D,2,R,X)
11562306a36Sopenharmony_ci#define _FP_SQRT_MEAT_D(R,S,T,X,Q)	_FP_SQRT_MEAT_2(R,S,T,X,Q)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#define FP_CMP_D(r,X,Y,un)	_FP_CMP(D,2,r,X,Y,un)
11862306a36Sopenharmony_ci#define FP_CMP_EQ_D(r,X,Y)	_FP_CMP_EQ(D,2,r,X,Y)
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define FP_TO_INT_D(r,X,rsz,rsg)	_FP_TO_INT(D,2,r,X,rsz,rsg)
12162306a36Sopenharmony_ci#define FP_TO_INT_ROUND_D(r,X,rsz,rsg)	_FP_TO_INT_ROUND(D,2,r,X,rsz,rsg)
12262306a36Sopenharmony_ci#define FP_FROM_INT_D(X,r,rs,rt)	_FP_FROM_INT(D,2,X,r,rs,rt)
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define _FP_FRAC_HIGH_D(X)	_FP_FRAC_HIGH_2(X)
12562306a36Sopenharmony_ci#define _FP_FRAC_HIGH_RAW_D(X)	_FP_FRAC_HIGH_2(X)
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci#else
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciunion _FP_UNION_D
13062306a36Sopenharmony_ci{
13162306a36Sopenharmony_ci  double flt;
13262306a36Sopenharmony_ci  struct {
13362306a36Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
13462306a36Sopenharmony_ci    unsigned sign : 1;
13562306a36Sopenharmony_ci    unsigned exp  : _FP_EXPBITS_D;
13662306a36Sopenharmony_ci    unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
13762306a36Sopenharmony_ci#else
13862306a36Sopenharmony_ci    unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
13962306a36Sopenharmony_ci    unsigned exp  : _FP_EXPBITS_D;
14062306a36Sopenharmony_ci    unsigned sign : 1;
14162306a36Sopenharmony_ci#endif
14262306a36Sopenharmony_ci  } bits __attribute__((packed));
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#define FP_DECL_D(X)		_FP_DECL(1,X)
14662306a36Sopenharmony_ci#define FP_UNPACK_RAW_D(X,val)	_FP_UNPACK_RAW_1(D,X,val)
14762306a36Sopenharmony_ci#define FP_UNPACK_RAW_DP(X,val)	_FP_UNPACK_RAW_1_P(D,X,val)
14862306a36Sopenharmony_ci#define FP_PACK_RAW_D(val,X)	_FP_PACK_RAW_1(D,val,X)
14962306a36Sopenharmony_ci#define FP_PACK_RAW_DP(val,X)		\
15062306a36Sopenharmony_ci  do {					\
15162306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
15262306a36Sopenharmony_ci      _FP_PACK_RAW_1_P(D,val,X);	\
15362306a36Sopenharmony_ci  } while (0)
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci#define FP_UNPACK_D(X,val)		\
15662306a36Sopenharmony_ci  do {					\
15762306a36Sopenharmony_ci    _FP_UNPACK_RAW_1(D,X,val);		\
15862306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(D,1,X);	\
15962306a36Sopenharmony_ci  } while (0)
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#define FP_UNPACK_DP(X,val)		\
16262306a36Sopenharmony_ci  do {					\
16362306a36Sopenharmony_ci    _FP_UNPACK_RAW_1_P(D,X,val);	\
16462306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(D,1,X);	\
16562306a36Sopenharmony_ci  } while (0)
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define FP_PACK_D(val,X)		\
16862306a36Sopenharmony_ci  do {					\
16962306a36Sopenharmony_ci    _FP_PACK_CANONICAL(D,1,X);		\
17062306a36Sopenharmony_ci    _FP_PACK_RAW_1(D,val,X);		\
17162306a36Sopenharmony_ci  } while (0)
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define FP_PACK_DP(val,X)		\
17462306a36Sopenharmony_ci  do {					\
17562306a36Sopenharmony_ci    _FP_PACK_CANONICAL(D,1,X);		\
17662306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
17762306a36Sopenharmony_ci      _FP_PACK_RAW_1_P(D,val,X);	\
17862306a36Sopenharmony_ci  } while (0)
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci#define FP_ISSIGNAN_D(X)		_FP_ISSIGNAN(D,1,X)
18162306a36Sopenharmony_ci#define FP_NEG_D(R,X)			_FP_NEG(D,1,R,X)
18262306a36Sopenharmony_ci#define FP_ADD_D(R,X,Y)			_FP_ADD(D,1,R,X,Y)
18362306a36Sopenharmony_ci#define FP_SUB_D(R,X,Y)			_FP_SUB(D,1,R,X,Y)
18462306a36Sopenharmony_ci#define FP_MUL_D(R,X,Y)			_FP_MUL(D,1,R,X,Y)
18562306a36Sopenharmony_ci#define FP_DIV_D(R,X,Y)			_FP_DIV(D,1,R,X,Y)
18662306a36Sopenharmony_ci#define FP_SQRT_D(R,X)			_FP_SQRT(D,1,R,X)
18762306a36Sopenharmony_ci#define _FP_SQRT_MEAT_D(R,S,T,X,Q)	_FP_SQRT_MEAT_1(R,S,T,X,Q)
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* The implementation of _FP_MUL_D and _FP_DIV_D should be chosen by
19062306a36Sopenharmony_ci   the target machine.  */
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#define FP_CMP_D(r,X,Y,un)	_FP_CMP(D,1,r,X,Y,un)
19362306a36Sopenharmony_ci#define FP_CMP_EQ_D(r,X,Y)	_FP_CMP_EQ(D,1,r,X,Y)
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci#define FP_TO_INT_D(r,X,rsz,rsg)	_FP_TO_INT(D,1,r,X,rsz,rsg)
19662306a36Sopenharmony_ci#define FP_TO_INT_ROUND_D(r,X,rsz,rsg)	_FP_TO_INT_ROUND(D,1,r,X,rsz,rsg)
19762306a36Sopenharmony_ci#define FP_FROM_INT_D(X,r,rs,rt)	_FP_FROM_INT(D,1,X,r,rs,rt)
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#define _FP_FRAC_HIGH_D(X)	_FP_FRAC_HIGH_1(X)
20062306a36Sopenharmony_ci#define _FP_FRAC_HIGH_RAW_D(X)	_FP_FRAC_HIGH_1(X)
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci#endif /* W_TYPE_SIZE < 64 */
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#endif /* __MATH_EMU_DOUBLE_H__ */
206