public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] x86 pseudo-normal numbers
@ 2020-12-24  2:45 Siddhesh Poyarekar
  2020-12-24  2:45 ` [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
  2020-12-24  2:45 ` [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers Siddhesh Poyarekar
  0 siblings, 2 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-24  2:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, fweimer, joseph

Following is the patchset that harmonizes classification of
pseudo-normal numbers with gcc.  Pseudo-NaNs, Pseudo-Infinities and
unnormal numbers are considered as signaling NaN as per classification
since that is how they behave when used as operands in x86.

In summary, the patchset does the following:

- Make issignalingl return true for all pseudo-normals.
- Add tests

Changes since v1:

- Committed patches 1-3, so these are the only two remaining.

Siddhesh Poyarekar (2):
  x86 long double: Consider pseudo numbers as signaling
  x86 long double: Add tests for pseudo normal numbers

 math/libm-test-driver.c                  | 38 ++++++++++++++++++++++++
 math/libm-test-fpclassify.inc            | 14 +++++++++
 math/libm-test-isnan.inc                 | 14 +++++++++
 math/libm-test-issignaling.inc           | 14 +++++++++
 sysdeps/generic/nan-pseudo-number.h      | 32 ++++++++++++++++++++
 sysdeps/ieee754/ldbl-96/s_issignalingl.c | 11 +++++--
 sysdeps/x86/fpu/nan-pseudo-number.h      | 30 +++++++++++++++++++
 7 files changed, 150 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/generic/nan-pseudo-number.h
 create mode 100644 sysdeps/x86/fpu/nan-pseudo-number.h

-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling
  2020-12-24  2:45 [PATCH v3 0/2] x86 pseudo-normal numbers Siddhesh Poyarekar
@ 2020-12-24  2:45 ` Siddhesh Poyarekar
  2020-12-28 16:57   ` Adhemerval Zanella
  2020-12-31 22:58   ` [PATCH v3 1/2] " Joseph Myers
  2020-12-24  2:45 ` [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers Siddhesh Poyarekar
  1 sibling, 2 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-24  2:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, fweimer, joseph

Add support to treat pseudo-numbers specially and implement x86
version to consider all of them as signaling.
---
 sysdeps/generic/nan-pseudo-number.h      | 32 ++++++++++++++++++++++++
 sysdeps/ieee754/ldbl-96/s_issignalingl.c | 11 +++++---
 sysdeps/x86/fpu/nan-pseudo-number.h      | 30 ++++++++++++++++++++++
 3 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/generic/nan-pseudo-number.h
 create mode 100644 sysdeps/x86/fpu/nan-pseudo-number.h

diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/generic/nan-pseudo-number.h
new file mode 100644
index 0000000000..1562e06e4b
--- /dev/null
+++ b/sysdeps/generic/nan-pseudo-number.h
@@ -0,0 +1,32 @@
+/* Pseudo-normal number handling.  Generic version.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef NAN_PSEUDO_NUMBER_H
+#define NAN_PSEUDO_NUMBER_H	1
+
+/* Set this macro and override the definition of IS_PSEUDO_SIGNALING if pseudo
+   numbers need special handling.  */
+#define HANDLE_PSEUDO_NUMBERS 0
+static inline int
+is_pseudo_signaling (uint32_t exi __attribute__ ((unused)),
+		     uint32_t hxi __attribute__ ((unused)))
+{
+  return 0;
+}
+
+#endif /* nan-pseudo-number.h */
diff --git a/sysdeps/ieee754/ldbl-96/s_issignalingl.c b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
index ec542ad468..37e05aa259 100644
--- a/sysdeps/ieee754/ldbl-96/s_issignalingl.c
+++ b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
@@ -19,12 +19,19 @@
 #include <math.h>
 #include <math_private.h>
 #include <nan-high-order-bit.h>
+#include <nan-pseudo-number.h>
 
 int
 __issignalingl (long double x)
 {
   uint32_t exi, hxi, lxi;
   GET_LDOUBLE_WORDS (exi, hxi, lxi, x);
+
+  /* By default we do not recognize a pseudo NaN as sNaN.  However on 80387 and
+     later all pseudo numbers including pseudo NaNs result in a signal and are
+     hence recognized as signaling.  */
+  int ret = is_pseudo_signaling (exi, hxi);
+
 #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
 # error not implemented
 #else
@@ -34,11 +41,9 @@ __issignalingl (long double x)
   hxi ^= 0x40000000;
   /* If lxi != 0, then set any suitable bit of the significand in hxi.  */
   hxi |= (lxi | -lxi) >> 31;
-  /* We do not recognize a pseudo NaN as sNaN; they're invalid on 80387 and
-     later.  */
   /* We have to compare for greater (instead of greater or equal), because x's
      significand being all-zero designates infinity not NaN.  */
-  return ((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000);
+  return ret || (((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000));
 #endif
 }
 libm_hidden_def (__issignalingl)
diff --git a/sysdeps/x86/fpu/nan-pseudo-number.h b/sysdeps/x86/fpu/nan-pseudo-number.h
new file mode 100644
index 0000000000..ea43b175a1
--- /dev/null
+++ b/sysdeps/x86/fpu/nan-pseudo-number.h
@@ -0,0 +1,30 @@
+/* Pseudo-normal number handling.  x86 version.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef NAN_PSEUDO_NUMBER_H
+#define NAN_PSEUDO_NUMBER_H	1
+
+#define HANDLE_PSEUDO_NUMBERS 1
+/* Pseudo numbers on x86 are always signaling.  */
+static inline int
+is_pseudo_signaling (uint32_t exi, uint32_t hxi)
+{
+  return ((exi & 0x7fff) && ((hxi & 0x80000000) == 0));
+}
+
+#endif /* nan-pseudo-number.h */
-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers
  2020-12-24  2:45 [PATCH v3 0/2] x86 pseudo-normal numbers Siddhesh Poyarekar
  2020-12-24  2:45 ` [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
@ 2020-12-24  2:45 ` Siddhesh Poyarekar
  2020-12-28 17:04   ` Adhemerval Zanella
  2020-12-31 23:09   ` Joseph Myers
  1 sibling, 2 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-24  2:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, fweimer, joseph

Add some tests for fpclassify, isnan, isinf and issignaling.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
 math/libm-test-driver.c        | 38 ++++++++++++++++++++++++++++++++++
 math/libm-test-fpclassify.inc  | 14 +++++++++++++
 math/libm-test-isinf.inc       | 14 +++++++++++++
 math/libm-test-isnan.inc       | 14 +++++++++++++
 math/libm-test-issignaling.inc | 14 +++++++++++++
 5 files changed, 94 insertions(+)

diff --git a/math/libm-test-driver.c b/math/libm-test-driver.c
index 11b541b2e7..7f1af071da 100644
--- a/math/libm-test-driver.c
+++ b/math/libm-test-driver.c
@@ -19,6 +19,7 @@
 #include "libm-test-support.h"
 
 #include <math-tests-arch.h>
+#include <nan-pseudo-number.h>
 
 /* Flags set by the including file.  */
 const int flag_test_errno = TEST_ERRNO;
@@ -122,6 +123,16 @@ const char qtype_str[] = TYPE_STR;
 /* For nexttoward tests.  */
 #define snan_value_ld	__builtin_nansl ("")
 
+/* For pseudo-normal number tests.  */
+#if HANDLE_PSEUDO_NUMBERS
+# include <math_ldbl.h>
+#define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }}
+#define pseudo_zero { .parts = { 0x00000000, 0x00000000, 0x0100 }}
+#define pseudo_qnan { .parts = { 0x00000001, 0x00000000, 0x7fff }}
+#define pseudo_snan { .parts = { 0x00000001, 0x40000000, 0x7fff }}
+#define pseudo_unnormal { .parts = { 0x00000001, 0x40000000, 0x0100 }}
+#endif
+
 /* Structures for each kind of test.  */
 /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f.  */
 struct test_f_f_data
@@ -316,6 +327,19 @@ struct test_f_i_data
     int exceptions;
   } rd, rn, rz, ru;
 };
+/* Used for RUN_TEST_LOOP_f_i_tg_u and RUN_TEST_LOOP_f_b_tg_u.  */
+#if HANDLE_PSEUDO_NUMBERS
+struct test_f_i_data_u
+{
+  const char *arg_str;
+  ieee_long_double_shape_type arg;
+  struct
+  {
+    int expected;
+    int exceptions;
+  } rd, rn, rz, ru;
+};
+#endif
 /* Used for RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
    RUN_TEST_LOOP_ff_i_tg.  */
 struct test_ff_i_data
@@ -832,6 +856,20 @@ struct test_Ff_b1_data
 		       (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
 		       (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);	\
   ROUND_RESTORE_ ## ROUNDING_MODE
+#define RUN_TEST_LOOP_f_b_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE)		\
+  IF_ROUND_INIT_ ## ROUNDING_MODE					\
+  for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++)	\
+  RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg.value,	\
+		   (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
+		   (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);		\
+  ROUND_RESTORE_ ## ROUNDING_MODE
+#define RUN_TEST_LOOP_f_i_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE)		\
+  IF_ROUND_INIT_ ## ROUNDING_MODE					\
+  for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++)	\
+  RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg.value,	\
+		   (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
+		   (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);		\
+  ROUND_RESTORE_ ## ROUNDING_MODE
 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED,		\
 		      EXCEPTIONS)					\
   do									\
diff --git a/math/libm-test-fpclassify.inc b/math/libm-test-fpclassify.inc
index 96b557ecb4..480ccfe9cb 100644
--- a/math/libm-test-fpclassify.inc
+++ b/math/libm-test-fpclassify.inc
@@ -37,10 +37,24 @@ static const struct test_f_i_data fpclassify_test_data[] =
     TEST_f_i (fpclassify, -min_subnorm_value, FP_SUBNORMAL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
   };
 
+#if HANDLE_PSEUDO_NUMBERS
+static const struct test_f_i_data_u fpclassify_test_data_u[] =
+  {
+    TEST_f_i (fpclassify, pseudo_zero, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_i (fpclassify, pseudo_inf, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_i (fpclassify, pseudo_qnan, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_i (fpclassify, pseudo_snan, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_i (fpclassify, pseudo_unnormal, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+#endif
+
 static void
 fpclassify_test (void)
 {
   ALL_RM_TEST (fpclassify, 1, fpclassify_test_data, RUN_TEST_LOOP_f_i_tg, END);
+#if HANDLE_PSEUDO_NUMBERS
+  ALL_RM_TEST (fpclassify, 1, fpclassify_test_data_u, RUN_TEST_LOOP_f_i_tg_u, END);
+#endif
 }
 
 static void
diff --git a/math/libm-test-isinf.inc b/math/libm-test-isinf.inc
index 6ecbf7ba6e..44cebd2198 100644
--- a/math/libm-test-isinf.inc
+++ b/math/libm-test-isinf.inc
@@ -37,10 +37,24 @@ static const struct test_f_i_data isinf_test_data[] =
     TEST_f_b (isinf, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
   };
 
+#if HANDLE_PSEUDO_NUMBERS
+static const struct test_f_i_data_u isinf_test_data_u[] =
+  {
+    TEST_f_b (isinf, pseudo_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isinf, pseudo_inf, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isinf, pseudo_qnan, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isinf, pseudo_snan, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isinf, pseudo_unnormal, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+#endif
+
 static void
 isinf_test (void)
 {
   ALL_RM_TEST (isinf, 1, isinf_test_data, RUN_TEST_LOOP_f_b_tg, END);
+#if HANDLE_PSEUDO_NUMBERS
+  ALL_RM_TEST (isinf, 1, isinf_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
+#endif
 }
 
 static void
diff --git a/math/libm-test-isnan.inc b/math/libm-test-isnan.inc
index e6e2bb6a47..d8545c4dc5 100644
--- a/math/libm-test-isnan.inc
+++ b/math/libm-test-isnan.inc
@@ -37,10 +37,24 @@ static const struct test_f_i_data isnan_test_data[] =
     TEST_f_b (isnan, -snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
   };
 
+#if HANDLE_PSEUDO_NUMBERS
+static const struct test_f_i_data_u isnan_test_data_u[] =
+  {
+    TEST_f_b (isnan, pseudo_zero, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isnan, pseudo_inf, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isnan, pseudo_qnan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isnan, pseudo_snan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (isnan, pseudo_unnormal, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+#endif
+
 static void
 isnan_test (void)
 {
   ALL_RM_TEST (isnan, 1, isnan_test_data, RUN_TEST_LOOP_f_b_tg, END);
+#if HANDLE_PSEUDO_NUMBERS
+  ALL_RM_TEST (isnan, 1, isnan_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
+#endif
 }
 
 static void
diff --git a/math/libm-test-issignaling.inc b/math/libm-test-issignaling.inc
index a2bdcef265..80060dcb75 100644
--- a/math/libm-test-issignaling.inc
+++ b/math/libm-test-issignaling.inc
@@ -39,10 +39,24 @@ static const struct test_f_i_data issignaling_test_data[] =
     TEST_f_b (issignaling, -snan_value_MACRO, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
   };
 
+#if HANDLE_PSEUDO_NUMBERS
+static const struct test_f_i_data_u issignaling_test_data_u[] =
+  {
+    TEST_f_b (issignaling, pseudo_zero, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (issignaling, pseudo_inf, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (issignaling, pseudo_qnan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (issignaling, pseudo_snan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (issignaling, pseudo_unnormal, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+#endif
+
 static void
 issignaling_test (void)
 {
   ALL_RM_TEST (issignaling, 1, issignaling_test_data, RUN_TEST_LOOP_f_b_tg, END);
+#if HANDLE_PSEUDO_NUMBERS
+  ALL_RM_TEST (issignaling, 1, issignaling_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
+#endif
 }
 
 static void
-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling
  2020-12-24  2:45 ` [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
@ 2020-12-28 16:57   ` Adhemerval Zanella
  2020-12-30  5:31     ` [COMMITTED] " Siddhesh Poyarekar
  2020-12-31 22:58   ` [PATCH v3 1/2] " Joseph Myers
  1 sibling, 1 reply; 10+ messages in thread
From: Adhemerval Zanella @ 2020-12-28 16:57 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: fweimer, joseph



On 23/12/2020 23:45, Siddhesh Poyarekar wrote:
> Add support to treat pseudo-numbers specially and implement x86
> version to consider all of them as signaling.

Ok with the above changes.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/nan-pseudo-number.h      | 32 ++++++++++++++++++++++++
>  sysdeps/ieee754/ldbl-96/s_issignalingl.c | 11 +++++---
>  sysdeps/x86/fpu/nan-pseudo-number.h      | 30 ++++++++++++++++++++++
>  3 files changed, 70 insertions(+), 3 deletions(-)
>  create mode 100644 sysdeps/generic/nan-pseudo-number.h
>  create mode 100644 sysdeps/x86/fpu/nan-pseudo-number.h
> 
> diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/generic/nan-pseudo-number.h
> new file mode 100644
> index 0000000000..1562e06e4b
> --- /dev/null
> +++ b/sysdeps/generic/nan-pseudo-number.h
> @@ -0,0 +1,32 @@
> +/* Pseudo-normal number handling.  Generic version.
> +   Copyright (C) 2020 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef NAN_PSEUDO_NUMBER_H
> +#define NAN_PSEUDO_NUMBER_H	1
> +
> +/* Set this macro and override the definition of IS_PSEUDO_SIGNALING if pseudo
> +   numbers need special handling.  */
> +#define HANDLE_PSEUDO_NUMBERS 0
> +static inline int
> +is_pseudo_signaling (uint32_t exi __attribute__ ((unused)),
> +		     uint32_t hxi __attribute__ ((unused)))
> +{
> +  return 0;
> +}
> +
> +#endif /* nan-pseudo-number.h */

Afaik, there is no need to __attribute__ ((unused)) on arguments for static
inline functions.

> diff --git a/sysdeps/ieee754/ldbl-96/s_issignalingl.c b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
> index ec542ad468..37e05aa259 100644
> --- a/sysdeps/ieee754/ldbl-96/s_issignalingl.c
> +++ b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
> @@ -19,12 +19,19 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <nan-high-order-bit.h>
> +#include <nan-pseudo-number.h>
>  
>  int
>  __issignalingl (long double x)
>  {
>    uint32_t exi, hxi, lxi;
>    GET_LDOUBLE_WORDS (exi, hxi, lxi, x);
> +
> +  /* By default we do not recognize a pseudo NaN as sNaN.  However on 80387 and
> +     later all pseudo numbers including pseudo NaNs result in a signal and are
> +     hence recognized as signaling.  */
> +  int ret = is_pseudo_signaling (exi, hxi);
> +
>  #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
>  # error not implemented
>  #else
> @@ -34,11 +41,9 @@ __issignalingl (long double x)
>    hxi ^= 0x40000000;
>    /* If lxi != 0, then set any suitable bit of the significand in hxi.  */
>    hxi |= (lxi | -lxi) >> 31;
> -  /* We do not recognize a pseudo NaN as sNaN; they're invalid on 80387 and
> -     later.  */
>    /* We have to compare for greater (instead of greater or equal), because x's
>       significand being all-zero designates infinity not NaN.  */
> -  return ((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000);
> +  return ret || (((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000));
>  #endif
>  }
>  libm_hidden_def (__issignalingl)

Ok.

> diff --git a/sysdeps/x86/fpu/nan-pseudo-number.h b/sysdeps/x86/fpu/nan-pseudo-number.h
> new file mode 100644
> index 0000000000..ea43b175a1
> --- /dev/null
> +++ b/sysdeps/x86/fpu/nan-pseudo-number.h
> @@ -0,0 +1,30 @@
> +/* Pseudo-normal number handling.  x86 version.
> +   Copyright (C) 2020 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef NAN_PSEUDO_NUMBER_H
> +#define NAN_PSEUDO_NUMBER_H	1
> +
> +#define HANDLE_PSEUDO_NUMBERS 1
> +/* Pseudo numbers on x86 are always signaling.  */
> +static inline int
> +is_pseudo_signaling (uint32_t exi, uint32_t hxi)
> +{
> +  return ((exi & 0x7fff) && ((hxi & 0x80000000) == 0));
> +}
> +
> +#endif /* nan-pseudo-number.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers
  2020-12-24  2:45 ` [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers Siddhesh Poyarekar
@ 2020-12-28 17:04   ` Adhemerval Zanella
  2020-12-31 23:09   ` Joseph Myers
  1 sibling, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2020-12-28 17:04 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: fweimer, joseph



On 23/12/2020 23:45, Siddhesh Poyarekar wrote:
> Add some tests for fpclassify, isnan, isinf and issignaling.
> 
> Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

LGTM, thanks.

> ---
>  math/libm-test-driver.c        | 38 ++++++++++++++++++++++++++++++++++
>  math/libm-test-fpclassify.inc  | 14 +++++++++++++
>  math/libm-test-isinf.inc       | 14 +++++++++++++
>  math/libm-test-isnan.inc       | 14 +++++++++++++
>  math/libm-test-issignaling.inc | 14 +++++++++++++
>  5 files changed, 94 insertions(+)
> 
> diff --git a/math/libm-test-driver.c b/math/libm-test-driver.c
> index 11b541b2e7..7f1af071da 100644
> --- a/math/libm-test-driver.c
> +++ b/math/libm-test-driver.c
> @@ -19,6 +19,7 @@
>  #include "libm-test-support.h"
>  
>  #include <math-tests-arch.h>
> +#include <nan-pseudo-number.h>
>  
>  /* Flags set by the including file.  */
>  const int flag_test_errno = TEST_ERRNO;
> @@ -122,6 +123,16 @@ const char qtype_str[] = TYPE_STR;
>  /* For nexttoward tests.  */
>  #define snan_value_ld	__builtin_nansl ("")
>  
> +/* For pseudo-normal number tests.  */
> +#if HANDLE_PSEUDO_NUMBERS
> +# include <math_ldbl.h>
> +#define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }}
> +#define pseudo_zero { .parts = { 0x00000000, 0x00000000, 0x0100 }}
> +#define pseudo_qnan { .parts = { 0x00000001, 0x00000000, 0x7fff }}
> +#define pseudo_snan { .parts = { 0x00000001, 0x40000000, 0x7fff }}
> +#define pseudo_unnormal { .parts = { 0x00000001, 0x40000000, 0x0100 }}
> +#endif
> +
>  /* Structures for each kind of test.  */
>  /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f.  */
>  struct test_f_f_data
> @@ -316,6 +327,19 @@ struct test_f_i_data
>      int exceptions;
>    } rd, rn, rz, ru;
>  };
> +/* Used for RUN_TEST_LOOP_f_i_tg_u and RUN_TEST_LOOP_f_b_tg_u.  */
> +#if HANDLE_PSEUDO_NUMBERS
> +struct test_f_i_data_u
> +{
> +  const char *arg_str;
> +  ieee_long_double_shape_type arg;
> +  struct
> +  {
> +    int expected;
> +    int exceptions;
> +  } rd, rn, rz, ru;
> +};
> +#endif
>  /* Used for RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
>     RUN_TEST_LOOP_ff_i_tg.  */
>  struct test_ff_i_data
> @@ -832,6 +856,20 @@ struct test_Ff_b1_data
>  		       (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
>  		       (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);	\
>    ROUND_RESTORE_ ## ROUNDING_MODE
> +#define RUN_TEST_LOOP_f_b_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE)		\
> +  IF_ROUND_INIT_ ## ROUNDING_MODE					\
> +  for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++)	\
> +  RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg.value,	\
> +		   (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
> +		   (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);		\
> +  ROUND_RESTORE_ ## ROUNDING_MODE
> +#define RUN_TEST_LOOP_f_i_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE)		\
> +  IF_ROUND_INIT_ ## ROUNDING_MODE					\
> +  for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++)	\
> +  RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg.value,	\
> +		   (ARRAY)[i].RM_##ROUNDING_MODE.expected,		\
> +		   (ARRAY)[i].RM_##ROUNDING_MODE.exceptions);		\
> +  ROUND_RESTORE_ ## ROUNDING_MODE
>  #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED,		\
>  		      EXCEPTIONS)					\
>    do									\
> diff --git a/math/libm-test-fpclassify.inc b/math/libm-test-fpclassify.inc
> index 96b557ecb4..480ccfe9cb 100644
> --- a/math/libm-test-fpclassify.inc
> +++ b/math/libm-test-fpclassify.inc
> @@ -37,10 +37,24 @@ static const struct test_f_i_data fpclassify_test_data[] =
>      TEST_f_i (fpclassify, -min_subnorm_value, FP_SUBNORMAL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
>    };
>  
> +#if HANDLE_PSEUDO_NUMBERS
> +static const struct test_f_i_data_u fpclassify_test_data_u[] =
> +  {
> +    TEST_f_i (fpclassify, pseudo_zero, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_i (fpclassify, pseudo_inf, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_i (fpclassify, pseudo_qnan, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_i (fpclassify, pseudo_snan, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_i (fpclassify, pseudo_unnormal, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +  };
> +#endif
> +
>  static void
>  fpclassify_test (void)
>  {
>    ALL_RM_TEST (fpclassify, 1, fpclassify_test_data, RUN_TEST_LOOP_f_i_tg, END);
> +#if HANDLE_PSEUDO_NUMBERS
> +  ALL_RM_TEST (fpclassify, 1, fpclassify_test_data_u, RUN_TEST_LOOP_f_i_tg_u, END);
> +#endif
>  }
>  
>  static void
> diff --git a/math/libm-test-isinf.inc b/math/libm-test-isinf.inc
> index 6ecbf7ba6e..44cebd2198 100644
> --- a/math/libm-test-isinf.inc
> +++ b/math/libm-test-isinf.inc
> @@ -37,10 +37,24 @@ static const struct test_f_i_data isinf_test_data[] =
>      TEST_f_b (isinf, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
>    };
>  
> +#if HANDLE_PSEUDO_NUMBERS
> +static const struct test_f_i_data_u isinf_test_data_u[] =
> +  {
> +    TEST_f_b (isinf, pseudo_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isinf, pseudo_inf, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isinf, pseudo_qnan, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isinf, pseudo_snan, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isinf, pseudo_unnormal, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +  };
> +#endif
> +
>  static void
>  isinf_test (void)
>  {
>    ALL_RM_TEST (isinf, 1, isinf_test_data, RUN_TEST_LOOP_f_b_tg, END);
> +#if HANDLE_PSEUDO_NUMBERS
> +  ALL_RM_TEST (isinf, 1, isinf_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
> +#endif
>  }
>  
>  static void
> diff --git a/math/libm-test-isnan.inc b/math/libm-test-isnan.inc
> index e6e2bb6a47..d8545c4dc5 100644
> --- a/math/libm-test-isnan.inc
> +++ b/math/libm-test-isnan.inc
> @@ -37,10 +37,24 @@ static const struct test_f_i_data isnan_test_data[] =
>      TEST_f_b (isnan, -snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
>    };
>  
> +#if HANDLE_PSEUDO_NUMBERS
> +static const struct test_f_i_data_u isnan_test_data_u[] =
> +  {
> +    TEST_f_b (isnan, pseudo_zero, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isnan, pseudo_inf, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isnan, pseudo_qnan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isnan, pseudo_snan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (isnan, pseudo_unnormal, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +  };
> +#endif
> +
>  static void
>  isnan_test (void)
>  {
>    ALL_RM_TEST (isnan, 1, isnan_test_data, RUN_TEST_LOOP_f_b_tg, END);
> +#if HANDLE_PSEUDO_NUMBERS
> +  ALL_RM_TEST (isnan, 1, isnan_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
> +#endif
>  }
>  
>  static void
> diff --git a/math/libm-test-issignaling.inc b/math/libm-test-issignaling.inc
> index a2bdcef265..80060dcb75 100644
> --- a/math/libm-test-issignaling.inc
> +++ b/math/libm-test-issignaling.inc
> @@ -39,10 +39,24 @@ static const struct test_f_i_data issignaling_test_data[] =
>      TEST_f_b (issignaling, -snan_value_MACRO, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
>    };
>  
> +#if HANDLE_PSEUDO_NUMBERS
> +static const struct test_f_i_data_u issignaling_test_data_u[] =
> +  {
> +    TEST_f_b (issignaling, pseudo_zero, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (issignaling, pseudo_inf, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (issignaling, pseudo_qnan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (issignaling, pseudo_snan, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +    TEST_f_b (issignaling, pseudo_unnormal, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
> +  };
> +#endif
> +
>  static void
>  issignaling_test (void)
>  {
>    ALL_RM_TEST (issignaling, 1, issignaling_test_data, RUN_TEST_LOOP_f_b_tg, END);
> +#if HANDLE_PSEUDO_NUMBERS
> +  ALL_RM_TEST (issignaling, 1, issignaling_test_data_u, RUN_TEST_LOOP_f_b_tg_u, END);
> +#endif
>  }
>  
>  static void
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [COMMITTED] x86 long double: Consider pseudo numbers as signaling
  2020-12-28 16:57   ` Adhemerval Zanella
@ 2020-12-30  5:31     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-30  5:31 UTC (permalink / raw)
  To: libc-alpha

> Afaik, there is no need to __attribute__ ((unused)) on arguments for
> static inline functions.

You're right, this is what I finally committed.

Thanks,
Siddhesh

Add support to treat pseudo-numbers specially and implement x86
version to consider all of them as signaling.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
 sysdeps/generic/nan-pseudo-number.h      | 31 ++++++++++++++++++++++++
 sysdeps/ieee754/ldbl-96/s_issignalingl.c | 11 ++++++---
 sysdeps/x86/fpu/nan-pseudo-number.h      | 30 +++++++++++++++++++++++
 3 files changed, 69 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/generic/nan-pseudo-number.h
 create mode 100644 sysdeps/x86/fpu/nan-pseudo-number.h

diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/generic/nan-pseudo-number.h
new file mode 100644
index 0000000000..b39e347402
--- /dev/null
+++ b/sysdeps/generic/nan-pseudo-number.h
@@ -0,0 +1,31 @@
+/* Pseudo-normal number handling.  Generic version.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef NAN_PSEUDO_NUMBER_H
+#define NAN_PSEUDO_NUMBER_H	1
+
+/* Set this macro and override the definition of IS_PSEUDO_SIGNALING if pseudo
+   numbers need special handling.  */
+#define HANDLE_PSEUDO_NUMBERS 0
+static inline int
+is_pseudo_signaling (uint32_t exi, uint32_t hxi)
+{
+  return 0;
+}
+
+#endif /* nan-pseudo-number.h */
diff --git a/sysdeps/ieee754/ldbl-96/s_issignalingl.c b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
index ec542ad468..37e05aa259 100644
--- a/sysdeps/ieee754/ldbl-96/s_issignalingl.c
+++ b/sysdeps/ieee754/ldbl-96/s_issignalingl.c
@@ -19,12 +19,19 @@
 #include <math.h>
 #include <math_private.h>
 #include <nan-high-order-bit.h>
+#include <nan-pseudo-number.h>
 
 int
 __issignalingl (long double x)
 {
   uint32_t exi, hxi, lxi;
   GET_LDOUBLE_WORDS (exi, hxi, lxi, x);
+
+  /* By default we do not recognize a pseudo NaN as sNaN.  However on 80387 and
+     later all pseudo numbers including pseudo NaNs result in a signal and are
+     hence recognized as signaling.  */
+  int ret = is_pseudo_signaling (exi, hxi);
+
 #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
 # error not implemented
 #else
@@ -34,11 +41,9 @@ __issignalingl (long double x)
   hxi ^= 0x40000000;
   /* If lxi != 0, then set any suitable bit of the significand in hxi.  */
   hxi |= (lxi | -lxi) >> 31;
-  /* We do not recognize a pseudo NaN as sNaN; they're invalid on 80387 and
-     later.  */
   /* We have to compare for greater (instead of greater or equal), because x's
      significand being all-zero designates infinity not NaN.  */
-  return ((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000);
+  return ret || (((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000));
 #endif
 }
 libm_hidden_def (__issignalingl)
diff --git a/sysdeps/x86/fpu/nan-pseudo-number.h b/sysdeps/x86/fpu/nan-pseudo-number.h
new file mode 100644
index 0000000000..ea43b175a1
--- /dev/null
+++ b/sysdeps/x86/fpu/nan-pseudo-number.h
@@ -0,0 +1,30 @@
+/* Pseudo-normal number handling.  x86 version.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef NAN_PSEUDO_NUMBER_H
+#define NAN_PSEUDO_NUMBER_H	1
+
+#define HANDLE_PSEUDO_NUMBERS 1
+/* Pseudo numbers on x86 are always signaling.  */
+static inline int
+is_pseudo_signaling (uint32_t exi, uint32_t hxi)
+{
+  return ((exi & 0x7fff) && ((hxi & 0x80000000) == 0));
+}
+
+#endif /* nan-pseudo-number.h */
-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling
  2020-12-24  2:45 ` [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
  2020-12-28 16:57   ` Adhemerval Zanella
@ 2020-12-31 22:58   ` Joseph Myers
  2020-12-31 23:23     ` Andreas Schwab
  2021-01-04  9:30     ` [COMMITTED] Move generic nan-pseudo-number.h to ldbl-96 Siddhesh Poyarekar
  1 sibling, 2 replies; 10+ messages in thread
From: Joseph Myers @ 2020-12-31 22:58 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha, fweimer

On Thu, 24 Dec 2020, Siddhesh Poyarekar via Libc-alpha wrote:

> diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/generic/nan-pseudo-number.h

I don't think this belongs in sysdeps/generic/.  The "pseudo-number" 
concept is specific to the ldbl-96 format; a "generic" header is really 
something specific to ldbl-96 and so should go in sysdeps/ieee754/ldbl-96/ 
instead.  (x86 and m68k have different rules regarding what encodings are 
valid.  ia64 manuals seem to suggest that only a subset of the encodings 
that are invalid on x86 are also invalid on ia64 but I don't have access 
to hardware to test.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers
  2020-12-24  2:45 ` [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers Siddhesh Poyarekar
  2020-12-28 17:04   ` Adhemerval Zanella
@ 2020-12-31 23:09   ` Joseph Myers
  1 sibling, 0 replies; 10+ messages in thread
From: Joseph Myers @ 2020-12-31 23:09 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha, fweimer

On Thu, 24 Dec 2020, Siddhesh Poyarekar via Libc-alpha wrote:

> Add some tests for fpclassify, isnan, isinf and issignaling.

This looks like these tests get duplicated for every floating-point type 
for which they are run.  They should only be run for long double and 
_Float64x; when the libm tests are run for other floating-point types 
(choices of FLOAT), these new tests should be compiled out.

Note that "f" in the test macro names means FLOAT, but these tests seem 
always to test long double, indpendent of the choice of FLOAT, not FLOAT.  
(The second argument of nexttoward is the only case where it's *correct* 
for a math/ test to use long double independent of FLOAT.)

Properly testing _Float64x (i.e. with that as the argument type to the 
macro, not long double, when FLOAT is _Float64x) may need further changes; 
either not using the math_ldbl.h unions but a local union with FLOAT, or 
casting the argument to type FLOAT.

> +/* For pseudo-normal number tests.  */
> +#if HANDLE_PSEUDO_NUMBERS
> +# include <math_ldbl.h>
> +#define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }}
> +#define pseudo_zero { .parts = { 0x00000000, 0x00000000, 0x0100 }}
> +#define pseudo_qnan { .parts = { 0x00000001, 0x00000000, 0x7fff }}
> +#define pseudo_snan { .parts = { 0x00000001, 0x40000000, 0x7fff }}
> +#define pseudo_unnormal { .parts = { 0x00000001, 0x40000000, 0x0100 }}

I think the right condition here (and everywhere in this patch) is 
TEST_COND_intel96: a condition on the format for which the tests are being 
run rather than on how glibc is built.  The tests are both specific to 
rules for that format about which encodings are valid (the high bit of the 
significand is unspecified for NaNs and infinities for m68k), and, in the 
form in which they're written here, also specific to little-endian, since 
you're relying on the ordering of initializer elements rather than using 
designated initializers, so wouldn't work on m68k for that reason as well.

If you need to avoid these tests for ia64 because of different rules on 
such encodings for ia64, some other condition might then be used *inside* 
a TEST_COND_intel96 condition.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling
  2020-12-31 22:58   ` [PATCH v3 1/2] " Joseph Myers
@ 2020-12-31 23:23     ` Andreas Schwab
  2021-01-04  9:30     ` [COMMITTED] Move generic nan-pseudo-number.h to ldbl-96 Siddhesh Poyarekar
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2020-12-31 23:23 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Siddhesh Poyarekar, fweimer, libc-alpha

On Dez 31 2020, Joseph Myers wrote:

> On Thu, 24 Dec 2020, Siddhesh Poyarekar via Libc-alpha wrote:
>
>> diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/generic/nan-pseudo-number.h
>
> I don't think this belongs in sysdeps/generic/.  The "pseudo-number" 
> concept is specific to the ldbl-96 format; a "generic" header is really 
> something specific to ldbl-96 and so should go in sysdeps/ieee754/ldbl-96/ 
> instead.  (x86 and m68k have different rules regarding what encodings are 
> valid.

m68k doesn't have the concept of pseudo-nan and pseudo-inf, as it treats
the explicit integer bit in those formats as don't-care.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [COMMITTED] Move generic nan-pseudo-number.h to ldbl-96
  2020-12-31 22:58   ` [PATCH v3 1/2] " Joseph Myers
  2020-12-31 23:23     ` Andreas Schwab
@ 2021-01-04  9:30     ` Siddhesh Poyarekar
  1 sibling, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2021-01-04  9:30 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph

> I don't think this belongs in sysdeps/generic/.  The "pseudo-number"
> concept is specific to the ldbl-96 format; a "generic" header is really
> something specific to ldbl-96 and so should go in sysdeps/ieee754/ldbl-96/

Done with this commit.

> instead.  (x86 and m68k have different rules regarding what encodings are
> valid.  ia64 manuals seem to suggest that only a subset of the encodings
> that are invalid on x86 are also invalid on ia64 but I don't have access
> to hardware to test.)

I retained old behaviour on these platforms with the assumption that
architecture maintainers will do what is right.  It already does the
right thing for m68k AFAICT, which is to ignore the significand MSB.

Siddhesh

-----------

The concept of pseudo number formats only exists in the realm of the
96 bit long double format.
---
 sysdeps/{generic => ieee754/ldbl-96}/nan-pseudo-number.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename sysdeps/{generic => ieee754/ldbl-96}/nan-pseudo-number.h (100%)

diff --git a/sysdeps/generic/nan-pseudo-number.h b/sysdeps/ieee754/ldbl-96/nan-pseudo-number.h
similarity index 100%
rename from sysdeps/generic/nan-pseudo-number.h
rename to sysdeps/ieee754/ldbl-96/nan-pseudo-number.h
-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-01-04  9:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24  2:45 [PATCH v3 0/2] x86 pseudo-normal numbers Siddhesh Poyarekar
2020-12-24  2:45 ` [PATCH v3 1/2] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
2020-12-28 16:57   ` Adhemerval Zanella
2020-12-30  5:31     ` [COMMITTED] " Siddhesh Poyarekar
2020-12-31 22:58   ` [PATCH v3 1/2] " Joseph Myers
2020-12-31 23:23     ` Andreas Schwab
2021-01-04  9:30     ` [COMMITTED] Move generic nan-pseudo-number.h to ldbl-96 Siddhesh Poyarekar
2020-12-24  2:45 ` [PATCH v3 2/2] x86 long double: Add tests for pseudo normal numbers Siddhesh Poyarekar
2020-12-28 17:04   ` Adhemerval Zanella
2020-12-31 23:09   ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).