[libc-commits] [libc] [llvm] [libc][math] Refactor logbf16 to Header Only. (PR #176231)
via libc-commits
libc-commits at lists.llvm.org
Thu Jan 15 12:14:56 PST 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/176231
>From c1b9ef3a6c3750101c2faebdcb0ad4b904b38085 Mon Sep 17 00:00:00 2001
From: anonmiraj <nabilmalek48 at gmail.com>
Date: Thu, 15 Jan 2026 21:35:52 +0200
Subject: [PATCH] [libc][math] Refactor logbf16 to Header Only.
---
libc/shared/math.h | 1 +
libc/shared/math/logbf16.h | 29 ++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 8 +++++
libc/src/__support/math/logbf16.h | 33 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 4 +--
libc/src/math/generic/logbf16.cpp | 7 ++--
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 2 ++
.../llvm-project-overlay/libc/BUILD.bazel | 15 ++++++++-
9 files changed, 92 insertions(+), 8 deletions(-)
create mode 100644 libc/shared/math/logbf16.h
create mode 100644 libc/src/__support/math/logbf16.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 287f3aea1565a..aae768298d33f 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/logbf16.h"
#include "math/rsqrtf.h"
#include "math/rsqrtf16.h"
#include "math/sin.h"
diff --git a/libc/shared/math/logbf16.h b/libc/shared/math/logbf16.h
new file mode 100644
index 0000000000000..a708222236921
--- /dev/null
+++ b/libc/shared/math/logbf16.h
@@ -0,0 +1,29 @@
+//===-- Shared logbf16 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_LOGBF16_H
+#define LLVM_LIBC_SHARED_MATH_LOGBF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/logbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::logbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_LOGBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4139a1b1d3444..fe8fe00d6ddf1 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1078,3 +1078,11 @@ add_header_library(
libc.src.__support.math.sincos_eval
libc.src.__support.macros.optimization
)
+add_header_library(
+ logbf16
+ HDRS
+ logbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.properties.types
+)
diff --git a/libc/src/__support/math/logbf16.h b/libc/src/__support/math/logbf16.h
new file mode 100644
index 0000000000000..5b78291095165
--- /dev/null
+++ b/libc/src/__support/math/logbf16.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for logbf16----------------------- -*- 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_LOGBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGBF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/logbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float16 logbf16(float16 x) {
+ return fputil::logb(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6de4cf376bf02..608cc6de3c464 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2193,8 +2193,8 @@ add_entrypoint_object(
HDRS
../logbf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.logbf16
+ libc.src.errno.errno
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/logbf16.cpp b/libc/src/math/generic/logbf16.cpp
index 6e286a266a137..a782e9c109341 100644
--- a/libc/src/math/generic/logbf16.cpp
+++ b/libc/src/math/generic/logbf16.cpp
@@ -7,12 +7,9 @@
//===----------------------------------------------------------------------===//
#include "src/math/logbf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
+#include "src/__support/math/logbf16.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float16, logbf16, (float16 x)) { return fputil::logb(x); }
+LLVM_LIBC_FUNCTION(float16, logbf16, (float16 x)) { return math::logb(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index c5955ecfd54cb..5fcd8ea89c5b9 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.logbf16
)
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 20a98a1a9138c..e3f2b0c39571c 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -44,6 +44,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbf16(1.0f16));
EXPECT_FP_EQ(0x1.921fb6p+0f16, LIBC_NAMESPACE::shared::acosf16(0.0f16));
+
+ EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::logbf16(1.0f16));
}
#endif // LIBC_TYPES_HAS_FLOAT16
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c03c21b834895..4fc658d527d87 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4530,7 +4530,12 @@ libc_math_function(name = "logbl")
libc_math_function(name = "logbf128")
-libc_math_function(name = "logbf16")
+libc_math_function(
+ name = "logbf16",
+ additional_deps = [
+ ":__support_math_logbf16",
+ ],
+)
libc_math_function(name = "lrint")
@@ -7860,3 +7865,11 @@ libc_function(
":types_wchar_t",
],
)
+
+libc_support_library(
+ name = "__support_math_logbf16",
+ hdrs = ["src/__support/math/logbf16.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ],
+)
More information about the libc-commits
mailing list