[PATCH v4] Improve performance of sinf/cosf/sincosf

Corinna Vinschen vinschen@redhat.com
Thu Jun 21 07:41:00 GMT 2018


On Jun 20 12:07, Wilco Dijkstra wrote:
> 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

Pushed, thanks.  I accidentally pushed the previous version first,
so don't worry about the reversion orgy :}


Thanks again,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20180621/f344ab60/attachment.sig>


More information about the Newlib mailing list