41c67149b9
TS 18661-1 defines roundeven functions that round a floating-point number to the nearest integer, in that floating-point type, with ties rounding to even (whereas the round functions round ties away from zero). As with other such functions, they raise no exceptions apart from "invalid" for signaling NaNs. There was a previous user request for this functionality in glibc in <https://sourceware.org/ml/libc-help/2015-02/msg00005.html>. This patch implements these functions for glibc. The implementations use integer bit-manipulation (or roundeven on the high and low parts, in the IBM long double case). It's possible that there may be faster approaches on some architectures (in particular, on AArch64 the frintn instruction should do exactly what's required); I'll leave it to architecture maintainers or others interested to implement such architecture-specific versions if desired. (Where architectures have instructions to round to nearest integer in the current rounding mode, implementations saving and restoring the rounding mode - and dealing with exceptions if those instructions generate "inexact" - are also possible, though their performance depends on the cost of manipulating exceptions / rounding mode state.) Tested for x86_64, x86, mips64 and powerpc. * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (roundeven): New declaration. * math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (roundeven): New macro. * math/Versions (roundeven): New libm symbol at version GLIBC_2.25. (roundevenf): Likewise. (roundevenl): Likewise. * math/Makefile (libm-calls): Add s_roundevenF. * math/libm-test.inc (roundeven_test_data): New array. (roundeven_test): New function. (main): Call roundeven_test. * math/test-tgmath.c (NCALLS): Increase to 134. (F(compile_test)): Call roundeven. (F(roundeven)): New function. * manual/arith.texi (Rounding Functions): Document roundeven, roundevenf and roundevenl. * manual/libm-err-tab.pl (@all_functions): Add roundeven. * include/math.h (roundeven): Use libm_hidden_proto. * sysdeps/ieee754/dbl-64/s_roundeven.c: New file. * sysdeps/ieee754/dbl-64/wordsize-64/s_roundeven.c: Likewise. * sysdeps/ieee754/flt-32/s_roundevenf.c: Likewise. * sysdeps/ieee754/ldbl-128/s_roundevenl.c: Likewise. * sysdeps/ieee754/ldbl-128ibm/s_roundevenl.c: Likewise. * sysdeps/ieee754/ldbl-96/s_roundevenl.c: Likewise. * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add roundeven. (CFLAGS-nldbl-roundeven.c): New variable. * sysdeps/ieee754/ldbl-opt/nldbl-roundeven.c: New file. * sysdeps/nacl/libm.abilist: Update. * sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise. |
||
---|---|---|
.. | ||
bits | ||
machine | ||
atest-exp2.c | ||
atest-exp.c | ||
atest-sincos.c | ||
auto-libm-test-in | ||
auto-libm-test-out | ||
basic-test.c | ||
bug-nextafter.c | ||
bug-nexttoward.c | ||
bug-tgmath1.c | ||
cabs_template.c | ||
carg_template.c | ||
cimag_template.c | ||
complex.h | ||
conj_template.c | ||
creal_template.c | ||
divtc3.c | ||
e_acoshl.c | ||
e_acosl.c | ||
e_asinl.c | ||
e_atan2l.c | ||
e_atanhl.c | ||
e_coshl.c | ||
e_exp2l.c | ||
e_exp10.c | ||
e_exp10f.c | ||
e_exp10l.c | ||
e_expl.c | ||
e_fmodl.c | ||
e_gammal_r.c | ||
e_hypotl.c | ||
e_j0l.c | ||
e_j1l.c | ||
e_jnl.c | ||
e_lgammal_r.c | ||
e_log2l.c | ||
e_log10l.c | ||
e_logl.c | ||
e_powl.c | ||
e_rem_pio2l.c | ||
e_scalb.c | ||
e_scalbf.c | ||
e_scalbl.c | ||
e_sinhl.c | ||
e_sqrtl.c | ||
fclrexcpt.c | ||
fedisblxcpt.c | ||
feenablxcpt.c | ||
fegetenv.c | ||
fegetexcept.c | ||
fegetmode.c | ||
fegetround.c | ||
feholdexcpt.c | ||
fenv.h | ||
fesetenv.c | ||
fesetexcept.c | ||
fesetmode.c | ||
fesetround.c | ||
fetestexceptflag.c | ||
feupdateenv.c | ||
fgetexcptflg.c | ||
fpu_control.c | ||
fraiseexcpt.c | ||
fsetexcptflg.c | ||
ftestexcept.c | ||
gen-auto-libm-tests.c | ||
gen-libm-have-vector-test.sh | ||
gen-libm-test.pl | ||
ieee-math.c | ||
k_casinh_template.c | ||
k_cosl.c | ||
k_sincosl.c | ||
k_sinl.c | ||
k_tanl.c | ||
lgamma-compat.h | ||
libm-test.inc | ||
Makefile | ||
math.h | ||
mul_split.h | ||
mul_splitl.h | ||
multc3.c | ||
README.libm-test | ||
s_asinhl.c | ||
s_atanl.c | ||
s_cacos_template.c | ||
s_cacosh_template.c | ||
s_canonicalize_template.c | ||
s_casin_template.c | ||
s_casinh_template.c | ||
s_catan_template.c | ||
s_catanh_template.c | ||
s_cbrtl.c | ||
s_ccos_template.c | ||
s_ccosh_template.c | ||
s_cexp_template.c | ||
s_clog10_template.c | ||
s_clog_template.c | ||
s_cpow_template.c | ||
s_cproj_template.c | ||
s_csin_template.c | ||
s_csinh_template.c | ||
s_csqrt_template.c | ||
s_ctan_template.c | ||
s_ctanh_template.c | ||
s_erfl.c | ||
s_expm1l.c | ||
s_fdim_template.c | ||
s_fma.c | ||
s_fmaf.c | ||
s_fmal.c | ||
s_fmax_template.c | ||
s_fmaxmag_template.c | ||
s_fmin_template.c | ||
s_fminmag_template.c | ||
s_iscanonicall.c | ||
s_iseqsig_template.c | ||
s_ldexp_template.c | ||
s_log1pl.c | ||
s_nan_template.c | ||
s_nextafter.c | ||
s_nextdown_template.c | ||
s_nexttowardf.c | ||
s_nexttowardl.c | ||
s_significand.c | ||
s_significandf.c | ||
s_significandl.c | ||
s_tanhl.c | ||
setfpucw.c | ||
t_sincosl.c | ||
test-double-finite.c | ||
test-double-vlen2.h | ||
test-double-vlen4.h | ||
test-double-vlen8.h | ||
test-double.c | ||
test-double.h | ||
test-fe-snans-always-signal.c | ||
test-femode-traps.c | ||
test-femode.c | ||
test-fenv-clear-main.c | ||
test-fenv-clear.c | ||
test-fenv-preserve.c | ||
test-fenv-return.c | ||
test-fenv-tls.c | ||
test-fenv.c | ||
test-fenvinline.c | ||
test-fesetexcept-traps.c | ||
test-fesetexcept.c | ||
test-fetestexceptflag.c | ||
test-fexcept-traps.c | ||
test-fexcept.c | ||
test-float-finite.c | ||
test-float-vlen4.h | ||
test-float-vlen8.h | ||
test-float-vlen16.h | ||
test-float.c | ||
test-float.h | ||
test-flt-eval-method.c | ||
test-fp-ilogb-constants.c | ||
test-fp-llogb-constants.c | ||
test-fpucw-ieee-static.c | ||
test-fpucw-ieee.c | ||
test-fpucw-static.c | ||
test-fpucw.c | ||
test-idouble.c | ||
test-ifloat.c | ||
test-ildouble.c | ||
test-iseqsig-excess-precision.c | ||
test-iszero-excess-precision.c | ||
test-ldouble-finite.c | ||
test-ldouble.c | ||
test-ldouble.h | ||
test-math-errno.h | ||
test-math-finite.h | ||
test-math-inline.h | ||
test-math-isinff.cc | ||
test-math-iszero.cc | ||
test-math-no-finite.h | ||
test-math-no-inline.h | ||
test-math-scalar.h | ||
test-math-vector.h | ||
test-matherr.c | ||
test-misc.c | ||
test-nan-overflow.c | ||
test-nan-payload.c | ||
test-nearbyint-except-2.c | ||
test-nearbyint-except.c | ||
test-powl.c | ||
test-signgam-finite-c11.c | ||
test-signgam-finite-c99.c | ||
test-signgam-finite.c | ||
test-signgam-main.c | ||
test-signgam-uchar-init-static.c | ||
test-signgam-uchar-init.c | ||
test-signgam-uchar-static.c | ||
test-signgam-uchar.c | ||
test-signgam-uint-init-static.c | ||
test-signgam-uint-init.c | ||
test-signgam-uint-static.c | ||
test-signgam-uint.c | ||
test-signgam-ullong-init-static.c | ||
test-signgam-ullong-init.c | ||
test-signgam-ullong-static.c | ||
test-signgam-ullong.c | ||
test-snan.c | ||
test-tgmath2.c | ||
test-tgmath-int.c | ||
test-tgmath-ret.c | ||
test-tgmath.c | ||
tgmath.h | ||
tst-CMPLX2.c | ||
tst-CMPLX.c | ||
tst-definitions.c | ||
Versions | ||
w_acos.c | ||
w_acosf.c | ||
w_acosh.c | ||
w_acoshf.c | ||
w_acoshl.c | ||
w_acosl.c | ||
w_asin.c | ||
w_asinf.c | ||
w_asinl.c | ||
w_atan2.c | ||
w_atan2f.c | ||
w_atan2l.c | ||
w_atanh.c | ||
w_atanhf.c | ||
w_atanhl.c | ||
w_cosh.c | ||
w_coshf.c | ||
w_coshl.c | ||
w_exp2.c | ||
w_exp2f.c | ||
w_exp2l.c | ||
w_exp10.c | ||
w_exp10f.c | ||
w_exp10l.c | ||
w_expl.c | ||
w_fmod.c | ||
w_fmodf.c | ||
w_fmodl.c | ||
w_hypot.c | ||
w_hypotf.c | ||
w_hypotl.c | ||
w_ilogb_template.c | ||
w_j0.c | ||
w_j0f.c | ||
w_j0l.c | ||
w_j1.c | ||
w_j1f.c | ||
w_j1l.c | ||
w_jn.c | ||
w_jnf.c | ||
w_jnl.c | ||
w_lgamma_compat.c | ||
w_lgamma_compatf.c | ||
w_lgamma_compatl.c | ||
w_lgamma_main.c | ||
w_lgamma_r.c | ||
w_lgamma.c | ||
w_lgammaf_main.c | ||
w_lgammaf_r.c | ||
w_lgammaf.c | ||
w_lgammal_main.c | ||
w_lgammal_r.c | ||
w_lgammal.c | ||
w_llogb_template.c | ||
w_log1p_template.c | ||
w_log2.c | ||
w_log2f.c | ||
w_log2l.c | ||
w_log10.c | ||
w_log10f.c | ||
w_log10l.c | ||
w_log.c | ||
w_logf.c | ||
w_logl.c | ||
w_pow.c | ||
w_powf.c | ||
w_powl.c | ||
w_remainder.c | ||
w_remainderf.c | ||
w_remainderl.c | ||
w_scalb.c | ||
w_scalbf.c | ||
w_scalbl.c | ||
w_scalbln_template.c | ||
w_sinh.c | ||
w_sinhf.c | ||
w_sinhl.c | ||
w_sqrt.c | ||
w_sqrtf.c | ||
w_sqrtl.c | ||
w_tgamma.c | ||
w_tgammaf.c | ||
w_tgammal.c |
README for libm-test math test suite ==================================== The libm-test math test suite tests a number of function points of math functions in the GNU C library. The following sections contain a brief overview. Please note that the test drivers and the Perl script "gen-libm-test.pl" have some options. A full list of options is available with --help (for the test drivers) and -h for "gen-libm-test.pl". What is tested? =============== The tests just evaluate the functions at specified points and compare the results with precomputed values and the requirements of the ISO C99 standard. Besides testing the special values mandated by IEEE 754 (infinities, NaNs and minus zero), some more or less random values are tested. Files that are part of libm-test ================================ The main file is "libm-test.inc". It is independent of the target platform and the specific real floating type and format and contains placeholder test "templates" for math functions defined in libm. The file, along with a generated file named "auto-libm-test-out", is preprocessed by the Perl script "gen-libm-test.pl" to expand the templates and produce a set of test cases for each math function that are specific to the target platform but still independent of the real floating type. The results of the processing are "libm-test.c" and a file "libm-test-ulps.h" with platform specific deltas by which the actual math function results may deviate from the expected results and still be considered correct. The test drivers "test-double.c", "test-float.c", and "test-ldouble.c" test the normal double, float and long double implementation of libm. The test drivers with an 'i' in their name ("test-idouble.c", "test-ifloat.c", and "test-ildoubl.c") test the corresponding inline functions (where available - otherwise they also test the real functions in libm). Each driver selects the desired real floating type to exercise the math functions to test with (float, double, or long double) by defining a small set of macros just before including the generic "libm-test.c" file. Each driver also either defines or undefines the __NO_MATH_INLINES macro just before including "libm-test.c" to select either the real or inline functions, respectively. Each driver is compiled into a single executable test program with the corresponding name. As mentioned above, the "gen-libm-test.pl" script looks for a file named "libm-test-ulps" in the platform specific sysdep directory (or its fpu or nofpu subdirectory) and for each variant (real floating type and rounding mode) of every tested function reads from it the maximum difference expressed as Units of Least Precision (ULP) the actual result of the function may deviate from the expected result before it's considered incorrect. The "auto-libm-test-out" file contains sets of test cases to exercise, the conditions under which to exercise each, and the expected results. The file is generated by the "gen-auto-libm-tests" program from the "auto-libm-test-in" file. See the comments in gen-auto-libm-tests.c for details about the content and format of the -in and -out files. How can I generate "libm-test-ulps"? ==================================== To automatically generate a new "libm-test-ulps" run "make regen-ulps". This generates the file "math/NewUlps" in the build directory. The file contains the sorted results of all the tests. You can use the "NewUlps" file as the machine's updated "libm-test-ulps" file. Copy "NewUlps" to "libm-test-ulps" in the appropriate machine sysdep directory. Verify the changes, post your patch, and check it in after review. To manually generate a new "libm-test-ulps" file, first remove "ULPs" file in the current directory, then you can execute for example: ./testrun.sh math/test-double -u --ignore-max-ulp=yes This generates a file "ULPs" with all double ULPs in it, ignoring any previously calculated ULPs, and running with the newly built dynamic loader and math library (assumes you didn't install your build). Now generate the ULPs for all other formats, the tests will be appending the data to the "ULPs" file. As final step run "gen-libm-test.pl" with the file as input and ask to generate a pretty printed output in the file "NewUlps": gen-libm-test.pl -u ULPs -n Copy "NewUlps" to "libm-test-ulps" in the appropriate machine sysdep directory. Note that the test drivers have an option "-u" to output an unsorted list of all epsilons that the functions have. The output can be read in directly but it's better to pretty print it first. "gen-libm-test.pl" has an option to generate a pretty-printed and sorted new ULPs file from the output of the test drivers. Contents of libm-test-ulps ========================== Since libm-test-ulps can be generated automatically, just a few notes. The file contains lines for maximal errors of single functions, like: Function "yn": idouble: 6 The keywords are float, ifloat, double, idouble, ldouble and ildouble (the prefix i stands for inline). Adding tests to libm-test.inc ============================= The tests are evaluated by a set of special test macros. The macros start with "TEST_" followed by a specification the input values, an underscore and a specification of the output values. As an example, the test macro for a function with input of type FLOAT (FLOAT is either float, double, long double) and output of type FLOAT is "TEST_f_f". The macro's parameter are the name of the function, the input parameter, output parameter and optionally one exception parameter. The accepted parameter types are: - "f" for FLOAT - "b" for boolean - just tests if the output parameter evaluates to 0 or 1 (only for output). - "c" for complex. This parameter needs two values, first the real, then the imaginary part. - "i" for int. - "l" for long int. - "L" for long long int. - "F" for the address of a FLOAT (only as input parameter) - "I" for the address of an int (only as input parameter) How to read the test output =========================== Running each test on its own at the default level of verbosity will print on stdout a line describing the implementation of math functions exercised by the test (float, double, or long double), along with whether the inline set has been selected, regardless of whether or not any inline functions actually exist. This is then followed by the details of test failures (if any). The output concludes by a summary listing the number of test cases exercised and the number of test failures uncovered. For each test failure (and for each test case at higher levels of verbosity), the output contains the name of the function under test and its arguments or conditions that triggered the failure. Note that the name of the function in the output need not correspond exactly to the name of the math function actually invoked. For example, the output will refer to the "acos" function even if the actual function under test is acosf (for the float version) or acosl (for the long double version). Also note that the function arguments may be shown in either the decimal or the hexadecimal floating point format which may or may not correspond to the format used in the auto-libm-test-in file. Besides the name of the function, for each test failure the output contains the actual and expected results and the difference between the two, printed in both the decimal and hexadecimal floating point format, and the ULP and maximum ULP for the test case.