[libc-commits] [libc] [libc][math] Improve performance of double precision trig functions. (PR #111793)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Oct 10 08:52:09 PDT 2024
================
@@ -44,40 +41,47 @@ LLVM_LIBC_FUNCTION(void, sincos, (double x, double *sin_x, double *cos_x)) {
DoubleDouble y;
unsigned k;
- generic::LargeRangeReduction<NO_FMA> range_reduction_large{};
+ LargeRangeReduction range_reduction_large{};
- // |x| < 2^32 (with FMA) or |x| < 2^23 (w/o FMA)
+ // |x| < 2^16
if (LIBC_LIKELY(x_e < FPBits::EXP_BIAS + FAST_PASS_EXPONENT)) {
- // |x| < 2^-27
- if (LIBC_UNLIKELY(x_e < FPBits::EXP_BIAS - 27)) {
- // Signed zeros.
- if (LIBC_UNLIKELY(x == 0.0)) {
- *sin_x = x;
- *cos_x = 1.0;
- return;
- }
-
- // For |x| < 2^-27, max(|sin(x) - x|, |cos(x) - 1|) < ulp(x)/2.
+ // |x| < 2^-7
+ if (LIBC_UNLIKELY(x_e < FPBits::EXP_BIAS - 7)) {
+ // |x| < 2^-27
+ if (LIBC_UNLIKELY(x_e < FPBits::EXP_BIAS - 27)) {
+ // Signed zeros.
+ if (LIBC_UNLIKELY(x == 0.0)) {
+ *sin_x = x;
+ *cos_x = 1.0;
+ return;
+ }
----------------
nickdesaulniers wrote:
Perhaps in the future, we can have one implementation for computing sincos that BOTH sin and cos use, where once inlined we can skip computing the unneeded result. Currently, there's a fair amount of duplication between sincos, sin, and cos that I think can be avoided. Not necessary for this PR, but worth a thought.
https://github.com/llvm/llvm-project/pull/111793
More information about the libc-commits
mailing list