[PATCH 5/5] x86 long double: Add tests for pseudo normal numbers

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Dec 23 17:44:00 GMT 2020



On 23/12/2020 07:20, Siddhesh Poyarekar wrote:
> On 12/23/20 7:28 AM, Siddhesh Poyarekar via Libc-alpha wrote:
>> On 12/23/20 3:18 AM, Adhemerval Zanella via Libc-alpha wrote:
>>>
>>>
>>> On 15/12/2020 11:13, Siddhesh Poyarekar via Libc-alpha wrote:
>>>> Add some tests for fpclassify, isnanl, isinfl and issignaling.
>>>> ---
>>>>   sysdeps/x86/fpu/Makefile        |   3 +-
>>>>   sysdeps/x86/fpu/test-unnormal.c | 196 ++++++++++++++++++++++++++++++++
>>>>   2 files changed, 198 insertions(+), 1 deletion(-)
>>>>   create mode 100644 sysdeps/x86/fpu/test-unnormal.c
>>>>
>>>> diff --git a/sysdeps/x86/fpu/Makefile b/sysdeps/x86/fpu/Makefile
>>>> index 600e42c3db..e77de56d14 100644
>>>> --- a/sysdeps/x86/fpu/Makefile
>>>> +++ b/sysdeps/x86/fpu/Makefile
>>>> @@ -4,11 +4,12 @@ CPPFLAGS += -I../soft-fp
>>>>   libm-support += powl_helper
>>>>   tests += test-fenv-sse test-fenv-clear-sse test-fenv-x87 test-fenv-sse-2 \
>>>> -     test-flt-eval-method-387 test-flt-eval-method-sse
>>>> +     test-flt-eval-method-387 test-flt-eval-method-sse test-unnormal
>>>>   CFLAGS-test-fenv-sse.c += -msse2 -mfpmath=sse
>>>>   CFLAGS-test-fenv-clear-sse.c += -msse2 -mfpmath=sse
>>>>   CFLAGS-test-fenv-sse-2.c += -msse2 -mfpmath=sse
>>>>   CFLAGS-test-flt-eval-method-387.c += -fexcess-precision=standard -mfpmath=387
>>>>   CFLAGS-test-flt-eval-method-sse.c += -fexcess-precision=standard -msse2 \
>>>>                        -mfpmath=sse
>>>> +CFLAGS-test-unnormal.c += -fsignaling-nans -std=c2x
>>>>   endif
>>>
>>> A possibility is to hookup this tests on
>>> math/libm-test-{fpclassify,isnan,isinf,issignaling}.inc using the new define
>>> I suggested on the 4/5 part [1] so you can also check if no exceptions are being
>>> generated and errno is not set.
>>>
>>> It increases the tests coverage and avoid a arch-specific tests.
>>>
>>> [1] https://sourceware.org/pipermail/libc-alpha/2020-December/121004.html
>>
>> OK, it will need changes to the driver.
>>
> 
> I took a look at this and it looks like it will need a significant amount of changes to the driver and test generation scripts, since these numbers are not generated by the CPU.  Would it be OK if I defer this to later if we ever feel the need to add tests beyond test-unnormal?
> 
> Siddhesh

I don't have a strong opinion, although below you can check it does not
really require too much tinkering to add a new tests for pseudo-normal zero. 
The idea is to add the generic constants pseudo_xxx, define a new list using 
a different struct, and issue ALL_RM_TESTS with RUN_TEST_LOOP_f_i_tg_u.

It does add a *lot* more coverage (errno, rounding modes, exceptions).

---

diff --git a/math/libm-test-driver.c b/math/libm-test-driver.c
index 11b541b2e7..ddfd16cf91 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,11 @@ const char qtype_str[] = TYPE_STR;
 /* For nexttoward tests.  */
 #define snan_value_ld	__builtin_nansl ("")
 
+#if HANDLE_PSEUDO_NUMBERS
+# include <math_ldbl.h>
+#define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }}
+#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 +322,18 @@ struct test_f_i_data
     int exceptions;
   } rd, rn, rz, ru;
 };
+#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 +850,13 @@ 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_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..0e2e00a09d 100644
--- a/math/libm-test-fpclassify.inc
+++ b/math/libm-test-fpclassify.inc
@@ -37,10 +37,20 @@ 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_inf, 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


More information about the Libc-alpha mailing list