//===-- Utilities for trigonometric functions -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_LIBC_SRC_MATH_GENERIC_RANGE_REDUCTION_H #define LLVM_LIBC_SRC_MATH_GENERIC_RANGE_REDUCTION_H #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/multiply_add.h" #include "src/__support/FPUtil/nearest_integer.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { namespace generic { static constexpr uint32_t FAST_PASS_BOUND = …; // 2^22 static constexpr int N_ENTRIES = …; // We choose to split bits of 32/pi into 28-bit precision pieces, so that the // product of x * THIRTYTWO_OVER_PI_28[i] is exact. // These are generated by Sollya with: // > a1 = D(round(32/pi, 28, RN)); a1; // > a2 = D(round(32/pi - a1, 28, RN)); a2; // > a3 = D(round(32/pi - a1 - a2, 28, RN)); a3; // > a4 = D(round(32/pi - a1 - a2 - a3, 28, RN)); a4; // ... static constexpr double THIRTYTWO_OVER_PI_28[N_ENTRIES] = …; // Exponents of the least significant bits of the corresponding entries in // THIRTYTWO_OVER_PI_28. static constexpr int THIRTYTWO_OVER_PI_28_LSB_EXP[N_ENTRIES] = …; // Return k and y, where // k = round(x * 16 / pi) and y = (x * 16 / pi) - k. LIBC_INLINE int64_t small_range_reduction(double x, double &y) { … } // Return k and y, where // k = round(x * 32 / pi) and y = (x * 32 / pi) - k. // For large range, there are at most 2 parts of THIRTYTWO_OVER_PI_28 // contributing to the lowest 6 binary digits (k & 63). If the least // significant bit of x * the least significant bit of THIRTYTWO_OVER_PI_28[i] // >= 64, we can completely ignore THIRTYTWO_OVER_PI_28[i]. LIBC_INLINE int64_t large_range_reduction(double x, int x_exp, double &y) { … } } // namespace generic } // namespace LIBC_NAMESPACE_DECL #endif // LLVM_LIBC_SRC_MATH_GENERIC_RANGE_REDUCTION_H