x86 long double: Add tests for pseudo normal numbers

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

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
Siddhesh Poyarekar 2020-12-24 08:14:20 +05:30
parent 7525c1c71d
commit 38a033ac85
5 changed files with 94 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "libm-test-support.h" #include "libm-test-support.h"
#include <math-tests-arch.h> #include <math-tests-arch.h>
#include <nan-pseudo-number.h>
/* Flags set by the including file. */ /* Flags set by the including file. */
const int flag_test_errno = TEST_ERRNO; const int flag_test_errno = TEST_ERRNO;
@ -122,6 +123,16 @@ const char qtype_str[] = TYPE_STR;
/* For nexttoward tests. */ /* For nexttoward tests. */
#define snan_value_ld __builtin_nansl ("") #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. */ /* Structures for each kind of test. */
/* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */ /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */
struct test_f_f_data struct test_f_f_data
@ -316,6 +327,19 @@ struct test_f_i_data
int exceptions; int exceptions;
} rd, rn, rz, ru; } 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 /* Used for RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
RUN_TEST_LOOP_ff_i_tg. */ RUN_TEST_LOOP_ff_i_tg. */
struct test_ff_i_data 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.expected, \
(ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \ (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
ROUND_RESTORE_ ## ROUNDING_MODE 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, \ #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
EXCEPTIONS) \ EXCEPTIONS) \
do \ do \

View File

@ -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), 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 static void
fpclassify_test (void) fpclassify_test (void)
{ {
ALL_RM_TEST (fpclassify, 1, fpclassify_test_data, RUN_TEST_LOOP_f_i_tg, END); 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 static void

View File

@ -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), 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 static void
isinf_test (void) isinf_test (void)
{ {
ALL_RM_TEST (isinf, 1, isinf_test_data, RUN_TEST_LOOP_f_b_tg, END); 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 static void

View File

@ -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), 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 static void
isnan_test (void) isnan_test (void)
{ {
ALL_RM_TEST (isnan, 1, isnan_test_data, RUN_TEST_LOOP_f_b_tg, END); 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 static void

View File

@ -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), 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 static void
issignaling_test (void) issignaling_test (void)
{ {
ALL_RM_TEST (issignaling, 1, issignaling_test_data, RUN_TEST_LOOP_f_b_tg, END); 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 static void