[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:05:39 PST 2026


https://github.com/VachanVY updated https://github.com/llvm/llvm-project/pull/181659

>From 5f91dc161a7156ef72d48af38c175c9b984ea981 Mon Sep 17 00:00:00 2001
From: Vachan V Y <vachanvy05 at gmail.com>
Date: Mon, 16 Feb 2026 18:26:05 +0530
Subject: [PATCH 1/2] [libc][math] add logbl function

---
 libc/shared/math.h                            |  1 +
 libc/shared/math/logbl.h                      | 23 ++++++++++++++++
 libc/src/__support/math/CMakeLists.txt        |  8 ++++++
 libc/src/__support/math/logbl.h               | 26 +++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |  2 +-
 libc/src/math/generic/logbl.cpp               |  6 ++---
 libc/test/shared/CMakeLists.txt               |  1 +
 libc/test/shared/shared_math_test.cpp         |  1 +
 .../llvm-project-overlay/libc/BUILD.bazel     | 14 +++++++++-
 9 files changed, 76 insertions(+), 6 deletions(-)
 create mode 100644 libc/shared/math/logbl.h
 create mode 100644 libc/src/__support/math/logbl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 3949b1210e317..11e5db5a7bf8e 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -102,6 +102,7 @@
 #include "math/logbf16.h"
 #include "math/logf.h"
 #include "math/logf16.h"
+#include "math/logbl.h"
 #include "math/pow.h"
 #include "math/powf.h"
 #include "math/rsqrtf.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 d83b8990e21f3..d67ff5a54048a 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1503,6 +1503,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 e93450b67a28c..c1a0c7a73d9db 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2035,7 +2035,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 9ac0fc0d54a3a..4e50874fabd3d 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -97,6 +97,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 4587bfe5bf8d6..f3965dfc16c0d 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -159,6 +159,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));
 }
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 86ce007503a93..402ba2edfceec 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3158,6 +3158,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"],
@@ -5054,7 +5063,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",

>From dae1e03d862c85d28063be6f6d50faeda81e4ed5 Mon Sep 17 00:00:00 2001
From: Vachan V Y <vachanvy05 at gmail.com>
Date: Mon, 16 Feb 2026 18:35:26 +0530
Subject: [PATCH 2/2] clang format

---
 libc/shared/math.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index cf3addd23d8cd..e7c197d932344 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -109,9 +109,9 @@
 #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/logbl.h"
 #include "math/pow.h"
 #include "math/powf.h"
 #include "math/rsqrtf.h"



More information about the libc-commits mailing list