libc/newlib/libm/math
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 New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
Makefile.in makedoc: make errors visible 2017-12-07 11:54:11 +00:00
e_acos.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_acosh.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_asin.c 2000-05-26 Marek Michalkiewicz <marekm@linux.org.pl> 2000-05-26 22:42:39 +00:00
e_atan2.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_atanh.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_cosh.c 2000-08-23 Werner Almesberger <Werner.Almesberger@epfl.ch> 2000-08-28 17:45:56 +00:00
e_exp.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_fmod.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_hypot.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_j0.c 2000-05-26 Marek Michalkiewicz <marekm@linux.org.pl> 2000-05-26 22:42:39 +00:00
e_j1.c 2000-05-26 Marek Michalkiewicz <marekm@linux.org.pl> 2000-05-26 22:42:39 +00:00
e_jn.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_log.c 2000-05-26 Marek Michalkiewicz <marekm@linux.org.pl> 2000-05-26 22:42:39 +00:00
e_log10.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_pow.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_rem_pio2.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_remainder.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_scalb.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
e_sinh.c 2000-08-23 Werner Almesberger <Werner.Almesberger@epfl.ch> 2000-08-28 17:45:56 +00:00
e_sqrt.c Avoid unneeded truncation to "int" 2015-05-27 13:30:20 +02:00
ef_acos.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
ef_acosh.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_asin.c 2001-04-17 Stephen L. Moshier <moshier@moshier.ne.mediaone.net> 2001-04-17 17:13:00 +00:00
ef_atan2.c 2005-07-20 Bob Wilson <bob.wilson@acm.org> 2005-07-20 16:20:24 +00:00
ef_atanh.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
ef_cosh.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_exp.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
ef_fmod.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_hypot.c 2005-08-02 Bob Wilson <bob.wilson@acm.org> 2005-08-02 19:44:44 +00:00
ef_j0.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_j1.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_jn.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_log.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
ef_log10.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_pow.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
ef_rem_pio2.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_remainder.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_scalb.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
ef_sinh.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
ef_sqrt.c * libm/math/ef_sqrt.c: Delete unused variable sign. 2010-03-05 08:55:16 +00:00
el_hypot.c * libc/include/complex.h (cabsl): Add prototype. 2015-02-06 16:14:04 +00:00
er_gamma.c * libm/common/s_fdim.c: New file. 2002-06-07 21:59:57 +00:00
er_lgamma.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
erf_gamma.c * libm/common/s_fdim.c: New file. 2002-06-07 21:59:57 +00:00
erf_lgamma.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
k_cos.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
k_rem_pio2.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
k_sin.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
k_standard.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
k_tan.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
kf_cos.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
kf_rem_pio2.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
kf_sin.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
kf_tan.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
math.tex Use makedoc output files which are generated but aren't included 2015-06-24 12:23:55 +01:00
s_asinh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_atan.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_ceil.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
s_cos.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
s_erf.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fabs.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_floor.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_frexp.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_ldexp.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_signif.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
s_sin.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_tan.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_tanh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
sf_asinh.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_atan.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_ceil.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_cos.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sf_erf.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_fabs.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
sf_floor.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_frexp.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_ldexp.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
sf_signif.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
sf_sin.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sf_tan.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
sf_tanh.c * libc/include/machine/ieeefp.h: Comment about new configuration 2001-04-04 13:33:01 +00:00
w_acos.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_acosh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_asin.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_atan2.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_atanh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_cosh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_drem.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
w_exp.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_exp2.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_fmod.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_gamma.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_hypot.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_j0.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_j1.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
w_jn.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
w_lgamma.c * implement a new `struct _reent' that is significantly smaller. use this 2002-02-03 09:24:18 +00:00
w_log.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_log10.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_pow.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_remainder.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_scalb.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
w_sincos.c * libc/sys/linux/cmath: New directory. 2002-08-16 21:29:45 +00:00
w_sinh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_sqrt.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
w_tgamma.c 2011-01-12 Ralf Corsépius <ralf.corsepius@rtems.org> 2011-01-12 22:25:15 +00:00
wf_acos.c ansification: remove _HAVE_STDC 2018-01-17 11:47:30 -06:00
wf_acosh.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_asin.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_atan2.c 2007-05-17 Cary R. <cygcary <at> yahoo.com> 2007-05-17 21:52:11 +00:00
wf_atanh.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_cosh.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_drem.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wf_exp.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_exp2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_fmod.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_gamma.c * implement a new `struct _reent' that is significantly smaller. use this 2002-02-03 09:24:18 +00:00
wf_hypot.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wf_j0.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_j1.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_jn.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_lgamma.c * implement a new `struct _reent' that is significantly smaller. use this 2002-02-03 09:24:18 +00:00
wf_log.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_log2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_log10.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_pow.c newlib: Don't do double divide in powf. 2017-12-13 11:33:19 +01:00
wf_remainder.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_scalb.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_sincos.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
wf_sinh.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wf_sqrt.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
wf_tgamma.c 2011-01-12 Ralf Corsépius <ralf.corsepius@rtems.org> 2011-01-12 22:25:15 +00:00
wr_gamma.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wr_lgamma.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wrf_gamma.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00
wrf_lgamma.c import newlib-2000-02-17 snapshot 2000-02-17 19:39:52 +00:00