[libc-commits] [libc] 79f8eba - [libc][math] Refactor `logbl` to header only (#181659)
via libc-commits
libc-commits at lists.llvm.org
Wed Feb 18 06:03:50 PST 2026
Author: Vachan
Date: 2026-02-18T14:03:17Z
New Revision: 79f8eba842c9bce7d85e702574f0bc02b2397af2
URL: https://github.com/llvm/llvm-project/commit/79f8eba842c9bce7d85e702574f0bc02b2397af2
DIFF: https://github.com/llvm/llvm-project/commit/79f8eba842c9bce7d85e702574f0bc02b2397af2.diff
LOG: [libc][math] Refactor `logbl` to header only (#181659)
Closes #175366
Added:
libc/shared/math/logbl.h
libc/src/__support/math/logbl.h
Modified:
libc/shared/math.h
libc/src/__support/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/logbl.cpp
libc/test/shared/CMakeLists.txt
libc/test/shared/shared_math_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 195a71663ad3c..ca711544f00d4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -117,6 +117,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..d2bee4afe4e76
--- /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 6cd1ecddb4b4a..245777c56a167 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1716,6 +1716,16 @@ add_header_library(
libc.src.__support.macros.properties.cpu_features
)
+add_header_library(
+ logbl
+ HDRS
+ logbl.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
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 1c9dda6cbcc8e..be23e14830f73 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1999,7 +1999,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 c30c46efdba74..22670dbe4ea97 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -114,6 +114,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 3d7b2abf07330..41ce6ee62fabb 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -195,6 +195,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 ab17728a53511..00f88723aaea6 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3305,6 +3305,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_logbl",
+ hdrs = ["src/__support/math/logbl.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_log10",
hdrs = ["src/__support/math/log10.h"],
@@ -5399,7 +5409,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",
More information about the libc-commits
mailing list