aboutsummaryrefslogtreecommitdiff
path: root/newlib/libm
AgeCommit message (Collapse)AuthorFilesLines
2018-08-08newlib: fix various gcc warningsCorinna Vinschen5-4/+7
* unused variables * potentially used uninitialized * suggested bracketing * misleading indentation Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-11Remove float compare option from sincosfSzabolcs Nagy1-10/+1
PREFER_FLOAT_COMPARISON setting was not correct as it could raise spurious exceptions. Fixing it is easy: just use ISLESS(x, y) instead of abstop12(x) < abstop12(y) with appropriate non-signaling definition for ISLESS. However it seems this setting is not very useful (there is only minor performance difference on various architectures), so remove this option for now.
2018-07-11Fix the documentation comments for log_inline in powSzabolcs Nagy1-3/+3
There was a typo and the arguments were not explained clearly.
2018-07-06Fix namespace issues in sinf, cosf and sincosfSzabolcs Nagy5-18/+19
Use const sincos_t for clarity instead of making the typedef const. Use __inv_pi4 and __sincosf_table to avoid namespace issues with static linking.
2018-07-06Fix large ulp error in pow without fma very near 1.0Szabolcs Nagy1-2/+4
The !HAVE_FAST_FMA code path split r = z/c - 1 into r = rhi + rlo such that when z = 1-tiny and c = 1 then rlo and rhi could have much larger magnitude than r which later caused large rounding errors. So do a nearest rounding instead of truncation at the split. In newlib with default settings this was observable on some arm targets that enable the new math code but has no fma.
2018-07-06Change the return type of converttoint and document the semanticsSzabolcs Nagy1-1/+9
The roundtoint and converttoint internal functions are only called with small values, so 32 bit result is enough for converttoint and it is a signed int conversion so the natural return type is int32_t. The original idea was to help the compiler keeping the result in uint64_t, then it's clear that no sign extension is needed and there is no accidental undefined or implementation defined signed int arithmetics. But it turns out gcc does a good job with inlining so changing the type has no overhead and the semantics of the conversion is less surprising this way. Since we want to allow the asuint64 (x + 0x1.8p52) style conversion, the top bits were never usable and the existing code ensures that only the bottom 32 bits of the conversion result are used. In newlib with default settings only aarch64 is affected and there is no significant code generation change with gcc after the patch.
2018-07-06Remove unused TOINT_RINT and TOINT_SHIFT macrosSzabolcs Nagy2-10/+1
Only have separate code paths for TOINT_INTRINSICS and !TOINT_INTRINSICS.
2018-07-06Move __HAVE_FAST_FMA to math_config.hSzabolcs Nagy6-12/+21
Define it consistently with other HAVE_* macros that only affect code using math_config.h. This is also closer to the Arm Optimized Routines code.
2018-07-06Fix code style and comments of new math codeSzabolcs Nagy8-74/+134
Synchronize code style and comments with Arm Optimized Routines, there are no code changes in this patch. This ensures different projects using the same code have consistent code style so bug fix patches can be applied more easily.
2018-06-27New pow implementationSzabolcs Nagy8-5/+607
The new implementation is provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.54 ULP with inlined fma and fma contraction. It uses a 4 KB lookup table in addition to the table in exp_data.c, on aarch64 .text+.rodata size of libm.a is increased by 2295 bytes. Improvements on Cortex-A72: latency: 3.3x thruput: 4.9x
2018-06-27New log2 implementationSzabolcs Nagy6-4/+399
The new implementation is provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.547 ULP with inlined fma and fma contraction. It uses a 1 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1584 bytes. Note that the math.h header defines log2(x) to be log(x)/Ln2, this is not changed, so the new code is only used if that macro is suppressed. Improvements on Cortex-A72: latency: 2.0x thruput: 2.2x
2018-06-27New log implementationSzabolcs Nagy8-4/+721
The new implementations are provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.519 ULP with inlined fma and fma contraction. It uses a 2 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1703 bytes. The w_log.c wrapper is disabled since error handling is inline in the new code. New __HAVE_FAST_FMA and __HAVE_FAST_FMA_DEFAULT feature macros were added to enable selecting between the code path that uses fma and the one that does not. Targets supposed to set __HAVE_FAST_FMA_DEFAULT if they have single instruction fma and the compiler can actually inline it (gcc has __FP_FAST_FMA macro but that does not guarantee inlining with -fno-builtin-fma). Improvements on Cortex-A72: latency: 1.9x thruput: 2.3x
2018-06-27New exp and exp2 implementationsSzabolcs Nagy11-5/+1138
The new implementations are provided under !__OBSOLETE_MATH, they use ISO C99 code. There are several settings, with the default one the worst case error in nearest rounding mode is 0.509 ULP for exp and 0.507 ULP for exp2 when a multiply and add is contracted into an fma. They use a shared 2 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1868 bytes. The w_*.c wrappers are disabled for the new code as it takes care of error handling inline. The old exp2(x) code used to be just pow(2,x) so the speedup there is more significant. The file name has no special prefix to avoid any name collision with existing files. Improvements on Cortex-A72: exp latency: 3.2x exp thruput: 4.1x exp2 latency: 7.8x exp2 thruput: 18.8x
2018-06-27Use uint32_t sign argument to math error functionsSzabolcs Nagy3-13/+13
This change is equivalent to the commit https://github.com/ARM-software/optimized-routines/commit/c65db17340782d647c49e17cbba244862dc38402 and only affects code that is from the Arm optimized-routines project. It does not affect the observable behaviour, but the code generation can be different on 64bit targets. The intention is to make the portable semantics of the code obvious by using a fixed size type.
2018-06-26Revert "Remove -fno-builtin to allow gcc to inline functions such as fabs, ↵Corinna Vinschen8-8/+8
floor, creal, imag." This reverts commit c077b9de99c6980a0c1631ec2938f6ff2cf0c289. Yet another accidental commit...
2018-06-25Remove -fno-builtin to allow gcc to inline functions such as fabs, floor, ↵Jon Beniston8-8/+8
creal, imag.
2018-06-21Improve performance of sinf/cosf/sincosfWilco Dijkstra11-6/+667
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-21Revert "Improve performance of sinf/cosf/sincosf"Corinna Vinschen11-667/+6
This reverts commit fca80a9d1b3fa6620cdaccec6b726eef1a6530a1. Accidentally pushed a preliminary version
2018-06-21libm/common/s_round.c (round): Add cast for 16-bit CPUsJon Beniston1-1/+1
2018-06-19Improve performance of sinf/cosf/sincosfWilco Dijkstra11-6/+667
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-06-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-05-29fix llrint and lrint for 52 <= exponent <= 62Matthias Kannwischer2-4/+4
2018-05-07Use _LDBL_EQ_DBL in nexttowardf.cJeff Johnston1-2/+2
2018-05-07 Tom de Vries <tom@codesourcery.com> * libm/common/nexttowardf.c: Use _LDBL_EQ_DBL instead of _LDBL_EQ_DOUBLE.
2018-04-13Add nvptx port.Jeff Johnston9-38/+73
- From: Cesar Philippidis <cesar@codesourcery.com> Date: Tue, 10 Apr 2018 14:43:42 -0700 Subject: [PATCH] nvptx port This port adds support for Nvidia GPU's, which are primarily used as offload accelerators in OpenACC and OpenMP.
2018-01-18Bump release to 3.0.0 for yearly snapshotnewlib-snapshot-20180118newlib-3.0.0Jeff Johnston10-199/+180
- major release required due to removal of K&R support
2018-01-17ansification: remove _HAVE_STDCYaakov Selkowitz1-5/+0
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _EXFUN, _EXFUN_NOTHROWYaakov Selkowitz4-33/+33
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _DEFUNYaakov Selkowitz69-231/+127
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _DEFUN_VOIDYaakov Selkowitz5-31/+31
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _CONSTYaakov Selkowitz3-4/+4
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _ANDYaakov Selkowitz24-93/+93
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-13newlib: Don't do double divide in powf.Jim Wilson1-1/+3
* Use 0.0f instead of 0.0 in divide.
2017-12-13Don't call double rint from float powf.Jim Wilson1-2/+2
Updated patch to use 0.0f in addition to calling rintf. Tested same way as before, with a testcase that triggers the code and make check. OK? newlib/ * libm/math/wf_pow.c (powf): Call rintf instead of rint. Use 0.0f for compare.
2017-12-07makedoc: make errors visibleJon Turney10-30/+30
Discard QUICKREF sections, rather than writing them to stderr Discard MATHREF sections, rather than discarding as an error Pass NOTES sections through to texinfo, rather than discarding as an error Don't redirect makedoc stderr to .ref file Remove makedoc output on error Remove .ref files from CLEANFILES Regenerate Makefile.ins Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-12-01mathfp: remove TRAD_SYNOPSISYaakov Selkowitz28-344/+28
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01math: remove TRAD_SYNOPSISYaakov Selkowitz28-310/+28
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01libm/machine: remove TRAD_SYNOPSISYaakov Selkowitz3-12/+3
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01complex: remove TRAD_SYNOPSISYaakov Selkowitz23-23/+23
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01libm/common: remove TRAD_SYNOPSISYaakov Selkowitz30-133/+30
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-10-20fix internal __ieee754_expf and __ieee754_logf callsSzabolcs Nagy1-0/+11
The recently added new math code inlines error handling instead of using error handling wrappers around __ieee754* internal symbols, and thus the __ieee754* symbols are no longer provided. However __ieee754_expf and __ieee754_logf are used in the implementation of a number of other math functions. These symbols are safe to redirect to the external expf and logf symbols, because those names are always reserved when single precision math functions are reserved and the additional error handling code is either not reached or there will be an error in the final result that will override an internal spurious errno setting. For consistency all of __ieee754_expf, __ieee754_logf and __ieee754_powf are redirected using a macro.
2017-10-13New expf, exp2f, logf, log2f and powf implementationsSzabolcs Nagy23-88/+1312
Based on code from https://github.com/ARM-software/optimized-routines/ This patch adds a highly optimized generic implementation of expf, exp2f, logf, log2f and powf. The new functions are not only faster (6x for powf!), but are also smaller and more accurate. In order to achieve this, the algorithm uses double precision arithmetic for accuracy, avoids divisions and uses small table lookups to minimize the polynomials. Special cases are handled inline to avoid the unnecessary overhead of wrapper functions and set errno to POSIX requirements. The new functions are added under newlib/libm/common, but the old implementations are kept (in newlib/libm/math) for non-IEEE or pre-C99 systems. Targets can enable the new math code by defining __OBSOLETE_MATH_DEFAULT to 0 in newlib/libc/include/machine/ieeefp.h, users can override the default by defining __OBSOLETE_MATH. Currently the new code is enabled for AArch64 and AArch32 with VFP. Targets with a single precision FPU may still prefer the old implementation. libm.a size changes: arm: -1692 arm/thumb/v7-a/nofp: -878 arm/thumb/v7-a+fp/hard: -864 arm/thumb/v7-a+fp/softfp: -908 aarch64: -1476
2017-09-19newlib/libm/complex/cargl.c change imag() real() to cimagl() creall()newlib-snapshot-20170922Brian Inglis1-1/+1
2017-08-17Add RISC-V port for libmKito Cheng19-1/+7282
Contributor list: - Michael Neilly <mneilly@yahoo.com> - Kito Cheng <kito.cheng@gmail.com>
2017-07-28Importing catanl long double complex method from NetBSD.Aditya Upadhyay3-4/+88
2017-07-28Fixing HUGE_VALF to HUGE_VALL.Aditya Upadhyay1-1/+1
2017-06-29newlib: fix file mode of newly added complex sourcesCorinna Vinschen16-0/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-06-29newlib: libm/complex/Makefile.in: regenerateCorinna Vinschen1-22/+161
2017-06-29Adding csinl.c in Makefile.amAditya Upadhyay1-1/+1
Signed-off-by: Aditya Upadhyay <aadit0402@gmail.com>
2017-06-29Importing csinl.c from NetBSD.Aditya Upadhyay1-0/+45
2017-06-29Importing csinhl.c from NetBSD.Aditya Upadhyay2-1/+46
2017-06-29Importing casinhl.c from NetBSD.Aditya Upadhyay2-1/+43