162306a36Sopenharmony_ci/* Software floating-point emulation.
262306a36Sopenharmony_ci   Definitions for IEEE Quad 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_QUAD_H__
2662306a36Sopenharmony_ci#define  __MATH_EMU_QUAD_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_Q         (4*_FP_W_TYPE_SIZE)
3462306a36Sopenharmony_ci#else
3562306a36Sopenharmony_ci#define _FP_FRACTBITS_Q		(2*_FP_W_TYPE_SIZE)
3662306a36Sopenharmony_ci#endif
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define _FP_FRACBITS_Q		113
3962306a36Sopenharmony_ci#define _FP_FRACXBITS_Q		(_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
4062306a36Sopenharmony_ci#define _FP_WFRACBITS_Q		(_FP_WORKBITS + _FP_FRACBITS_Q)
4162306a36Sopenharmony_ci#define _FP_WFRACXBITS_Q	(_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
4262306a36Sopenharmony_ci#define _FP_EXPBITS_Q		15
4362306a36Sopenharmony_ci#define _FP_EXPBIAS_Q		16383
4462306a36Sopenharmony_ci#define _FP_EXPMAX_Q		32767
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define _FP_QNANBIT_Q		\
4762306a36Sopenharmony_ci	((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
4862306a36Sopenharmony_ci#define _FP_IMPLBIT_Q		\
4962306a36Sopenharmony_ci	((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
5062306a36Sopenharmony_ci#define _FP_OVERFLOW_Q		\
5162306a36Sopenharmony_ci	((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#if _FP_W_TYPE_SIZE < 64
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciunion _FP_UNION_Q
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci   long double flt;
5862306a36Sopenharmony_ci   struct
5962306a36Sopenharmony_ci   {
6062306a36Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
6162306a36Sopenharmony_ci      unsigned sign : 1;
6262306a36Sopenharmony_ci      unsigned exp : _FP_EXPBITS_Q;
6362306a36Sopenharmony_ci      unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
6462306a36Sopenharmony_ci      unsigned long frac2 : _FP_W_TYPE_SIZE;
6562306a36Sopenharmony_ci      unsigned long frac1 : _FP_W_TYPE_SIZE;
6662306a36Sopenharmony_ci      unsigned long frac0 : _FP_W_TYPE_SIZE;
6762306a36Sopenharmony_ci#else
6862306a36Sopenharmony_ci      unsigned long frac0 : _FP_W_TYPE_SIZE;
6962306a36Sopenharmony_ci      unsigned long frac1 : _FP_W_TYPE_SIZE;
7062306a36Sopenharmony_ci      unsigned long frac2 : _FP_W_TYPE_SIZE;
7162306a36Sopenharmony_ci      unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
7262306a36Sopenharmony_ci      unsigned exp : _FP_EXPBITS_Q;
7362306a36Sopenharmony_ci      unsigned sign : 1;
7462306a36Sopenharmony_ci#endif /* not bigendian */
7562306a36Sopenharmony_ci   } bits __attribute__((packed));
7662306a36Sopenharmony_ci};
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#define FP_DECL_Q(X)		_FP_DECL(4,X)
8062306a36Sopenharmony_ci#define FP_UNPACK_RAW_Q(X,val)	_FP_UNPACK_RAW_4(Q,X,val)
8162306a36Sopenharmony_ci#define FP_UNPACK_RAW_QP(X,val)	_FP_UNPACK_RAW_4_P(Q,X,val)
8262306a36Sopenharmony_ci#define FP_PACK_RAW_Q(val,X)	_FP_PACK_RAW_4(Q,val,X)
8362306a36Sopenharmony_ci#define FP_PACK_RAW_QP(val,X)		\
8462306a36Sopenharmony_ci  do {					\
8562306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
8662306a36Sopenharmony_ci      _FP_PACK_RAW_4_P(Q,val,X);	\
8762306a36Sopenharmony_ci  } while (0)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define FP_UNPACK_Q(X,val)		\
9062306a36Sopenharmony_ci  do {					\
9162306a36Sopenharmony_ci    _FP_UNPACK_RAW_4(Q,X,val);		\
9262306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(Q,4,X);	\
9362306a36Sopenharmony_ci  } while (0)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define FP_UNPACK_QP(X,val)		\
9662306a36Sopenharmony_ci  do {					\
9762306a36Sopenharmony_ci    _FP_UNPACK_RAW_4_P(Q,X,val);	\
9862306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(Q,4,X);	\
9962306a36Sopenharmony_ci  } while (0)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define FP_PACK_Q(val,X)		\
10262306a36Sopenharmony_ci  do {					\
10362306a36Sopenharmony_ci    _FP_PACK_CANONICAL(Q,4,X);		\
10462306a36Sopenharmony_ci    _FP_PACK_RAW_4(Q,val,X);		\
10562306a36Sopenharmony_ci  } while (0)
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define FP_PACK_QP(val,X)		\
10862306a36Sopenharmony_ci  do {					\
10962306a36Sopenharmony_ci    _FP_PACK_CANONICAL(Q,4,X);		\
11062306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
11162306a36Sopenharmony_ci      _FP_PACK_RAW_4_P(Q,val,X);	\
11262306a36Sopenharmony_ci  } while (0)
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#define FP_ISSIGNAN_Q(X)		_FP_ISSIGNAN(Q,4,X)
11562306a36Sopenharmony_ci#define FP_NEG_Q(R,X)			_FP_NEG(Q,4,R,X)
11662306a36Sopenharmony_ci#define FP_ADD_Q(R,X,Y)			_FP_ADD(Q,4,R,X,Y)
11762306a36Sopenharmony_ci#define FP_SUB_Q(R,X,Y)			_FP_SUB(Q,4,R,X,Y)
11862306a36Sopenharmony_ci#define FP_MUL_Q(R,X,Y)			_FP_MUL(Q,4,R,X,Y)
11962306a36Sopenharmony_ci#define FP_DIV_Q(R,X,Y)			_FP_DIV(Q,4,R,X,Y)
12062306a36Sopenharmony_ci#define FP_SQRT_Q(R,X)			_FP_SQRT(Q,4,R,X)
12162306a36Sopenharmony_ci#define _FP_SQRT_MEAT_Q(R,S,T,X,Q)	_FP_SQRT_MEAT_4(R,S,T,X,Q)
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define FP_CMP_Q(r,X,Y,un)	_FP_CMP(Q,4,r,X,Y,un)
12462306a36Sopenharmony_ci#define FP_CMP_EQ_Q(r,X,Y)	_FP_CMP_EQ(Q,4,r,X,Y)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#define FP_TO_INT_Q(r,X,rsz,rsg)	_FP_TO_INT(Q,4,r,X,rsz,rsg)
12762306a36Sopenharmony_ci#define FP_TO_INT_ROUND_Q(r,X,rsz,rsg)	_FP_TO_INT_ROUND(Q,4,r,X,rsz,rsg)
12862306a36Sopenharmony_ci#define FP_FROM_INT_Q(X,r,rs,rt)	_FP_FROM_INT(Q,4,X,r,rs,rt)
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define _FP_FRAC_HIGH_Q(X)	_FP_FRAC_HIGH_4(X)
13162306a36Sopenharmony_ci#define _FP_FRAC_HIGH_RAW_Q(X)	_FP_FRAC_HIGH_4(X)
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#else   /* not _FP_W_TYPE_SIZE < 64 */
13462306a36Sopenharmony_ciunion _FP_UNION_Q
13562306a36Sopenharmony_ci{
13662306a36Sopenharmony_ci  long double flt /* __attribute__((mode(TF))) */ ;
13762306a36Sopenharmony_ci  struct {
13862306a36Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
13962306a36Sopenharmony_ci    unsigned sign  : 1;
14062306a36Sopenharmony_ci    unsigned exp   : _FP_EXPBITS_Q;
14162306a36Sopenharmony_ci    unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
14262306a36Sopenharmony_ci    unsigned long frac0 : _FP_W_TYPE_SIZE;
14362306a36Sopenharmony_ci#else
14462306a36Sopenharmony_ci    unsigned long frac0 : _FP_W_TYPE_SIZE;
14562306a36Sopenharmony_ci    unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
14662306a36Sopenharmony_ci    unsigned exp   : _FP_EXPBITS_Q;
14762306a36Sopenharmony_ci    unsigned sign  : 1;
14862306a36Sopenharmony_ci#endif
14962306a36Sopenharmony_ci  } bits;
15062306a36Sopenharmony_ci};
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci#define FP_DECL_Q(X)		_FP_DECL(2,X)
15362306a36Sopenharmony_ci#define FP_UNPACK_RAW_Q(X,val)	_FP_UNPACK_RAW_2(Q,X,val)
15462306a36Sopenharmony_ci#define FP_UNPACK_RAW_QP(X,val)	_FP_UNPACK_RAW_2_P(Q,X,val)
15562306a36Sopenharmony_ci#define FP_PACK_RAW_Q(val,X)	_FP_PACK_RAW_2(Q,val,X)
15662306a36Sopenharmony_ci#define FP_PACK_RAW_QP(val,X)		\
15762306a36Sopenharmony_ci  do {					\
15862306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
15962306a36Sopenharmony_ci      _FP_PACK_RAW_2_P(Q,val,X);	\
16062306a36Sopenharmony_ci  } while (0)
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci#define FP_UNPACK_Q(X,val)		\
16362306a36Sopenharmony_ci  do {					\
16462306a36Sopenharmony_ci    _FP_UNPACK_RAW_2(Q,X,val);		\
16562306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(Q,2,X);	\
16662306a36Sopenharmony_ci  } while (0)
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci#define FP_UNPACK_QP(X,val)		\
16962306a36Sopenharmony_ci  do {					\
17062306a36Sopenharmony_ci    _FP_UNPACK_RAW_2_P(Q,X,val);	\
17162306a36Sopenharmony_ci    _FP_UNPACK_CANONICAL(Q,2,X);	\
17262306a36Sopenharmony_ci  } while (0)
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#define FP_PACK_Q(val,X)		\
17562306a36Sopenharmony_ci  do {					\
17662306a36Sopenharmony_ci    _FP_PACK_CANONICAL(Q,2,X);		\
17762306a36Sopenharmony_ci    _FP_PACK_RAW_2(Q,val,X);		\
17862306a36Sopenharmony_ci  } while (0)
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci#define FP_PACK_QP(val,X)		\
18162306a36Sopenharmony_ci  do {					\
18262306a36Sopenharmony_ci    _FP_PACK_CANONICAL(Q,2,X);		\
18362306a36Sopenharmony_ci    if (!FP_INHIBIT_RESULTS)		\
18462306a36Sopenharmony_ci      _FP_PACK_RAW_2_P(Q,val,X);	\
18562306a36Sopenharmony_ci  } while (0)
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define FP_ISSIGNAN_Q(X)		_FP_ISSIGNAN(Q,2,X)
18862306a36Sopenharmony_ci#define FP_NEG_Q(R,X)			_FP_NEG(Q,2,R,X)
18962306a36Sopenharmony_ci#define FP_ADD_Q(R,X,Y)			_FP_ADD(Q,2,R,X,Y)
19062306a36Sopenharmony_ci#define FP_SUB_Q(R,X,Y)			_FP_SUB(Q,2,R,X,Y)
19162306a36Sopenharmony_ci#define FP_MUL_Q(R,X,Y)			_FP_MUL(Q,2,R,X,Y)
19262306a36Sopenharmony_ci#define FP_DIV_Q(R,X,Y)			_FP_DIV(Q,2,R,X,Y)
19362306a36Sopenharmony_ci#define FP_SQRT_Q(R,X)			_FP_SQRT(Q,2,R,X)
19462306a36Sopenharmony_ci#define _FP_SQRT_MEAT_Q(R,S,T,X,Q)	_FP_SQRT_MEAT_2(R,S,T,X,Q)
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#define FP_CMP_Q(r,X,Y,un)	_FP_CMP(Q,2,r,X,Y,un)
19762306a36Sopenharmony_ci#define FP_CMP_EQ_Q(r,X,Y)	_FP_CMP_EQ(Q,2,r,X,Y)
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#define FP_TO_INT_Q(r,X,rsz,rsg)	_FP_TO_INT(Q,2,r,X,rsz,rsg)
20062306a36Sopenharmony_ci#define FP_TO_INT_ROUND_Q(r,X,rsz,rsg)	_FP_TO_INT_ROUND(Q,2,r,X,rsz,rsg)
20162306a36Sopenharmony_ci#define FP_FROM_INT_Q(X,r,rs,rt)	_FP_FROM_INT(Q,2,X,r,rs,rt)
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci#define _FP_FRAC_HIGH_Q(X)	_FP_FRAC_HIGH_2(X)
20462306a36Sopenharmony_ci#define _FP_FRAC_HIGH_RAW_Q(X)	_FP_FRAC_HIGH_2(X)
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci#endif /* not _FP_W_TYPE_SIZE < 64 */
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci#endif /* __MATH_EMU_QUAD_H__ */
209