glibc/sysdeps/ieee754/ldbl-128ibm
Joseph Myers 41c67149b9 Add roundeven, roundevenf, roundevenl.
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.
2016-12-21 01:48:27 +00:00
..
bits Refactor some libm type-generic macros. 2016-11-10 21:41:56 +00:00
include/bits Add canonicalize, canonicalizef, canonicalizel. 2016-10-26 23:14:31 +00:00
e_acoshl.c Fix ldbl-128ibm acoshl inaccuracy (bug 18019). 2015-02-25 00:01:15 +00:00
e_acosl.c This patch renames all uses of __isinf*, __isnan*, __finite* and __signbit* to use standard C99 macros. This has no effect on generated code. 2015-06-03 15:41:36 +01:00
e_asinl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_atan2l.c PowerPC floating point little-endian [3 of 15] 2013-10-04 10:32:36 +09:30
e_atanhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_coshl.c Fix cosh spurious underflows from expm1 (bug 16354), inaccurate results near 0 (bug 17061). 2014-06-23 20:20:10 +00:00
e_exp10l.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
e_expl.c ldbl-128: Rename 'long double' to '_Float128' 2016-08-31 10:38:11 -05:00
e_fmodl.c Fix ldbl-128ibm fmodl handling of equal arguments with low part zero (bug 19602). 2016-02-18 22:54:07 +00:00
e_gammal_r.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
e_hypotl.c Fix hypot sNaN handling (bug 20940). 2016-12-07 01:16:36 +00:00
e_ilogbl.c Fix ldbl-128ibm ilogbl near powers of 2 (bug 18029). 2015-02-26 12:57:21 +00:00
e_j0l.c ldbl-128: Rename 'long double' to '_Float128' 2016-08-31 10:38:11 -05:00
e_j1l.c ldbl-128: Rename 'long double' to '_Float128' 2016-08-31 10:38:11 -05:00
e_jnl.c Fix j1, jn missing errno setting on underflow (bug 18611). 2015-10-23 21:37:33 +00:00
e_lgammal_r.c ldbl-128: Rename 'long double' to '_Float128' 2016-08-31 10:38:11 -05:00
e_log2l.c Convert 231 sysdeps function definitions to prototype style. 2015-10-19 12:04:33 +00:00
e_log10l.c Fix log10 (1) in round-downward mode (bug 16977). 2014-05-23 12:07:50 +00:00
e_logl.c Fix ldbl-128ibm logl inaccuracy near 1 (bug 19351). 2015-12-09 23:51:11 +00:00
e_powl.c Fix sysdeps/ieee754 pow handling of sNaN arguments (bug 20916). 2016-12-02 23:21:15 +00:00
e_rem_pio2l.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
e_remainderl.c Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677). 2016-03-08 00:27:21 +00:00
e_sinhl.c Fix ldbl-128ibm sinhl spurious overflows (bug 19350). 2015-12-09 22:37:08 +00:00
e_sqrtl.c Fix ldbl-128ibm sqrtl (sNaN) (bug 20153). 2016-05-26 22:58:36 +00:00
gamma_productl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
ieee754.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
k_cosl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
k_sincosl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
k_sinl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
k_tanl.c Remove GCC version conditionals on -Wmaybe-uninitialized pragmas. 2015-10-27 23:42:20 +00:00
ldbl2mpn.c Increase internal precision of ldbl-128ibm decimal printf [BZ #19853] 2016-03-31 12:14:33 -05:00
lgamma_negl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
lgamma_productl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
Makefile Add canonicalize, canonicalizef, canonicalizel. 2016-10-26 23:14:31 +00:00
math_ldbl.h Fix ldbl-128ibm floorl for non-default rounding modes (bug 17899). 2016-02-18 21:31:10 +00:00
mpn2ldbl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
printf_fphex.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_asinhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_atanl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_cbrtl.c ldbl-128: Rename 'long double' to '_Float128' 2016-08-31 10:38:11 -05:00
s_ceill.c Fix ldbl-128ibm ceill, rintl etc. for sNaN arguments (bug 20156). 2016-05-27 13:59:24 +00:00
s_copysignl.c Remove IS_IN_libm 2014-11-24 11:41:47 +05:30
s_cosl.c PowerPC floating point little-endian [2 of 15] 2013-10-04 10:32:19 +09:30
s_erfl.c Remove unused variables 2016-01-27 09:30:16 +01:00
s_expm1l.c Fix ldbl-128ibm expm1l (sNaN) (bug 20233). 2016-06-09 17:24:52 +00:00
s_fabsl.c PowerPC floating point little-endian [2 of 15] 2013-10-04 10:32:19 +09:30
s_finitel.c Reduce number of constants in __finite* (bug 15384). 2015-09-17 16:47:14 +00:00
s_floorl.c Fix ldbl-128ibm ceill, rintl etc. for sNaN arguments (bug 20156). 2016-05-27 13:59:24 +00:00
s_fmal.c Merge common usage of mul_split function 2016-08-19 11:29:43 -05:00
s_fpclassifyl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_frexpl.c Fix frexp (NaN) (bug 20250). 2016-06-13 17:27:19 +00:00
s_getpayloadl.c Add getpayload, getpayloadf, getpayloadl. 2016-10-19 01:49:09 +00:00
s_iscanonicall.c Add canonicalize, canonicalizef, canonicalizel. 2016-10-26 23:14:31 +00:00
s_isinfl.c Remove IS_IN_libm 2014-11-24 11:41:47 +05:30
s_isnanl.c Remove IS_IN_libm 2014-11-24 11:41:47 +05:30
s_issignalingl.c Define HIGH_ORDER_BIT_IS_SET_FOR_SNAN to 0 or 1. 2016-10-17 22:48:51 +00:00
s_llrintl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_llroundl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_log1pl.c Fix ldbl-128ibm log1pl (sNaN) (bug 20234). 2016-06-09 17:25:54 +00:00
s_logbl.c Work around powerpc32 integer 0 converting to -0 (bug 887, bug 19049, bug 19050). 2015-10-05 17:46:50 +00:00
s_lrintl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_lroundl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_modfl.c Remove IS_IN_libm 2014-11-24 11:41:47 +05:30
s_nearbyintl.c Fix ldbl-128ibm nearbyintl in non-default rounding modes (bug 19790). 2016-03-09 00:30:59 +00:00
s_nextafterl.c Fix ldbl-128ibm nextafterl, nexttowardl sign of zero result (bug 19678). 2016-02-19 17:19:53 +00:00
s_nexttoward.c Make nextafter, nexttoward set errno (bug 6799). 2015-11-02 18:54:19 +00:00
s_nexttowardf.c Make nextafter, nexttoward set errno (bug 6799). 2015-11-02 18:54:19 +00:00
s_nextupl.c Add nextup and nextdown math functions 2016-06-16 21:37:45 +05:30
s_remquol.c Fix ldbl-128ibm remainderl, remquol equality tests (bug 19603). 2016-02-19 00:55:46 +00:00
s_rintl.c Fix ldbl-128ibm ceill, rintl etc. for sNaN arguments (bug 20156). 2016-05-27 13:59:24 +00:00
s_roundevenl.c Add roundeven, roundevenf, roundevenl. 2016-12-21 01:48:27 +00:00
s_roundl.c Fix ldbl-128ibm ceill, rintl etc. for sNaN arguments (bug 20156). 2016-05-27 13:59:24 +00:00
s_scalblnl.c [BZ #6803] Set errno for scalbln, scalbn 2014-06-20 07:48:20 +05:30
s_scalbnl.c Make scalbn set errno (bug 6803). 2015-09-16 21:11:00 +00:00
s_setpayloadl_main.c Add setpayload, setpayloadf, setpayloadl. 2016-11-19 00:16:28 +00:00
s_setpayloadl.c Add setpayload, setpayloadf, setpayloadl. 2016-11-19 00:16:28 +00:00
s_setpayloadsigl.c Add setpayloadsig, setpayloadsigf, setpayloadsigl. 2016-11-24 23:56:48 +00:00
s_signbitl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_sincosl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
s_sinl.c PowerPC floating point little-endian [2 of 15] 2013-10-04 10:32:19 +09:30
s_tanhl.c Fix ldbl-128ibm tanhl inaccuracy for small arguments (bug 19349). 2015-12-09 21:20:18 +00:00
s_tanl.c PowerPC floating point little-endian [2 of 15] 2013-10-04 10:32:19 +09:30
s_totalorderl.c Define HIGH_ORDER_BIT_IS_SET_FOR_SNAN to 0 or 1. 2016-10-17 22:48:51 +00:00
s_totalordermagl.c Define HIGH_ORDER_BIT_IS_SET_FOR_SNAN to 0 or 1. 2016-10-17 22:48:51 +00:00
s_truncl.c Fix ldbl-128ibm ceill, rintl etc. for sNaN arguments (bug 20156). 2016-05-27 13:59:24 +00:00
strtod_nan_ldouble.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
strtold_l.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
t_sincosl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
test-canonical-ldbl-128ibm.c Add canonicalize, canonicalizef, canonicalizel. 2016-10-26 23:14:31 +00:00
test-fmodl-ldbl-128ibm.c Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677). 2016-03-08 00:27:21 +00:00
test-fmodrem-ldbl-128ibm.c Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677). 2016-03-08 00:27:21 +00:00
test-remainderl-ldbl-128ibm.c Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677). 2016-03-08 00:27:21 +00:00
test-remquol-ldbl-128ibm.c Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677). 2016-03-08 00:27:21 +00:00
test-totalorderl-ldbl-128ibm.c Add totalordermag, totalordermagf, totalordermagl. 2016-10-15 00:36:48 +00:00
tst-strtold-ldbl-128ibm.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
w_expl.c Fix ldbl-128ibm expl overflow in non-default rounding modes (bug 19078). 2015-10-06 17:37:49 +00:00
x2y2m1l.c Merge common usage of mul_split function 2016-08-19 11:29:43 -05:00