[libc-commits] [libc] [llvm] [libc][math] Refactor log to header-only shared math (PR #175395)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Sat Jan 10 15:26:04 PST 2026
================
@@ -0,0 +1,845 @@
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
+
+#include "log_range_reduction.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/integer_literals.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/math/common_constants.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// 128-bit precision dyadic floating point numbers.
+using Float128 = typename fputil::DyadicFloat<128>;
+
+using LIBC_NAMESPACE::operator""_u128;
+
+namespace math {
+
+using namespace common_constants_internal;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+// A simple upper bound for the error of e_x * log(2) - log(r).
+constexpr double HI_ERR = 0x1.0p-85;
+
+// Extra errors from P is from using x^2 to reduce evaluation latency.
+constexpr double P_ERR = 0x1.0p-50;
+
+// log(2) with 128-bit precision generated by SageMath with:
+// def format_hex(value):
+// l = hex(value)[2:]
+// n = 8
+// x = [l[i:i + n] for i in range(0, len(l), n)]
+// return "0x" + "'".join(x) + "_u128"
+// (s, m, e) = RealField(128)(2).log().sign_mantissa_exponent();
+// print(format_hex(m));
+constexpr Float128 LOG_2(Sign::POS, /*exponent=*/-128, /*mantissa=*/
+ 0xb17217f7'd1cf79ab'c9e3b398'03f2f6af_u128);
+
+alignas(16) constexpr LogRR LOG_TABLE = {
----------------
bassiounix wrote:
```suggestion
LIBC_INLINE_VAR alignas(16) constexpr LogRR LOG_TABLE = {
```
https://github.com/llvm/llvm-project/pull/175395
More information about the libc-commits
mailing list