Use C2x return value from getpayload of non-NaN (bug 26073).

In TS 18661-1, getpayload had an unspecified return value for a
non-NaN argument, while C2x requires the return value -1 in that case.

This patch implements the return value of -1.  I don't think this is
worth having a new symbol version that's an alias of the old one,
although occasionally we do that in such cases where the new function
semantics are a refinement of the old ones (to avoid programs relying
on the new semantics running on older glibc versions but not behaving
as intended).

Tested for x86_64 and x86; also ran math/ tests for aarch64 and
powerpc.
This commit is contained in:
Joseph Myers 2020-07-06 16:18:02 +00:00
parent 28c13ae5bb
commit 6c010c5dde
8 changed files with 33 additions and 14 deletions

View File

@ -1895,9 +1895,10 @@ propagated from NaN inputs to the result of a floating-point
operation. These functions, defined by TS 18661-1:2014 and TS operation. These functions, defined by TS 18661-1:2014 and TS
18661-3:2015, return the payload of the NaN pointed to by @var{x} 18661-3:2015, return the payload of the NaN pointed to by @var{x}
(returned as a positive integer, or positive zero, represented as a (returned as a positive integer, or positive zero, represented as a
floating-point number); if @var{x} is not a NaN, they return an floating-point number); if @var{x} is not a NaN, they return
unspecified value. They raise no floating-point exceptions even for @minus{}1. They raise no floating-point exceptions even for signaling
signaling NaNs. NaNs. (The return value of @minus{}1 for an argument that is not a
NaN is specified in C2x; the value was unspecified in TS 18661.)
@end deftypefun @end deftypefun
@deftypefun int setpayload (double *@var{x}, double @var{payload}) @deftypefun int setpayload (double *@var{x}, double @var{payload})

View File

@ -20,17 +20,17 @@
static const struct test_f_f_data getpayload_test_data[] = static const struct test_f_f_data getpayload_test_data[] =
{ {
TEST_fp_f (getpayload, plus_infty, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, plus_infty, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, minus_infty, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, minus_infty, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, plus_zero, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, plus_zero, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, minus_zero, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, minus_zero, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, 1000, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, 1000, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, max_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, max_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, -max_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, -max_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, min_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, min_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, -min_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, -min_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, min_subnorm_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, min_subnorm_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, -min_subnorm_value, IGNORE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, -min_subnorm_value, -1.0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
#if HIGH_ORDER_BIT_IS_SET_FOR_SNAN #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
TEST_fp_f (getpayload, snan_value_pl ("0x0"), plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, snan_value_pl ("0x0"), plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fp_f (getpayload, -snan_value_pl ("0x0"), plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_fp_f (getpayload, -snan_value_pl ("0x0"), plus_zero, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),

View File

@ -27,6 +27,9 @@ __getpayload (const double *x)
{ {
uint32_t hx, lx; uint32_t hx, lx;
EXTRACT_WORDS (hx, lx, *x); EXTRACT_WORDS (hx, lx, *x);
if ((hx & 0x7ff00000) != 0x7ff00000
|| ((hx & 0xfffff) | lx) == 0)
return -1;
hx &= 0x7ffff; hx &= 0x7ffff;
uint64_t ix = ((uint64_t) hx << 32) | lx; uint64_t ix = ((uint64_t) hx << 32) | lx;
if (FIX_INT_FP_CONVERT_ZERO && ix == 0) if (FIX_INT_FP_CONVERT_ZERO && ix == 0)

View File

@ -26,6 +26,9 @@ __getpayload (const double *x)
{ {
uint64_t ix; uint64_t ix;
EXTRACT_WORDS64 (ix, *x); EXTRACT_WORDS64 (ix, *x);
if ((ix & 0x7ff0000000000000ULL) != 0x7ff0000000000000ULL
|| (ix & 0xfffffffffffffULL) == 0)
return -1;
ix &= 0x7ffffffffffffULL; ix &= 0x7ffffffffffffULL;
return (double) ix; return (double) ix;
} }

View File

@ -27,6 +27,9 @@ __getpayloadf (const float *x)
{ {
uint32_t ix; uint32_t ix;
GET_FLOAT_WORD (ix, *x); GET_FLOAT_WORD (ix, *x);
if ((ix & 0x7f800000) != 0x7f800000
|| (ix & 0x7fffff) == 0)
return -1;
ix &= 0x3fffff; ix &= 0x3fffff;
if (FIX_INT_FP_CONVERT_ZERO && ix == 0) if (FIX_INT_FP_CONVERT_ZERO && ix == 0)
return 0.0f; return 0.0f;

View File

@ -26,6 +26,9 @@ __getpayloadl (const _Float128 *x)
{ {
uint64_t hx, lx; uint64_t hx, lx;
GET_LDOUBLE_WORDS64 (hx, lx, *x); GET_LDOUBLE_WORDS64 (hx, lx, *x);
if ((hx & 0x7fff000000000000ULL) != 0x7fff000000000000ULL
|| ((hx & 0xffffffffffffULL) | lx) == 0)
return -1;
hx &= 0x7fffffffffffULL; hx &= 0x7fffffffffffULL;
/* Construct the representation of the return value directly, since /* Construct the representation of the return value directly, since
128-bit integers may not be available. */ 128-bit integers may not be available. */

View File

@ -27,6 +27,9 @@ __getpayloadl (const long double *x)
double xhi = ldbl_high (*x); double xhi = ldbl_high (*x);
uint64_t ix; uint64_t ix;
EXTRACT_WORDS64 (ix, xhi); EXTRACT_WORDS64 (ix, xhi);
if ((ix & 0x7ff0000000000000ULL) != 0x7ff0000000000000ULL
|| (ix & 0xfffffffffffffULL) == 0)
return -1;
ix &= 0x7ffffffffffffULL; ix &= 0x7ffffffffffffULL;
if (FIX_INT_FP_CONVERT_ZERO && ix == 0) if (FIX_INT_FP_CONVERT_ZERO && ix == 0)
return 0.0L; return 0.0L;

View File

@ -27,6 +27,9 @@ __getpayloadl (const long double *x)
uint16_t se __attribute__ ((unused)); uint16_t se __attribute__ ((unused));
uint32_t hx, lx; uint32_t hx, lx;
GET_LDOUBLE_WORDS (se, hx, lx, *x); GET_LDOUBLE_WORDS (se, hx, lx, *x);
if ((se & 0x7fff) != 0x7fff
|| ((hx & 0x7fffffff) | lx) == 0)
return -1;
hx &= 0x3fffffff; hx &= 0x3fffffff;
uint64_t ix = ((uint64_t) hx << 32) | lx; uint64_t ix = ((uint64_t) hx << 32) | lx;
return (long double) ix; return (long double) ix;