diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-10-12 01:20:30 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2016-10-12 01:20:30 +0000 |
commit | 5e9d98a3d9eec0a18e6875f6e86a3886fbb7e543 (patch) | |
tree | a4468dc50bae278c8ba8712e5953689b2be043f2 /sysdeps/ieee754/ldbl-128ibm | |
parent | 5da2c626a53bb3d4cfcdf773d94a153d8408d45b (diff) | |
download | glibc-5e9d98a3d9eec0a18e6875f6e86a3886fbb7e543.zip glibc-5e9d98a3d9eec0a18e6875f6e86a3886fbb7e543.tar.gz glibc-5e9d98a3d9eec0a18e6875f6e86a3886fbb7e543.tar.bz2 |
Add totalorder, totalorderf, totalorderl.
TS 18661-1 defines totalorder functions implementing the totalOrder
comparison operation from IEEE 754-2008. This patch implements these
functions for glibc, including the type-generic macro in <tgmath.h>.
(The totalordermag functions will be added in a separate patch.)
The description of the totalOrder operation is complicated. However,
for IEEE interchange binary formats and the preferred quiet NaN
convention, what that complicated description means is that you
interpret the representation as a sign-magnitude integer (with -0
coming before +0) and do a <= comparison on that interpretation. For
finite values and infinities the ordering of the sign-magnitude
integers is just the same as the ordering of floating-point values, so
this extends that to all representations. (Different representations
of the same floating-point value - which includes same quantum in the
decimal case - must still be considered equal by this operation, but
that issue doesn't arise for IEEE interchange binary formats.) So the
complications are:
* When MIPS quiet NaN conventions are in use, the representation of
NaNs needs adjusting before making such an integer comparison. This
patch does this adjustment only when both arguments are NaNs, as
there's no need for it if only one is a NaN, and as long as both are
NaNs you can just flip the relevant bits without any problems from
this turning a NaN into an infinity.
* For the m68k version of ldbl-96, where the high mantissa bit is
"don't care" for infinities and NaNs, representations where it
differs must compare the same. Note: although the testcase for this
compiles, I have not actually tested on m68k.
* For ldbl-128ibm, the low part must be ignored when the high part is
NaN, and low parts of +0 and -0 must be considered the same whatever
the high part.
The new tests in libm-test.inc are the first tests there specifying
particular payloads for input NaNs. Separate tests are also added for
the ldbl-96 and ldbl-128ibm special cases where there are different
representations of the same value that must compare equal (which can't
be covered in libm-test.inc as that only specifies values, not
representations).
Tested for x86_64, x86, mips64 and powerpc.
* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
(totalorder): New declaration.
* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (totalorder):
New macro.
* math/Versions (totalorder): New libm symbol at version
GLIBC_2.25.
(totalorderf): Likewise.
(totalorderl): Likewise.
* math/Makefile (libm-calls): Add s_totalorderF.
* math/gen-libm-test.pl (parse_args): Escape quotes in test name
string.
* math/libm-test.inc (PAYLOAD_DIG): New macro.
(qnan_value_pl): Likewise.
(snan_value_pl): Likewise.
(qnan_value): Define using qnan_value_pl.
(snan_value): Define using snan_value_pl.
(struct test_ff_i_data): Add comment about which tests use this
structure.
(RUN_TEST_ff_b): New macro.
(RUN_TEST_LOOP_ff_b): Likewise.
(totalorder_test_data): New array.
(totalorder_test): New function.
(main): Call totalorder_test.
* math/test-tgmath.c (NCALLS): Increase to 122.
(F(compile_test)): Call totalorder.
(F(totalorder)): New function.
* manual/arith.texi (FP Comparison Functions): Document
totalorder, totalorderf and totalorderl.
* manual/libm-err-tab.pl: Update comment on interfaces without
ulps tabulated.
* sysdeps/ieee754/dbl-64/s_totalorder.c: New file.
* sysdeps/ieee754/dbl-64/wordsize-64/s_totalorder.c: Likewise.
* sysdeps/ieee754/flt-32/s_totalorderf.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_totalorderl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_totalorderl.c: Likewise.
* sysdeps/ieee754/ldbl-opt/nldbl-totalorder.c: Likewise.
* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
totalorder.
(CFLAGS-nldbl-totalorder.c): New variable.
* sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c: New
file.
* sysdeps/ieee754/ldbl-128ibm/Makefile [$(subdir) = math] (tests):
Add test-totalorderl-ldbl-128ibm.
* sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c: New file.
* sysdeps/ieee754/ldbl-96/Makefile [$(subdir) = math] (tests): Add
test-totalorderl-ldbl-96.
* 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/ldbl-128ibm')
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/Makefile | 3 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c | 61 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c | 64 |
3 files changed, 127 insertions, 1 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/Makefile b/sysdeps/ieee754/ldbl-128ibm/Makefile index 56bebf8..eb625a7 100644 --- a/sysdeps/ieee754/ldbl-128ibm/Makefile +++ b/sysdeps/ieee754/ldbl-128ibm/Makefile @@ -11,5 +11,6 @@ endif ifeq ($(subdir),math) tests += test-fmodl-ldbl-128ibm test-remainderl-ldbl-128ibm \ - test-remquol-ldbl-128ibm test-iscanonical-ldbl-128ibm + test-remquol-ldbl-128ibm test-iscanonical-ldbl-128ibm \ + test-totalorderl-ldbl-128ibm endif diff --git a/sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c b/sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c new file mode 100644 index 0000000..1535b2f --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c @@ -0,0 +1,61 @@ +/* Total order operation. 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 <math.h> +#include <math_private.h> +#include <stdint.h> + +int +totalorderl (long double x, long double y) +{ + double xhi, xlo, yhi, ylo; + int64_t hx, hy, lx, ly; + + ldbl_unpack (x, &xhi, &xlo); + EXTRACT_WORDS64 (hx, xhi); + ldbl_unpack (y, &yhi, &ylo); + EXTRACT_WORDS64 (hy, yhi); +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN +# error not implemented +#endif + uint64_t hx_sign = hx >> 63; + uint64_t hy_sign = hy >> 63; + int64_t hx_adj = hx ^ (hx_sign >> 1); + int64_t hy_adj = hy ^ (hy_sign >> 1); + if (hx_adj < hy_adj) + return 1; + else if (hx_adj > hy_adj) + return 0; + + /* The high doubles are identical. If they are NaNs or both the low + parts are zero, the low parts are not significant (and if they + are infinities, both the low parts must be zero). */ + if ((hx & 0x7fffffffffffffffULL) >= 0x7ff0000000000000ULL) + return 1; + EXTRACT_WORDS64 (lx, xlo); + EXTRACT_WORDS64 (ly, ylo); + if (((lx | ly) & 0x7fffffffffffffffULL) == 0) + return 1; + + /* Otherwise compare the low parts. */ + uint64_t lx_sign = lx >> 63; + uint64_t ly_sign = ly >> 63; + lx ^= lx_sign >> 1; + ly ^= ly_sign >> 1; + return lx <= ly; +} diff --git a/sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c b/sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c new file mode 100644 index 0000000..78b162c --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c @@ -0,0 +1,64 @@ +/* Test totalorderl for ldbl-128ibm. + 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 <stdbool.h> +#include <stdio.h> + +struct test +{ + double hi, lo1, lo2; +}; + +static const struct test tests[] = + { + { __builtin_nan (""), 1, __builtin_nans ("") }, + { -__builtin_nan (""), 1, __builtin_nans ("") }, + { __builtin_nans (""), 1, __builtin_nan ("") }, + { -__builtin_nans (""), 1, __builtin_nan ("") }, + { __builtin_inf (), 0.0, -0.0 }, + { -__builtin_inf (), 0.0, -0.0 }, + { 1.5, 0.0, -0.0 }, + }; + +static int +do_test (void) +{ + int result = 0; + + for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + { + long double ldx = ldbl_pack (tests[i].hi, tests[i].lo1); + long double ldy = ldbl_pack (tests[i].hi, tests[i].lo2); + bool to1 = totalorderl (ldx, ldy); + bool to2 = totalorderl (ldy, ldx); + if (to1 && to2) + printf ("PASS: test %zu\n", i); + else + { + printf ("FAIL: test %zu\n", i); + result = 1; + } + } + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |