diff options
Diffstat (limited to 'sysdeps/ieee754')
-rw-r--r-- | sysdeps/ieee754/dbl-64/s_totalordermag.c | 48 | ||||
-rw-r--r-- | sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c | 46 | ||||
-rw-r--r-- | sysdeps/ieee754/flt-32/s_totalordermagf.c | 43 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128/s_totalordermagl.c | 47 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c | 63 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c | 11 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-96/s_totalordermagl.c | 50 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c | 13 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-opt/Makefile | 3 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c | 26 |
10 files changed, 347 insertions, 3 deletions
diff --git a/sysdeps/ieee754/dbl-64/s_totalordermag.c b/sysdeps/ieee754/dbl-64/s_totalordermag.c new file mode 100644 index 0000000000..e41dade54a --- /dev/null +++ b/sysdeps/ieee754/dbl-64/s_totalordermag.c @@ -0,0 +1,48 @@ +/* Total order operation on absolute values. 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 <math.h> +#include <math_private.h> +#include <stdint.h> + +int +totalordermag (double x, double y) +{ + uint32_t hx, hy; + uint32_t lx, ly; + EXTRACT_WORDS (hx, lx, x); + EXTRACT_WORDS (hy, ly, y); + hx &= 0x7fffffff; + hy &= 0x7fffffff; +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* For the preferred quiet NaN convention, this operation is a + comparison of the representations of the absolute values of the + arguments. If both arguments are NaNs, invert the + quiet/signaling bit so comparing that way works. */ + if ((hx > 0x7ff00000 || (hx == 0x7ff00000 && lx != 0)) + && (hy > 0x7ff00000 || (hy == 0x7ff00000 && ly != 0))) + { + hx ^= 0x00080000; + hy ^= 0x00080000; + } +#endif + return hx < hy || (hx == hy && lx <= ly); +} +#ifdef NO_LONG_DOUBLE +weak_alias (totalordermag, totalordermagl) +#endif diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c new file mode 100644 index 0000000000..38f2e1ba8f --- /dev/null +++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c @@ -0,0 +1,46 @@ +/* Total order operation on absolute values. 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> + +int +totalordermag (double x, double y) +{ + uint64_t ix, iy; + EXTRACT_WORDS64 (ix, x); + EXTRACT_WORDS64 (iy, y); + ix &= 0x7fffffffffffffffULL; + iy &= 0x7fffffffffffffffULL; +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* For the preferred quiet NaN convention, this operation is a + comparison of the representations of the absolute values of the + arguments. If both arguments are NaNs, invert the + quiet/signaling bit so comparing that way works. */ + if (ix > 0x7ff0000000000000ULL && iy > 0x7ff0000000000000ULL) + { + ix ^= 0x0008000000000000ULL; + iy ^= 0x0008000000000000ULL; + } +#endif + return ix <= iy; +} +#ifdef NO_LONG_DOUBLE +weak_alias (totalordermag, totalordermagl) +#endif diff --git a/sysdeps/ieee754/flt-32/s_totalordermagf.c b/sysdeps/ieee754/flt-32/s_totalordermagf.c new file mode 100644 index 0000000000..7c01edc29a --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_totalordermagf.c @@ -0,0 +1,43 @@ +/* Total order operation on absolute values. 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 <math.h> +#include <math_private.h> +#include <stdint.h> + +int +totalordermagf (float x, float y) +{ + uint32_t ix, iy; + GET_FLOAT_WORD (ix, x); + GET_FLOAT_WORD (iy, y); + ix &= 0x7fffffff; + iy &= 0x7fffffff; +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* For the preferred quiet NaN convention, this operation is a + comparison of the representations of the absolute values of the + arguments. If both arguments are NaNs, invert the + quiet/signaling bit so comparing that way works. */ + if (ix > 0x7f800000 && iy > 0x7f800000) + { + ix ^= 0x00400000; + iy ^= 0x00400000; + } +#endif + return ix <= iy; +} diff --git a/sysdeps/ieee754/ldbl-128/s_totalordermagl.c b/sysdeps/ieee754/ldbl-128/s_totalordermagl.c new file mode 100644 index 0000000000..bcfeecd4c4 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128/s_totalordermagl.c @@ -0,0 +1,47 @@ +/* Total order operation on absolute values. 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> + +int +totalordermagl (_Float128 x, _Float128 y) +{ + uint64_t hx, hy; + uint64_t lx, ly; + GET_LDOUBLE_WORDS64 (hx, lx, x); + GET_LDOUBLE_WORDS64 (hy, ly, y); + hx &= 0x7fffffffffffffffULL; + hy &= 0x7fffffffffffffffULL; +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* For the preferred quiet NaN convention, this operation is a + comparison of the representations of the absolute values of the + arguments. If both arguments are NaNs, invert the + quiet/signaling bit so comparing that way works. */ + if ((hx > 0x7fff000000000000ULL || (hx == 0x7fff000000000000ULL + && lx != 0)) + && (hy > 0x7fff000000000000ULL || (hy == 0x7fff000000000000ULL + && ly != 0))) + { + hx ^= 0x0000800000000000ULL; + hy ^= 0x0000800000000000ULL; + } +#endif + return hx < hy || (hx == hy && lx <= ly); +} diff --git a/sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c b/sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c new file mode 100644 index 0000000000..509a23a669 --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c @@ -0,0 +1,63 @@ +/* Total order operation on absolute values. 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 +totalordermagl (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 x_sign = hx & 0x8000000000000000ULL; + uint64_t y_sign = hy & 0x8000000000000000ULL; + hx ^= x_sign; + hy ^= y_sign; + if (hx < hy) + return 1; + else if (hx > hy) + 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 >= 0x7ff0000000000000ULL) + return 1; + EXTRACT_WORDS64 (lx, xlo); + EXTRACT_WORDS64 (ly, ylo); + if (((lx | ly) & 0x7fffffffffffffffULL) == 0) + return 1; + lx ^= x_sign; + ly ^= y_sign; + + /* 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 index 78b162c4fc..8e61a89f53 100644 --- a/sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c +++ b/sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c @@ -1,4 +1,4 @@ -/* Test totalorderl for ldbl-128ibm. +/* Test totalorderl and totalordermagl for ldbl-128ibm. Copyright (C) 2016 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -55,6 +55,15 @@ do_test (void) printf ("FAIL: test %zu\n", i); result = 1; } + to1 = totalordermagl (ldx, ldy); + to2 = totalordermagl (ldy, ldx); + if (to1 && to2) + printf ("PASS: test %zu (totalordermagl)\n", i); + else + { + printf ("FAIL: test %zu (totalordermagl)\n", i); + result = 1; + } } return result; diff --git a/sysdeps/ieee754/ldbl-96/s_totalordermagl.c b/sysdeps/ieee754/ldbl-96/s_totalordermagl.c new file mode 100644 index 0000000000..0167f0fb81 --- /dev/null +++ b/sysdeps/ieee754/ldbl-96/s_totalordermagl.c @@ -0,0 +1,50 @@ +/* Total order operation on absolute values. 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 <float.h> +#include <math.h> +#include <math_private.h> +#include <stdint.h> + +int +totalordermagl (long double x, long double y) +{ + uint16_t expx, expy; + uint32_t hx, hy; + uint32_t lx, ly; + GET_LDOUBLE_WORDS (expx, hx, lx, x); + GET_LDOUBLE_WORDS (expy, hy, ly, y); + expx &= 0x7fff; + expy &= 0x7fff; + if (LDBL_MIN_EXP == -16382) + { + /* M68K variant: for the greatest exponent, the high mantissa + bit is not significant and both values of it are valid, so + set it before comparing. For the Intel variant, only one + value of the high mantissa bit is valid for each exponent, so + this is not necessary. */ + if (expx == 0x7fff) + hx |= 0x80000000; + if (expy == 0x7fff) + hy |= 0x80000000; + } +#ifdef HIGH_ORDER_BIT_IS_SET_FOR_SNAN +# error not implemented +#endif + return expx < expy || (expx == expy && (hx < hy || (hx == hy && lx <= ly))); +} diff --git a/sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c b/sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c index 07fa772414..6afc1b5c1b 100644 --- a/sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c +++ b/sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c @@ -1,4 +1,4 @@ -/* Test totalorderl for ldbl-96. +/* Test totalorderl and totalordermagl for ldbl-96. Copyright (C) 2016 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -62,6 +62,17 @@ do_test (void) printf ("FAIL: test %zu\n", i); result = 1; } + to1 = totalordermagl (ldx, ldy); + to2 = totalordermagl (ldy, ldx); + to3 = totalordermagl (ldnx, ldny); + to4 = totalordermagl (ldny, ldnx); + if (to1 && to2 && to3 && to4) + printf ("PASS: test %zu (totalordermagl)\n", i); + else + { + printf ("FAIL: test %zu (totalordermagl)\n", i); + result = 1; + } } return result; diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile index 12255d6951..4c7db9e353 100644 --- a/sysdeps/ieee754/ldbl-opt/Makefile +++ b/sysdeps/ieee754/ldbl-opt/Makefile @@ -41,7 +41,7 @@ libnldbl-calls = asprintf dprintf fprintf fscanf fwprintf fwscanf iovfscanf \ isoc99_vscanf isoc99_vfscanf isoc99_vsscanf \ isoc99_wscanf isoc99_fwscanf isoc99_swscanf \ isoc99_vwscanf isoc99_vfwscanf isoc99_vswscanf \ - nextup nextdown totalorder + nextup nextdown totalorder totalordermag libnldbl-routines = $(libnldbl-calls:%=nldbl-%) libnldbl-inhibit-o = $(object-suffixes) libnldbl-static-only-routines = $(libnldbl-routines) @@ -143,6 +143,7 @@ CFLAGS-nldbl-tan.c = -fno-builtin-tanl CFLAGS-nldbl-tanh.c = -fno-builtin-tanhl CFLAGS-nldbl-tgamma.c = -fno-builtin-tgammal CFLAGS-nldbl-totalorder.c = -fno-builtin-totalorderl +CFLAGS-nldbl-totalordermag.c = -fno-builtin-totalordermagl CFLAGS-nldbl-trunc.c = -fno-builtin-truncl CFLAGS-nldbl-y0.c = -fno-builtin-y0l CFLAGS-nldbl-y1.c = -fno-builtin-y1l diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c b/sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c new file mode 100644 index 0000000000..2780383aea --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c @@ -0,0 +1,26 @@ +/* Compatibility routine for IEEE double as long double for totalordermag. + 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 "nldbl-compat.h" + +double +attribute_hidden +totalordermagl (double x, double y) +{ + return totalordermag (x, y); +} |