diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-10-19 01:49:09 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2016-10-19 01:49:09 +0000 |
commit | f8e8b8ed9f266097b42a77359445372d82365916 (patch) | |
tree | c8193dce446027347491ba1828af41d875708636 /sysdeps/ieee754 | |
parent | a9bfffe59333fdc6785f3cc903188d1ead36539d (diff) | |
download | glibc-f8e8b8ed9f266097b42a77359445372d82365916.zip glibc-f8e8b8ed9f266097b42a77359445372d82365916.tar.gz glibc-f8e8b8ed9f266097b42a77359445372d82365916.tar.bz2 |
Add getpayload, getpayloadf, getpayloadl.
TS 18661-1 defines functions for manipulating the payloads of NaNs.
This patch implements the getpayload functions for glibc; these
extract the NaN payload (from an argument passed as a pointer, for
which corresponding libm-test support is added) and return it in the
same floating-point type. The return value of these functions is
unspecified for non-NaN arguments; the patch does the simplest thing
to implement, which is that the functions do not check whether the
argument is a NaN and just treat the relevant bits of the
representation as a payload regardless. A conversion from integer to
floating-point is used to produce the required return value, except in
the ldbl-128 case; as 128-bit integers are not supported for all
configurations using ldbl-128, the code constructs the required
floating-point representation of the return value directly instead.
Tested for x86_64, x86, mips64 and powerpc.
* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
(getpayload): New declaration.
* math/Versions (getpayload): New libm symbol at version
GLIBC_2.25.
(getpayloadf): Likewise.
(getpayloadl): Likewise.
* math/Makefile (libm-calls): Add s_getpayloadF.
* math/libm-test.inc: Include <nan-high-order-bit.h>.
(struct test_f_f_data): Add comment.
(RUN_TEST_fp_f): New macro.
(RUN_TEST_LOOP_fp_f): Likewise.
(getpayload_test_data): New array.
(getpayload_test): New function.
(main): Call getpayload_test.
* math/gen-libm-test.pl (parse_args): Handle 'p' in argument
descriptor.
* manual/arith.texi (FP Bit Twiddling): Document getpayload,
getpayloadf and getpayloadl.
* manual/libm-err-tab.pl: Update comment on interfaces without
ulps tabulated.
* sysdeps/ieee754/dbl-64/s_getpayload.c: New file.
* sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c: Likewise.
* sysdeps/ieee754/flt-32/s_getpayloadf.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_getpayloadl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_getpayloadl.c: Likewise.
* sysdeps/nacl/libm.abilist: Update.
* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
Diffstat (limited to 'sysdeps/ieee754')
-rw-r--r-- | sysdeps/ieee754/dbl-64/s_getpayload.c | 37 | ||||
-rw-r--r-- | sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c | 33 | ||||
-rw-r--r-- | sysdeps/ieee754/flt-32/s_getpayloadf.c | 33 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128/s_getpayloadl.c | 57 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c | 34 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-96/s_getpayloadl.c | 32 |
6 files changed, 226 insertions, 0 deletions
diff --git a/sysdeps/ieee754/dbl-64/s_getpayload.c b/sysdeps/ieee754/dbl-64/s_getpayload.c new file mode 100644 index 0000000..2e7f033 --- /dev/null +++ b/sysdeps/ieee754/dbl-64/s_getpayload.c @@ -0,0 +1,37 @@ +/* Get NaN payload. dbl-64 version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <fix-int-fp-convert-zero.h> +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +double +getpayload (const double *x) +{ + uint32_t hx, lx; + EXTRACT_WORDS (hx, lx, *x); + hx &= 0x7ffff; + uint64_t ix = ((uint64_t) hx << 32) | lx; + if (FIX_INT_FP_CONVERT_ZERO && ix == 0) + return 0.0f; + return (double) ix; +} +#ifdef NO_LONG_DOUBLE +weak_alias (getpayload, getpayloadl) +#endif diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c new file mode 100644 index 0000000..c1cf56e --- /dev/null +++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c @@ -0,0 +1,33 @@ +/* Get NaN payload. dbl-64/wordsize-64 version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +double +getpayload (const double *x) +{ + uint64_t ix; + EXTRACT_WORDS64 (ix, *x); + ix &= 0x7ffffffffffffULL; + return (double) ix; +} +#ifdef NO_LONG_DOUBLE +weak_alias (getpayload, getpayloadl) +#endif diff --git a/sysdeps/ieee754/flt-32/s_getpayloadf.c b/sysdeps/ieee754/flt-32/s_getpayloadf.c new file mode 100644 index 0000000..fcc9e32 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_getpayloadf.c @@ -0,0 +1,33 @@ +/* Get NaN payload. flt-32 version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <fix-int-fp-convert-zero.h> +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +float +getpayloadf (const float *x) +{ + uint32_t ix; + GET_FLOAT_WORD (ix, *x); + ix &= 0x3fffff; + if (FIX_INT_FP_CONVERT_ZERO && ix == 0) + return 0.0f; + return (float) ix; +} diff --git a/sysdeps/ieee754/ldbl-128/s_getpayloadl.c b/sysdeps/ieee754/ldbl-128/s_getpayloadl.c new file mode 100644 index 0000000..ac7f6ed --- /dev/null +++ b/sysdeps/ieee754/ldbl-128/s_getpayloadl.c @@ -0,0 +1,57 @@ +/* Get NaN payload. ldbl-128 version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +long double +getpayloadl (const long double *x) +{ + uint64_t hx, lx; + GET_LDOUBLE_WORDS64 (hx, lx, *x); + hx &= 0x7fffffffffffULL; + /* Construct the representation of the return value directly, since + 128-bit integers may not be available. */ + int lz; + if (hx == 0) + { + if (lx == 0) + return 0.0L; + else + lz = __builtin_clzll (lx) + 64; + } + else + lz = __builtin_clzll (hx); + int shift = lz - 15; + if (shift >= 64) + { + hx = lx << (shift - 64); + lx = 0; + } + else + { + /* 2 <= SHIFT <= 63. */ + hx = (hx << shift) | (lx >> (64 - shift)); + lx <<= shift; + } + hx = (hx & 0xffffffffffffULL) | ((0x3fffULL + 127 - lz) << 48); + long double ret; + SET_LDOUBLE_WORDS64 (ret, hx, lx); + return ret; +} diff --git a/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c b/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c new file mode 100644 index 0000000..c23ba0c --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c @@ -0,0 +1,34 @@ +/* Get NaN payload. ldbl-128ibm version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <fix-int-fp-convert-zero.h> +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +long double +getpayloadl (const long double *x) +{ + double xhi = ldbl_high (*x); + uint64_t ix; + EXTRACT_WORDS64 (ix, xhi); + ix &= 0x7ffffffffffffULL; + if (FIX_INT_FP_CONVERT_ZERO && ix == 0) + return 0.0L; + return (long double) ix; +} diff --git a/sysdeps/ieee754/ldbl-96/s_getpayloadl.c b/sysdeps/ieee754/ldbl-96/s_getpayloadl.c new file mode 100644 index 0000000..3ef90d0 --- /dev/null +++ b/sysdeps/ieee754/ldbl-96/s_getpayloadl.c @@ -0,0 +1,32 @@ +/* Get NaN payload. ldbl-96 version. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +long double +getpayloadl (const long double *x) +{ + uint16_t se __attribute__ ((unused)); + uint32_t hx, lx; + GET_LDOUBLE_WORDS (se, hx, lx, *x); + hx &= 0x3fffffff; + uint64_t ix = ((uint64_t) hx << 32) | lx; + return (long double) ix; +} |