[libc-commits] [libc] [llvm] [libc][math] Refactor `logbl` to header only (PR #181659)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 16 05:06:32 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Vachan (VachanVY)
<details>
<summary>Changes</summary>
Patch for #<!-- -->175366
---
Full diff: https://github.com/llvm/llvm-project/pull/181659.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/logbl.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+8)
- (added) libc/src/__support/math/logbl.h (+26)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-1)
- (modified) libc/src/math/generic/logbl.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+1)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+13-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 93f7d6a8156cf..e7c197d932344 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -109,6 +109,7 @@
#include "math/logbf.h"
#include "math/logbf128.h"
#include "math/logbf16.h"
+#include "math/logbl.h"
#include "math/logf.h"
#include "math/logf16.h"
#include "math/pow.h"
diff --git a/libc/shared/math/logbl.h b/libc/shared/math/logbl.h
new file mode 100644
index 0000000000000..ae5c4b648c6d7
--- /dev/null
+++ b/libc/shared/math/logbl.h
@@ -0,0 +1,23 @@
+//===-- Shared logbl function -----------------------------------*- 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_SHARED_MATH_LOGBL_H
+#define LLVM_LIBC_SHARED_MATH_LOGBL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/logbl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::logbl;
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_LOGBL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index aaab78c01a891..deb4be86517fb 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1613,6 +1613,14 @@ add_header_library(
libc.src.__support.macros.properties.cpu_features
)
+add_header_library(
+ logbl
+ HDRS
+ logbl.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+)
+
add_header_library(
log_range_reduction
HDRS
diff --git a/libc/src/__support/math/logbl.h b/libc/src/__support/math/logbl.h
new file mode 100644
index 0000000000000..750050277c165
--- /dev/null
+++ b/libc/src/__support/math/logbl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for logbl -------------------------*- 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___SUPPORT_MATH_LOGBL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGBL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double logbl(long double x) {
+ return fputil::logb(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGBL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 75b51b4587bea..1554f049b7675 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2022,7 +2022,7 @@ add_entrypoint_object(
HDRS
../logbl.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.logbl
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/logbl.cpp b/libc/src/math/generic/logbl.cpp
index dcab957f2c9c5..6c1df6d6549c0 100644
--- a/libc/src/math/generic/logbl.cpp
+++ b/libc/src/math/generic/logbl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/logbl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/logbl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, logbl, (long double x)) {
- return fputil::logb(x);
+ return math::logbl(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9dfbedee66a33..af1681594efa2 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -106,6 +106,7 @@ add_fp_unittest(
libc.src.__support.math.llogbf
libc.src.__support.math.llogbf128
libc.src.__support.math.llogbf16
+ libc.src.__support.math.logbl
libc.src.__support.math.logf16
libc.src.__support.math.llogbl
libc.src.__support.math.pow
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 2d7ee388f754d..9b849150e9997 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -182,6 +182,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fsqrtl(0.0L));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbl(1.0L));
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::logbl(1.0L));
EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L));
long double canonicalizel_cx = 0.0L;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 608180b90e87b..5621941c994c9 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3234,6 +3234,15 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_logbl",
+ hdrs = ["src/__support/math/logbl.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_manipulation_functions",
+ ],
+)
+
libc_support_library(
name = "__support_math_log10",
hdrs = ["src/__support/math/log10.h"],
@@ -5230,7 +5239,10 @@ libc_math_function(
additional_deps = [":__support_math_logbf"],
)
-libc_math_function(name = "logbl")
+libc_math_function(
+ name = "logbl",
+ additional_deps = [":__support_math_logbl"],
+)
libc_math_function(
name = "logbf128",
``````````
</details>
https://github.com/llvm/llvm-project/pull/181659
More information about the libc-commits
mailing list