[libc-commits] [libc] [llvm] [libc][math] Refactor bf16subl family to header-only (PR #194498)
via libc-commits
libc-commits at lists.llvm.org
Mon Apr 27 17:03:12 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anonmiraj (AnonMiraj)
<details>
<summary>Changes</summary>
Refactors the bf16subl math family to be header-only.
Closes
Target Functions:
- bf16subl
---
Full diff: https://github.com/llvm/llvm-project/pull/194498.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/bf16subl.h (+22)
- (modified) libc/src/__support/math/CMakeLists.txt (+9)
- (added) libc/src/__support/math/bf16subl.h (+27)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-5)
- (modified) libc/src/math/generic/bf16subl.cpp (+2-5)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+1)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+15)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 80078afea59ba..98f011dc0db07 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -57,6 +57,7 @@
#include "math/bf16sub.h"
#include "math/bf16subf.h"
#include "math/bf16subf128.h"
+#include "math/bf16subl.h"
#include "math/canonicalize.h"
#include "math/canonicalizebf16.h"
#include "math/canonicalizef.h"
diff --git a/libc/shared/math/bf16subl.h b/libc/shared/math/bf16subl.h
new file mode 100644
index 0000000000000..2b2a270fb8492
--- /dev/null
+++ b/libc/shared/math/bf16subl.h
@@ -0,0 +1,22 @@
+//===-- Shared bf16subl 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_BF16SUBL_H
+#define LLVM_LIBC_SHARED_MATH_BF16SUBL_H
+
+#include "src/__support/math/bf16subl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::bf16subl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_BF16SUBL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 67c3b28109987..9c61f6322c128 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -631,6 +631,15 @@ add_header_library(
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.generic.add_sub
)
+add_header_library(
+ bf16subl
+ HDRS
+ bf16subl.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.config
+)
add_header_library(
canonicalize
diff --git a/libc/src/__support/math/bf16subl.h b/libc/src/__support/math/bf16subl.h
new file mode 100644
index 0000000000000..93fde4dfa3f56
--- /dev/null
+++ b/libc/src/__support/math/bf16subl.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for bf16subl ----------------------*- 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_BF16SUBL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16SUBL_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 bf16subl(long double x, long double y) {
+ return fputil::generic::sub<bfloat16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16SUBL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 0b91d1d4404ab..fec77a8fcaf98 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5236,11 +5236,7 @@ add_entrypoint_object(
HDRS
../bf16subl.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.generic.add_sub
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.bf16subl
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/bf16subl.cpp b/libc/src/math/generic/bf16subl.cpp
index d3a970cade922..faca50d36e906 100644
--- a/libc/src/math/generic/bf16subl.cpp
+++ b/libc/src/math/generic/bf16subl.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/bf16subl.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/bf16subl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, bf16subl, (long double x, long double y)) {
- return fputil::generic::sub<bfloat16>(x, y);
+ return math::bf16subl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 8f324ae814f71..f95622e943bc5 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -54,6 +54,7 @@ add_fp_unittest(
libc.src.__support.math.bf16sub
libc.src.__support.math.bf16subf
libc.src.__support.math.bf16subf128
+ libc.src.__support.math.bf16subl
libc.src.__support.math.canonicalize
libc.src.__support.math.canonicalizebf16
libc.src.__support.math.canonicalizef
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index d9d5c2c621d4a..bbda53faf353b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -320,6 +320,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0.0L, canonicalizel_cx);
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addl(2.0L, 3.0L));
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16subl(0.0L, 0.0L));
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divl(6.0L, 3.0L));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16mull(0.0L, 0.0L));
EXPECT_FP_EQ(bfloat16(10.0),
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e09828d682d98..edd3eb1878fc9 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3710,6 +3710,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_bf16subl",
+ hdrs = ["src/__support/math/bf16subl.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_canonicalize",
hdrs = ["src/__support/math/canonicalize.h"],
@@ -7082,6 +7092,11 @@ libc_math_function(
additional_deps = [":__support_math_bf16subf128"],
)
+libc_math_function(
+ name = "bf16subl",
+ additional_deps = [":__support_math_bf16subl"],
+)
+
libc_math_function(
name = "bf16fma",
additional_deps = [":__support_math_bf16fma"],
``````````
</details>
https://github.com/llvm/llvm-project/pull/194498
More information about the libc-commits
mailing list