acadia-newlib/newlib/libm/common
Wilco Dijkstra 3baadb9912 Improve performance of sinf/cosf/sincosf
Here is the correct patch with both filenames and int cast fixed:

This patch is a complete rewrite of sinf, cosf and sincosf.  The new version
is significantly faster, as well as simple and accurate.
The worst-case ULP is 0.56072, maximum relative error is 0.5303p-23 over all
4 billion inputs.  In non-nearest rounding modes the error is 1ULP.

The algorithm uses 3 main cases: small inputs which don't need argument
reduction, small inputs which need a simple range reduction and large inputs
requiring complex range reduction.  The code uses approximate integer
comparisons to quickly decide between these cases - on some targets this may
be slow, so this can be configured to use floating point comparisons.

The small range reducer uses a single reduction step to handle values up to
120.0.  It is fastest on targets which support inlined round instructions.

The large range reducer uses integer arithmetic for simplicity.  It does a
32x96 bit multiply to compute a 64-bit modulo result.  This is more than
accurate enough to handle the worst-case cancellation for values close to
an integer multiple of PI/4.  It could be further optimized, however it is
already much faster than necessary.

Simple benchmark showing speedup factor on AArch64 for various ranges:

range	0.7853982	sinf	1.7	cosf	2.2	sincosf	2.8
range	1.570796	sinf	1.9	cosf	1.9	sincosf	2.7
range	3.141593	sinf	2.0	cosf	2.0	sincosf	3.5
range	6.283185	sinf	2.3	cosf	2.3	sincosf	4.2
range	125.6637	sinf	2.9	cosf	3.0	sincosf	5.1
range	1.1259e15	sinf	26.8	cosf	26.8	sincosf	45.2

ChangeLog:
2018-05-18  Wilco Dijkstra  <wdijkstr@arm.com>

        * newlib/libm/common/Makefile.in: Regenerated.
        * newlib/libm/common/Makefile.am: Add sinf.c, cosf.c, sincosf.c
        sincosf.h, sincosf_data.c. Add -fbuiltin -fno-math-errno to CFLAGS.
        * newlib/libm/common/math_config.h: Add HAVE_FAST_ROUND, HAVE_FAST_LROUND,
        roundtoint, converttoint, force_eval_float, force_eval_double, eval_as_float,
        eval_as_double, likely, unlikely.
        * newlib/libm/common/cosf.c: New file.
        * newlib/libm/common/sinf.c: Likewise.
        * newlib/libm/common/sincosf.h: Likewise.
        * newlib/libm/common/sincosf.c: Likewise.
        * newlib/libm/common/sincosf_data.c: Likewise.
        * newlib/libm/math/sf_cos.c: Add #if to build conditionally.
        * newlib/libm/math/sf_sin.c: Likewise.
        * newlib/libm/math/wf_sincos.c: Likewise.

--
2018-06-21 09:37:04 +02:00
..
Makefile.am Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
Makefile.in Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
acoshl.c
acosl.c
asinhl.c
asinl.c
atan2l.c
atanhl.c
atanl.c
cbrtl.c
ceill.c
copysignl.c
cosf.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
coshl.c
cosl.c
erfcl.c
erfl.c
exp2l.c
expl.c
expm1l.c
fabsl.c
fdiml.c
fdlibm.h fix internal __ieee754_expf and __ieee754_logf calls 2017-10-20 11:19:02 +02:00
floorl.c
fmal.c
fmaxl.c
fminl.c
fmodl.c
frexpl.c
hypotl.c * libc/include/complex.h (cabsl): Add prototype. 2015-02-06 16:14:04 +00:00
ilogbl.c
isgreater.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
ldexpl.c
lgammal.c
llrintl.c
llroundl.c
local.h
log1pl.c
log2l.c 2014-12-15 Jonathan Roelofs <jonathan@codesourcery.com> 2014-12-15 20:50:23 +00:00
log10l.c
logbl.c 2014-12-15 Jonathan Roelofs <jonathan@codesourcery.com> 2014-12-15 20:50:23 +00:00
logl.c
lrintl.c
lroundl.c
math_config.h Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
math_errf.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
modfl.c 2013-11-19 Joel Sherrill <joel.sherrill@oarcorp.com> 2013-11-19 17:28:04 +00:00
nanl.c
nearbyintl.c
nextafterl.c
nexttoward.c 2014-12-15 Jonathan Roelofs <jonathan@codesourcery.com> 2014-12-15 20:50:23 +00:00
nexttowardf.c Use _LDBL_EQ_DBL in nexttowardf.c 2018-05-07 12:22:12 -04:00
nexttowardl.c 2014-12-15 Jonathan Roelofs <jonathan@codesourcery.com> 2014-12-15 20:50:23 +00:00
powl.c
remainderl.c
remquol.c
rintl.c
roundl.c
s_cbrt.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_copysign.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_exp10.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_expm1.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fdim.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_finite.c
s_fma.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fmax.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fmin.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fpclassify.c
s_ilogb.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_infinity.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_isinf.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
s_isinfd.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
s_isnan.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_isnand.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
s_lib_ver.c
s_llrint.c fix llrint and lrint for 52 <= exponent <= 62 2018-05-29 15:59:48 +02:00
s_llround.c 2010-08-03 Craig Howland <howland@LGSInnovations.com> 2010-08-03 18:21:20 +00:00
s_log1p.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_log2.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_logb.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_lrint.c fix llrint and lrint for 52 <= exponent <= 62 2018-05-29 15:59:48 +02:00
s_lround.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_matherr.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_modf.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_nan.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_nearbyint.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_nextafter.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_pow10.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_remquo.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_rint.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_round.c libm/common/s_round.c (round): Add cast for 16-bit CPUs 2018-06-21 09:31:13 +02:00
s_scalbln.c
s_scalbn.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_signbit.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_trunc.c libm/common: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
scalblnl.c
scalbnl.c
sf_cbrt.c
sf_copysign.c
sf_exp.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_exp2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_exp2_data.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_exp10.c
sf_expm1.c
sf_fdim.c
sf_finite.c
sf_fma.c
sf_fmax.c
sf_fmin.c
sf_fpclassify.c
sf_ilogb.c 2010-02-11 Craig Howland <howland@LGSInnovations.com> 2010-02-11 21:00:33 +00:00
sf_infinity.c
sf_isinf.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
sf_isinff.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
sf_isnan.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
sf_isnanf.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
sf_llrint.c * libm/common/sf_llrint.c, libm/common/sf_round.c: Add explicit casts 2010-10-08 15:24:56 +00:00
sf_llround.c
sf_log.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_log1p.c
sf_log2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_log2_data.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_log_data.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_logb.c
sf_lrint.c
sf_lround.c
sf_modf.c
sf_nan.c 2014-03-21 Maciej W. Rozycki <macro@codesourcery.com> 2014-03-21 21:27:29 +00:00
sf_nearbyint.c
sf_nextafter.c
sf_pow.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_pow10.c
sf_pow_log2_data.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
sf_remquo.c
sf_rint.c 2010-03-08 Craig Howland <howland@LGSInnovations.com> 2010-03-08 17:16:37 +00:00
sf_round.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
sf_scalbln.c
sf_scalbn.c
sf_trunc.c
sincosf.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sincosf.h Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sincosf_data.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sinf.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sinhl.c
sinl.c
sl_finite.c finitel: Use correct GCC builtin 2016-03-26 20:29:20 +01:00
sqrtl.c * libc/include/complex.h (cabsl): Add prototype. 2015-02-06 16:14:04 +00:00
tanhl.c
tanl.c
tgammal.c
truncl.c