[libc-commits] [libc] [llvm] [libc][math] Refactor logbf128 to Header Only. (PR #176234)

via libc-commits libc-commits at lists.llvm.org
Thu Jan 15 11:58:31 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Anonmiraj (AnonMiraj)

<details>
<summary>Changes</summary>

builds with both Clang and GCC 12.2.

Closes #<!-- -->175364.

CC @<!-- -->bassiounix

---
Full diff: https://github.com/llvm/llvm-project/pull/176234.diff


9 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/logbf128.h (+30) 
- (modified) libc/src/__support/math/CMakeLists.txt (+9) 
- (added) libc/src/__support/math/logbf128.h (+34) 
- (modified) libc/src/math/generic/CMakeLists.txt (+2-2) 
- (modified) libc/src/math/generic/logbf128.cpp (+1-4) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+2) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+12-1) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 287f3aea1565a..885deceaacea5 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -65,6 +65,7 @@
 #include "math/ldexpf128.h"
 #include "math/ldexpf16.h"
 #include "math/log.h"
+#include "math/logbf128.h"
 #include "math/rsqrtf.h"
 #include "math/rsqrtf16.h"
 #include "math/sin.h"
diff --git a/libc/shared/math/logbf128.h b/libc/shared/math/logbf128.h
new file mode 100644
index 0000000000000..c73725460922a
--- /dev/null
+++ b/libc/shared/math/logbf128.h
@@ -0,0 +1,30 @@
+//===-- Shared logbf128 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_LOGBF128_H
+#define LLVM_LIBC_SHARED_MATH_LOGBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/logbf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::logbf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_LOGBF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4139a1b1d3444..f5d0b5f3de11d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1078,3 +1078,12 @@ add_header_library(
     libc.src.__support.math.sincos_eval
     libc.src.__support.macros.optimization
 )
+
+add_header_library(
+  logbf128
+  HDRS
+    logbf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.properties.types
+)
diff --git a/libc/src/__support/math/logbf128.h b/libc/src/__support/math/logbf128.h
new file mode 100644
index 0000000000000..d18efc5077ade
--- /dev/null
+++ b/libc/src/__support/math/logbf128.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for logbf128-----------------------*- 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_LOGBF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#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 static constexpr float128 logbf128(float128 x) {
+  return fputil::logb(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGBF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6de4cf376bf02..1fa6fa8a57e9c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2204,8 +2204,8 @@ add_entrypoint_object(
   HDRS
     ../logbf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.logbf128
+    libc.src.errno.errno
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/logbf128.cpp b/libc/src/math/generic/logbf128.cpp
index af8348736c9f4..de31befd18c75 100644
--- a/libc/src/math/generic/logbf128.cpp
+++ b/libc/src/math/generic/logbf128.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/logbf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
+#include "src/__support/math/logbf128.h"
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, logbf128, (float128 x)) { return fputil::logb(x); }
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index c5955ecfd54cb..f58ed4593fe20 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -64,4 +64,5 @@ add_fp_unittest(
     libc.src.__support.math.rsqrtf
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.sin
+    libc.src.__support.math.logbf128
 )
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 20a98a1a9138c..1c11ac93f5b6a 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -111,6 +111,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
   ASSERT_FP_EQ(float128(-1 * (8 << 5)),
                LIBC_NAMESPACE::shared::ldexpf128(float128(-8), 5));
+
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::logbf128(float128(1.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c03c21b834895..c0eeeacb8a766 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4528,7 +4528,10 @@ libc_math_function(name = "logbf")
 
 libc_math_function(name = "logbl")
 
-libc_math_function(name = "logbf128")
+libc_math_function(
+    name = "logbf128",
+    additional_deps = [":__support_math_logbf128"],
+)
 
 libc_math_function(name = "logbf16")
 
@@ -7860,3 +7863,11 @@ libc_function(
         ":types_wchar_t",
     ],
 )
+
+libc_support_library(
+    name = "__support_math_logbf128",
+    hdrs = ["src/__support/math/logbf128.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+    ],
+)

``````````

</details>


https://github.com/llvm/llvm-project/pull/176234


More information about the libc-commits mailing list