diff options
author | Joseph Myers <joseph@codesourcery.com> | 2018-02-09 21:55:48 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2018-02-09 21:55:48 +0000 |
commit | 8e554659ad7722ff1d09c6fa68d7df8e75530dc8 (patch) | |
tree | f6bd1fc34df54e6b015bc9defbc3e61b4ea377fb /math/libm-test-driver.c | |
parent | 63716ab270df6846233e82c8b7ef494be90b2c45 (diff) | |
download | glibc-8e554659ad7722ff1d09c6fa68d7df8e75530dc8.zip glibc-8e554659ad7722ff1d09c6fa68d7df8e75530dc8.tar.gz glibc-8e554659ad7722ff1d09c6fa68d7df8e75530dc8.tar.bz2 |
Add test infrastructure for narrowing libm functions.
This patch continues preparations for adding TS 18661-1 narrowing libm
functions by adding the required testsuite infrastructure to test such
functions through the libm-test infrastructure.
That infrastructure is based around testing for a single type, FLOAT.
For the narrowing functions, FLOAT, the "main" type for testing, is
the function return type; the argument type is ARG_FLOAT. This is
consistent with how the code built once for each type,
libm-test-support.c, depends on FLOAT for such things as calculating
ulps errors in results but can already handle different argument types
(pointers, integers, long double for nexttoward).
Makefile machinery is added to handle building tests for all pairs of
types for which there are narrowing functions (as with non-narrowing
functions, aliases are tested just the same as the functions they
alias). gen-auto-libm-tests gains a --narrow option for building
outputs for narrowing functions (so narrowing sqrt and fma will share
the same inputs as non-narrowing, but gen-auto-libm-tests will be run
with and without that option to generate different output files). In
the narrowing case, the auto-libm-test-out-narrow-* files include
annotations for each test about what properties ARG_FLOAT must have to
be able to represent all the inputs for that test; those annotations
result in calls to the TEST_COND_arg_fmt macro.
gen-libm-test.pl has some minor updates to handle narrowing tests (for
example, arguments in such tests must be surrounded by ARG_LIT calls
instead of LIT calls). Various new macros are added to the C test
support code (for example, sNaN initializers need to be properly
typed, so arg_snan_value is added; other such arg_* macros are added
as it seems cleanest to do so, though some are not strictly required).
Special-casing of the ibm128 format to allow for its limitations is
adjusted to handle it as the argument format as well as as the result
format; thus, the tests of the new functions allow nonzero ulps only
in the case where ibm128 is the argument format, as otherwise the
functions correspond to fully-defined IEEE operations. The ulps in
question appear as e.g. 'Function: "add_ldouble"' in libm-test-ulps
(with 1ulp errors then listed for double and float for that function
in powerpc); no support is added to generate corresponding faddl /
daddl ulps listings in the ulps table in the manual.
For the previous patch, I noted the need to avoid spurious macro
expansions of identifiers such as "add". A test test-narrow-macros.c
is added to verify such macro expansions are successfully avoided, and
there is also a -mlong-double-64 version of that test for ldbl-opt.
This test is set up to cover the full set of relevant identifiers from
the start rather than adding functions one at a time as each function
group is added.
Tested for x86_64 (this patch in isolation, as well as testing for
various configurations in conjunction with the actual addition of
"add" functions).
* math/Makefile (test-type-pairs): New variable.
(test-type-pairs-f64xf128-yes): Likewise.
(tests): Add test-narrow-macros.
(libm-test-funcs-narrow): New variable.
(libm-test-c-narrow): Likewise.
(generated): Add $(libm-test-c-narrow).
(libm-tests-base-narrow): New variable.
(libm-tests-narrow): Likewise.
(libm-tests): Add $(libm-tests-narrow).
(libm-tests-for-type): Handle $(libm-tests-narrow).
(libm-test-c-narrow-obj): New variable.
($(libm-test-c-narrow-obj)): New rule.
($(foreach t,$(libm-tests-narrow),$(objpfx)$(t).c)): Likewise.
($(foreach f,$(libm-test-funcs-narrow),$(objpfx)$(o)-$(f).o)): Use
$(o-iterator) to set dependencies and CFLAGS.
* math/gen-auto-libm-tests.c: Document use for narrowing
functions.
(output_for_one_input_case): Take argument NARROW.
(generate_output): Likewise. Update call to
output_for_one_input_case.
(main): Take --narrow option. Update call to generate_output.
* math/gen-libm-test.pl (_apply_lit): Take macro name as argument.
(apply_lit): Update call to _apply_lit.
(apply_arglit): New function.
(parse_args): Handle "a" arguments.
(parse_auto_input): Handle format names using ":".
* math/README.libm-test: Document "a" parameter type.
* math/libm-test-support.h (ARG_TYPE_MIN): New macro.
(ARG_TYPE_TRUE_MIN): Likewise.
(ARG_TYPE_MAX): Likwise.
(ARG_MIN_EXP): Likewise.
(ARG_MAX_EXP): Likewise.
(ARG_MANT_DIG): Likewise.
(TEST_COND_arg_ibm128): Likewise.
(TEST_COND_ibm128_libgcc): Define conditional on [ARG_FLOAT].
(TEST_COND_arg_fmt): New macro.
(init_max_error): Update prototype.
* math/libm-test-support.c (test_ibm128): New variable.
(init_max_error): Take argument testing_ibm128 and set test_ibm128
instead of using [TEST_COND_ibm128] conditional.
(test_exceptions): Use test_ibm128 instead of TEST_COND_ibm128.
* math/libm-test-driver.c (STR_ARG_FLOAT): New macro.
[TEST_NARROW] (TEST_MSG): New definition.
(arg_plus_zero): New macro.
(arg_minus_zero): Likewise.
(arg_plus_infty): Likewise.
(arg_minus_infty): Likewise.
(arg_qnan_value_pl): Likewise.
(arg_qnan_value): Likewise.
(arg_snan_value_pl): Likewise.
(arg_snan_value): Likewise.
(arg_max_value): Likewise.
(arg_min_value): Likewise.
(arg_min_subnorm_value): Likewise.
[ARG_FLOAT] (struct test_aa_f_data): New struct type.
(RUN_TEST_LOOP_aa_f): New macro.
(TEST_SUFF): New macro.
(TEST_SUFF_STR): Likewise.
[!TEST_MATHVEC] (VEC_SUFF): Don't define.
(TEST_COND_any_ibm128): New macro.
(START): Use TEST_SUFF and TEST_SUFF_STR in initializer for
this_func. Update call to init_max_error.
* math/test-double.h (FUNC_NARROW_PREFIX): New macro.
* math/test-float.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-float128.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-float32.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-float32x.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-float64.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-float64x.h (FUNC_NARROW_PREFIX): Likewise.
* math/test-math-scalar.h (TEST_NARROW): Likewise.
* math/test-math-vector.h (TEST_NARROW): Likewise.
* math/test-arg-double.h: New file.
* math/test-arg-float128.h: Likewise.
* math/test-arg-float32x.h: Likewise.
* math/test-arg-float64.h: Likewise.
* math/test-arg-float64x.h: Likewise.
* math/test-arg-ldouble.h: Likewise.
* math/test-math-narrow.h: Likewise.
* math/test-narrow-macros.c: Likewise.
* sysdeps/ieee754/ldbl-opt/test-narrow-macros-ldbl-64.c: Likewise.
* sysdeps/ieee754/ldbl-opt/Makefile (tests): Add
test-narrow-macros-ldbl-64.
(CFLAGS-test-narrow-macros-ldbl-64.c): New variable.
Diffstat (limited to 'math/libm-test-driver.c')
-rw-r--r-- | math/libm-test-driver.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/math/libm-test-driver.c b/math/libm-test-driver.c index b7c0343..3713e70 100644 --- a/math/libm-test-driver.c +++ b/math/libm-test-driver.c @@ -30,6 +30,7 @@ const int flag_test_mathvec = TEST_MATHVEC; #define STRX(x) #x #define STR(x) STRX (x) #define STR_FLOAT STR (FLOAT) +#define STR_ARG_FLOAT STR (ARG_FLOAT) #define STR_VEC_LEN STR (VEC_LEN) /* Informal description of the functions being tested. */ @@ -39,6 +40,8 @@ const int flag_test_mathvec = TEST_MATHVEC; # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n" #elif TEST_FINITE # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\n" +#elif TEST_NARROW +# define TEST_MSG "testing " STR_FLOAT " (argument " STR_ARG_FLOAT ")\n" #else # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n" #endif @@ -108,6 +111,18 @@ const char qtype_str[] = TYPE_STR; #define min_value TYPE_MIN #define min_subnorm_value TYPE_TRUE_MIN +#define arg_plus_zero ARG_LIT (0.0) +#define arg_minus_zero ARG_LIT (-0.0) +#define arg_plus_infty ARG_FUNC (__builtin_inf) () +#define arg_minus_infty -(ARG_FUNC (__builtin_inf) ()) +#define arg_qnan_value_pl(S) ARG_FUNC (__builtin_nan) (S) +#define arg_qnan_value arg_qnan_value_pl ("") +#define arg_snan_value_pl(S) ARG_FUNC (__builtin_nans) (S) +#define arg_snan_value arg_snan_value_pl ("") +#define arg_max_value ARG_TYPE_MAX +#define arg_min_value ARG_TYPE_MIN +#define arg_min_subnorm_value ARG_TYPE_TRUE_MIN + /* For nexttoward tests. */ #define snan_value_ld __builtin_nansl ("") @@ -147,6 +162,18 @@ struct test_fj_f_data int exceptions; } rd, rn, rz, ru; }; +#ifdef ARG_FLOAT +struct test_aa_f_data +{ + const char *arg_str; + ARG_FLOAT arg1, arg2; + struct + { + FLOAT expected; + int exceptions; + } rd, rn, rz, ru; +}; +#endif struct test_fi_f_data { const char *arg_str; @@ -467,6 +494,7 @@ struct test_Ff_b1_data #define RUN_TEST_ff_f RUN_TEST_2_f #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f +#define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f #define RUN_TEST_fi_f RUN_TEST_2_f #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f #define RUN_TEST_fl_f RUN_TEST_2_f @@ -945,18 +973,32 @@ struct test_Ff_b1_data (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \ ROUND_RESTORE_ ## ROUNDING_MODE -#if !TEST_MATHVEC -# define VEC_SUFF +#if TEST_MATHVEC +# define TEST_SUFF VEC_SUFF +# define TEST_SUFF_STR +#elif TEST_NARROW +# define TEST_SUFF +# define TEST_SUFF_STR "_" ARG_TYPE_STR +#else +# define TEST_SUFF +# define TEST_SUFF_STR #endif #define STR_CONCAT(a, b, c) __STRING (a##b##c) #define STR_CON3(a, b, c) STR_CONCAT (a, b, c) +#if TEST_NARROW +# define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128) +#else +# define TEST_COND_any_ibm128 TEST_COND_ibm128 +#endif + /* Start and end the tests for a given function. */ #define START(FUN, SUFF, EXACT) \ CHECK_ARCH_EXT; \ - const char *this_func = STR_CON3 (FUN, SUFF, VEC_SUFF); \ - init_max_error (this_func, EXACT) + const char *this_func \ + = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \ + init_max_error (this_func, EXACT, TEST_COND_any_ibm128) #define END \ print_max_error (this_func) #define END_COMPLEX \ |