[PATCH 02/10] Improve performance of sincosf
Szabolcs Nagy
szabolcs.nagy@arm.com
Fri Jul 6 08:57:00 GMT 2018
v4:
- Added empty s_sincosf_data.c on targets with their own sincosf.
- Moved round/converttoint changes in math_private.h to separate patch.
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.
sincosf throughput gains on Cortex-A72:
* |x| < 0x1p-12 : 1.6x
* |x| < M_PI_4 : 1.7x
* |x| < 2 * M_PI: 1.5x
* |x| < 120.0 : 1.8x
* |x| < Inf : 2.3x
On a benchmark with significant use of sincosf the overall speedup is >33%.
ChangeLog:
2018-07-06 Wilco Dijkstra <wdijkstr@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com>
* math/Makefile: Add s_sincosf_data.c.
* sysdeps/ia64/fpu/s_sincosf_data.c: New file.
* sysdeps/ieee754/flt-32/math_config.h (PREFER_FLOAT_COMPARISON): Define.
* sysdeps/ieee754/flt-32/s_sincosf.h (abstop12): Add new function.
(sincosf_poly): Likewise.
(reduce_small): Likewise.
(reduce_large): Likewise.
* sysdeps/ieee754/flt-32/s_sincosf.c (sincosf): Rewrite.
* sysdeps/ieee754/flt-32/s_sincosf_data.c: New file with sincosf data.
* sysdeps/m68k/m680x0/fpu/s_sincosf_data.c: New file.
* sysdeps/x86_64/fpu/s_sincosf_data.c: New file.
---
math/Makefile | 2 +-
sysdeps/ia64/fpu/s_sincosf_data.c | 1 +
sysdeps/ieee754/flt-32/math_config.h | 3 +
sysdeps/ieee754/flt-32/s_sincosf.c | 197 ++++++++++---------------------
sysdeps/ieee754/flt-32/s_sincosf.h | 119 +++++++++++++++++++
sysdeps/ieee754/flt-32/s_sincosf_data.c | 74 ++++++++++++
sysdeps/m68k/m680x0/fpu/s_sincosf_data.c | 1 +
sysdeps/x86_64/fpu/s_sincosf_data.c | 1 +
8 files changed, 265 insertions(+), 133 deletions(-)
create mode 100644 sysdeps/ia64/fpu/s_sincosf_data.c
create mode 100644 sysdeps/ieee754/flt-32/s_sincosf_data.c
create mode 100644 sysdeps/m68k/m680x0/fpu/s_sincosf_data.c
create mode 100644 sysdeps/x86_64/fpu/s_sincosf_data.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Improve-performance-of-sincosf.diff
Type: text/x-patch
Size: 14491 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20180706/761a16b7/attachment.bin>
More information about the Libc-alpha
mailing list