[libc-commits] [libc] [llvm] Refactor logbbf16 to header (PR #189194)
via libc-commits
libc-commits at lists.llvm.org
Sat Mar 28 13:34:08 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
This PR intends to refactor the logb bfloat16 function to the header with shared_math tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/189194.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/logbbf16.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+11)
- (added) libc/src/__support/math/logbbf16.h (+27)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-5)
- (modified) libc/src/math/generic/logbbf16.cpp (+4-5)
- (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 (+16)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 71da66d37baba..f3aa3edfbcee4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -192,6 +192,7 @@
#include "math/log2f16.h"
#include "math/log_bf16.h"
#include "math/logb.h"
+#include "math/logbbf16.h"
#include "math/logbf.h"
#include "math/logbf128.h"
#include "math/logbf16.h"
diff --git a/libc/shared/math/logbbf16.h b/libc/shared/math/logbbf16.h
new file mode 100644
index 0000000000000..b71009ec7dd45
--- /dev/null
+++ b/libc/shared/math/logbbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared logbbf16 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_LOGBBF16_H
+#define LLVM_LIBC_SHARED_MATH_LOGBBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/logbbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::logbbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_LOGBBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 187ff4f124b20..ba018e2a79158 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2911,6 +2911,17 @@ add_header_library(
libc.src.__support.macros.properties.types
)
+add_header_library(
+ logbbf16
+ HDRS
+ logbbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_header_library(
logbf16
HDRS
diff --git a/libc/src/__support/math/logbbf16.h b/libc/src/__support/math/logbbf16.h
new file mode 100644
index 0000000000000..c5300b44ad3c1
--- /dev/null
+++ b/libc/src/__support/math/logbbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for logbbf16 ----------------------*- 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_LOGBBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGBBF16_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE bfloat16 logbbf16(bfloat16 x) { return fputil::logb(x); }
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGBBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index ad05fd83cadb9..05d112a81ab7c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2029,11 +2029,7 @@ add_entrypoint_object(
HDRS
../logbbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.manipulation_functions
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.logbbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/logbbf16.cpp b/libc/src/math/generic/logbbf16.cpp
index 5a43ddfafde75..08aa04e73f5a2 100644
--- a/libc/src/math/generic/logbbf16.cpp
+++ b/libc/src/math/generic/logbbf16.cpp
@@ -7,13 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/logbbf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/logbbf16.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(bfloat16, logbbf16, (bfloat16 x)) { return fputil::logb(x); }
+LLVM_LIBC_FUNCTION(bfloat16, logbbf16, (bfloat16 x)) {
+ return math::logbbf16(x);
+}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index b807ea9ac602f..1cb72c29dba31 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -183,6 +183,7 @@ add_fp_unittest(
libc.src.__support.math.log2f
libc.src.__support.math.log2f16
libc.src.__support.math.logbf
+ libc.src.__support.math.logbbf16
libc.src.__support.math.logbf128
libc.src.__support.math.logbf16
libc.src.__support.math.logf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 31b14bbe204c7..58e7188f0280a 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -459,6 +459,8 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(5.0),
LIBC_NAMESPACE::shared::hypotbf16(bfloat16(4.0), bfloat16(3.0)));
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::logbbf16(bfloat16(1.0f)));
+
bfloat16 setpayloadbf16_res = bfloat16(0.0);
EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadbf16(&setpayloadbf16_res,
bfloat16(0.0)));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 29792cec1149e..7e1db9e64c0a5 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5289,6 +5289,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_logbbf16",
+ hdrs = ["src/__support/math/logbbf16.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_logbf",
hdrs = ["src/__support/math/logbf.h"],
@@ -7984,6 +7995,11 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "logbbf16",
+ additional_deps = [":__support_math_logbbf16"],
+)
+
libc_math_function(
name = "logbf",
additional_deps = [":__support_math_logbf"],
``````````
</details>
https://github.com/llvm/llvm-project/pull/189194
More information about the libc-commits
mailing list