[libc-commits] [libc] [llvm] [libc][math] Refactored bf16fmaf to Header Only (PR #181919)
via libc-commits
libc-commits at lists.llvm.org
Tue Feb 17 14:04:04 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Abhijeet (abhijeetsharma200)
<details>
<summary>Changes</summary>
Fixes #<!-- -->181626
---
Full diff: https://github.com/llvm/llvm-project/pull/181919.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/bf16fmaf.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+11)
- (added) libc/src/__support/math/bf16fmaf.h (+26)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-5)
- (modified) libc/src/math/generic/bf16fmaf.cpp (+2-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 (+15)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 17d4c990efccd..fa17392e35740 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -33,6 +33,7 @@
#include "math/bf16add.h"
#include "math/bf16addf.h"
#include "math/bf16addf128.h"
+#include "math/bf16fmaf.h"
#include "math/canonicalize.h"
#include "math/canonicalizebf16.h"
#include "math/canonicalizef.h"
diff --git a/libc/shared/math/bf16fmaf.h b/libc/shared/math/bf16fmaf.h
new file mode 100644
index 0000000000000..bddf5c61b3b6e
--- /dev/null
+++ b/libc/shared/math/bf16fmaf.h
@@ -0,0 +1,23 @@
+//===-- Shared bf16fmaf 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_BF16FMAF_H
+#define LLVM_LIBC_SHARED_MATH_BF16FMAF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/bf16fmaf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::bf16fmaf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_BF16FMAF_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 520e7da040fe3..5ef84935fde5d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -361,6 +361,17 @@ add_header_library(
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
+
+add_header_library(
+ bf16fmaf
+ HDRS
+ bf16fmaf.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fma
+ libc.src.__support.macros.config
+)
+
add_header_library(
canonicalize
HDRS
diff --git a/libc/src/__support/math/bf16fmaf.h b/libc/src/__support/math/bf16fmaf.h
new file mode 100644
index 0000000000000..a7072bcb18418
--- /dev/null
+++ b/libc/src/__support/math/bf16fmaf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for bf16fmaf ----------------------*- 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_BF16FMAF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16FMAF_H
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE bfloat16 bf16fmaf(float x, float y, float z) {
+ return fputil::fma<bfloat16>(x, y, z);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16FMAF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3a0f75b4ce976..3d9a4ed001fd9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5244,11 +5244,7 @@ add_entrypoint_object(
HDRS
../bf16fmaf.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.fma
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.bf16fmaf
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/bf16fmaf.cpp b/libc/src/math/generic/bf16fmaf.cpp
index 739691cc50117..331a503b3a79f 100644
--- a/libc/src/math/generic/bf16fmaf.cpp
+++ b/libc/src/math/generic/bf16fmaf.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/bf16fmaf.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/bf16fmaf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, bf16fmaf, (float x, float y, float z)) {
- return fputil::fma<bfloat16>(x, y, z);
+ return math::bf16fmaf(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 595584f6e9118..00087f54628d4 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -29,6 +29,7 @@ add_fp_unittest(
libc.src.__support.math.bf16add
libc.src.__support.math.bf16addf
libc.src.__support.math.bf16addf128
+ libc.src.__support.math.bf16fmaf
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 faaf1a1c20e67..ce7386199bfb1 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -238,4 +238,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
&canonicalizebf16_x));
EXPECT_FP_EQ(bfloat16(0.0), canonicalizebf16_cx);
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf(2.0f, 3.0f));
+ EXPECT_FP_EQ(bfloat16(10.0),
+ LIBC_NAMESPACE::shared::bf16fmaf(2.0f, 3.0f, 4.0f));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 9afe425c3bc0a..ad7f7d664a17f 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2665,6 +2665,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_bf16fmaf",
+ hdrs = ["src/__support/math/bf16fmaf.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_fma",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_canonicalize",
hdrs = ["src/__support/math/canonicalize.h"],
@@ -4443,6 +4453,11 @@ libc_math_function(
additional_deps = [":__support_math_bf16addf128"],
)
+libc_math_function(
+ name = "bf16fmaf",
+ additional_deps = [":__support_math_bf16fmaf"],
+)
+
libc_math_function(
name = "canonicalize",
additional_deps = [
``````````
</details>
https://github.com/llvm/llvm-project/pull/181919
More information about the libc-commits
mailing list