glibc/sysdeps/ieee754
Anssi Hannula f67f9c9af2 ieee754: Remove slow paths from asin and acos
asin and acos have slow paths for rounding the last bit that cause some
calls to be 500-1500x slower than average calls.

These slow paths are rare, a test of a trillion (1.000.000.000.000)
random inputs between -1 and 1 showed 32870 slow calls for acos and 4473
for asin, with most occurrences between -1.0 .. -0.9 and 0.9 .. 1.0.

The slow paths claim correct rounding and use __sin32() and __cos32()
(which compare two result candidates and return the closest one) as the
final step, with the second result candidate (res1) having a small offset
applied from res. This suggests that res and res1 are intended to be 1
ULP apart (which makes sense for rounding), barring bugs, allowing us to
pick either one and still remain within 1 ULP of the exact result.

Remove the slow paths as the accuracy is better than 1 ULP even without
them, which is enough for glibc.

Also remove code comments claiming correctly rounded results.

After slow path removal, checking the accuracy of 14.400.000.000 random
asin() and acos() inputs showed only three incorrectly rounded
(error > 0.5 ULP) results:
- asin(-0x1.ee2b43286db75p-1) (0.500002 ULP, same as before)
- asin(-0x1.f692ba202abcp-4)  (0.500003 ULP, same as before)
- asin(-0x1.9915e876fc062p-1) (0.50000000001 ULP, previously exact)
The first two had the same error even before this commit, and they did
not use the slow path at all.

Checking 4934 known randomly found previously-slow-path asin inputs
shows 25 calls with incorrectly rounded results, with a maximum error of
0.500000002 ULP (for 0x1.fcd5742999ab8p-1). The previous slow-path code
rounded all these inputs correctly (error < 0.5 ULP).
The observed average speed increase was 130x.

Checking 36240 known randomly found previously-slow-path acos inputs
shows 42 calls with incorrectly rounded results, with a maximum error of
0.500000008 ULP (for 0x1.f63845056f35ep-1). The previous "exact"
slow-path code showed 34 calls with incorrectly rounded results, with the
same maximum error of 0.500000008 ULP (for 0x1.f63845056f35ep-1).
The observed average speed increase was 130x.

The functions could likely be trimmed more while keeping acceptable
accuracy, but this at least gets rid of the egregiously slow cases.

Tested on x86_64.
2020-12-18 12:09:23 +05:30
..
dbl-64 ieee754: Remove slow paths from asin and acos 2020-12-18 12:09:23 +05:30
float128 ieee754: provide gcc builtins based generic fma functions 2020-06-03 10:23:28 -07:00
flt-32 math: Fix inaccuracy of j0f for x >= 2^127 when sin(x)+cos(x) is tiny 2020-08-07 16:33:13 -03:00
ldbl-64-128 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
ldbl-96 Use C2x return value from getpayload of non-NaN (bug 26073). 2020-07-06 16:18:02 +00:00
ldbl-128 Use C2x return value from getpayload of non-NaN (bug 26073). 2020-07-06 16:18:02 +00:00
ldbl-128ibm Remove tls.h inclusion from internal errno.h 2020-11-13 12:59:19 -03:00
ldbl-128ibm-compat powerpc64le: blacklist broken GCC compilers (e.g GCC 7.5.0) 2020-04-30 08:52:08 -05:00
ldbl-opt Rename __LONG_DOUBLE_USES_FLOAT128 to __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 2020-04-30 08:52:08 -05:00
soft-fp Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
ieee754.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
k_standard.c Use copysign functions not __copysign functions in glibc libm. 2018-09-27 20:04:48 +00:00
k_standardf.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
k_standardl.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
libm-alias-finite.h Add libm_alias_finite for _finite symbols 2020-01-03 10:02:04 -03:00
Makefile Avoid -Wno-write-strings for k_standard.c. 2015-02-26 22:50:54 +00:00
s_lib_version.c Simplify math-svid-compat code. 2017-08-28 15:19:52 +00:00
s_matherr.c Obsolete matherr, _LIB_VERSION, libieee.a. 2017-08-21 17:45:10 +00:00
s_signgam.c Remove unnecessary math_private.h includes. 2018-09-28 21:53:33 +00:00