|
Packit |
6c4009 |
/* _Float128 IEEE like macros.
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
#ifndef _IEEE754_FLOAT128_H
|
|
Packit |
6c4009 |
#define _IEEE754_FLOAT128_H
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <endian.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
|
Packit |
6c4009 |
# define __FLT_EORDER2(t, a, b) t a; t b;
|
|
Packit |
6c4009 |
# define __FLT_EORDER4(t, a, b, c, d) \
|
|
Packit |
6c4009 |
t a; t b; t c; t d;
|
|
Packit |
6c4009 |
# define __FLT_EORDER6(t, a, b, c, d, e, f) \
|
|
Packit |
6c4009 |
t a; t b; t c; t d; t e; t f;
|
|
Packit |
6c4009 |
# define __FLT_EORDER7(t, a, b, c, d, e, f, g) \
|
|
Packit |
6c4009 |
t a; t b; t c; t d; t e; t f; t g;
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define __FLT_EORDER2(t, a, b) \
|
|
Packit |
6c4009 |
t b; t a;
|
|
Packit |
6c4009 |
# define __FLT_EORDER4(t, a, b, c, d) \
|
|
Packit |
6c4009 |
t d; t c; t b; t a;
|
|
Packit |
6c4009 |
# define __FLT_EORDER6(t, a, b, c, d, e, f) \
|
|
Packit |
6c4009 |
t f; t e; t d; t c; t b; t a;
|
|
Packit |
6c4009 |
# define __FLT_EORDER7(t, a, b, c, d, e, f, g) \
|
|
Packit |
6c4009 |
t g; t f; t e; t d; t c; t b; t a;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* A union which permits us to convert between _Float128 and
|
|
Packit |
6c4009 |
four 32 bit ints or two 64 bit ints. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
typedef union
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
_Float128 value;
|
|
Packit |
6c4009 |
struct
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__FLT_EORDER2 (uint64_t, msw, lsw);
|
|
Packit |
6c4009 |
} parts64;
|
|
Packit |
6c4009 |
struct
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__FLT_EORDER4 (uint32_t, w0, w1, w2, w3);
|
|
Packit |
6c4009 |
} parts32;
|
|
Packit |
6c4009 |
} ieee854_float128_shape_type;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get two 64 bit ints from a _Float128. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define GET_FLOAT128_WORDS64(ix0,ix1,d) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee854_float128_shape_type qw_u; \
|
|
Packit |
6c4009 |
qw_u.value = (d); \
|
|
Packit |
6c4009 |
(ix0) = qw_u.parts64.msw; \
|
|
Packit |
6c4009 |
(ix1) = qw_u.parts64.lsw; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set a _Float128 from two 64 bit ints. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define SET_FLOAT128_WORDS64(d,ix0,ix1) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee854_float128_shape_type qw_u; \
|
|
Packit |
6c4009 |
qw_u.parts64.msw = (ix0); \
|
|
Packit |
6c4009 |
qw_u.parts64.lsw = (ix1); \
|
|
Packit |
6c4009 |
(d) = qw_u.value; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get the more significant 64 bits of a _Float128 mantissa. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define GET_FLOAT128_MSW64(v,d) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee854_float128_shape_type sh_u; \
|
|
Packit |
6c4009 |
sh_u.value = (d); \
|
|
Packit |
6c4009 |
(v) = sh_u.parts64.msw; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set the more significant 64 bits of a _Float128 mantissa from an int. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define SET_FLOAT128_MSW64(d,v) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee854_float128_shape_type sh_u; \
|
|
Packit |
6c4009 |
sh_u.value = (d); \
|
|
Packit |
6c4009 |
sh_u.parts64.msw = (v); \
|
|
Packit |
6c4009 |
(d) = sh_u.value; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get the least significant 64 bits of a _Float128 mantissa. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define GET_FLOAT128_LSW64(v,d) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee854_float128_shape_type sh_u; \
|
|
Packit |
6c4009 |
sh_u.value = (d); \
|
|
Packit |
6c4009 |
(v) = sh_u.parts64.lsw; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Likewise, some helper macros which are exposed via ieee754.h for
|
|
Packit |
6c4009 |
C99 real types, but not _Float128. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
union ieee854_float128
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
_Float128 d;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This is the IEEE 854 quad-precision format. */
|
|
Packit |
6c4009 |
struct
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__FLT_EORDER6 (unsigned int, negative:1,
|
|
Packit |
6c4009 |
exponent:15,
|
|
Packit |
6c4009 |
mantissa0:16,
|
|
Packit |
6c4009 |
mantissa1:32,
|
|
Packit |
6c4009 |
mantissa2:32,
|
|
Packit |
6c4009 |
mantissa3:32)
|
|
Packit |
6c4009 |
} ieee;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This format makes it easier to see if a NaN is a signalling NaN. */
|
|
Packit |
6c4009 |
struct
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__FLT_EORDER7 (unsigned int, negative:1,
|
|
Packit |
6c4009 |
exponent:15,
|
|
Packit |
6c4009 |
quiet_nan:1,
|
|
Packit |
6c4009 |
mantissa0:15,
|
|
Packit |
6c4009 |
mantissa1:32,
|
|
Packit |
6c4009 |
mantissa2:32,
|
|
Packit |
6c4009 |
mantissa3:32)
|
|
Packit |
6c4009 |
} ieee_nan;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define IEEE854_FLOAT128_BIAS 0x3fff /* Added to exponent. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|