[libc-commits] [libc] [libc][math] Improve performance of double precision trig functions. (PR #111793)
via libc-commits
libc-commits at lists.llvm.org
Thu Oct 10 12:06:38 PDT 2024
================
@@ -42,22 +39,29 @@ LLVM_LIBC_FUNCTION(double, cos, (double 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))
- return 1.0;
-
- // For |x| < 2^-27, |cos(x) - 1| < |x|^2/2 < 2^-54 = ulp(1 - 2^-53)/2.
- return fputil::round_result_slightly_down(1.0);
+ // |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))
+ return 1.0;
----------------
lntue wrote:
statistically, for `|x| < 2^-27`, chance for `x == 0.0` is `1/4485585228861014016`
https://github.com/llvm/llvm-project/pull/111793
More information about the libc-commits
mailing list