[libc-commits] [libc] 2693adf - [libc][math] Refactor bf16addf128 to header only (#181058)
via libc-commits
libc-commits at lists.llvm.org
Fri Feb 13 21:49:23 PST 2026
Author: Abhijeet
Date: 2026-02-14T05:49:18Z
New Revision: 2693adf197d778f0c0c4d05efd2d8c1419c2cc73
URL: https://github.com/llvm/llvm-project/commit/2693adf197d778f0c0c4d05efd2d8c1419c2cc73
DIFF: https://github.com/llvm/llvm-project/commit/2693adf197d778f0c0c4d05efd2d8c1419c2cc73.diff
LOG: [libc][math] Refactor bf16addf128 to header only (#181058)
Resolves #181018
Part of #147386
Added:
libc/shared/math/bf16addf128.h
libc/src/__support/math/bf16addf128.h
Modified:
libc/shared/math.h
libc/src/__support/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/bf16addf128.cpp
libc/test/shared/CMakeLists.txt
libc/test/shared/shared_math_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/shared/math.h b/libc/shared/math.h
index eab584aea4e60..3949b1210e317 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -30,6 +30,7 @@
#include "math/atanf16.h"
#include "math/atanhf.h"
#include "math/atanhf16.h"
+#include "math/bf16addf128.h"
#include "math/cbrt.h"
#include "math/cbrtf.h"
#include "math/cos.h"
diff --git a/libc/shared/math/bf16addf128.h b/libc/shared/math/bf16addf128.h
new file mode 100644
index 0000000000000..98b985de7a999
--- /dev/null
+++ b/libc/shared/math/bf16addf128.h
@@ -0,0 +1,29 @@
+//===-- Shared bf16addf128 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_BF16ADDF128_H
+#define LLVM_LIBC_SHARED_MATH_BF16ADDF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/bf16addf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::bf16addf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_BF16ADDF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4e6e9bd6233ec..d83b8990e21f3 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -332,6 +332,16 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ bf16addf128
+ HDRS
+ bf16addf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.config
+)
+
add_header_library(
cbrt
HDRS
diff --git a/libc/src/__support/math/bf16addf128.h b/libc/src/__support/math/bf16addf128.h
new file mode 100644
index 0000000000000..2bd1d10e38d7d
--- /dev/null
+++ b/libc/src/__support/math/bf16addf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for bf16addf128 -------------------*- 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_BF16ADDF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_BF16ADDF128_H
+
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#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 bfloat16 bf16addf128(float128 x, float128 y) {
+ return fputil::generic::add<bfloat16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_BF16ADDF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 98d79e3b3826d..e93450b67a28c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5207,11 +5207,7 @@ add_entrypoint_object(
HDRS
../bf16addf128.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.bf16addf128
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/bf16addf128.cpp b/libc/src/math/generic/bf16addf128.cpp
index 03f70af82e892..cc76e0468f027 100644
--- a/libc/src/math/generic/bf16addf128.cpp
+++ b/libc/src/math/generic/bf16addf128.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/bf16addf128.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/bf16addf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, bf16addf128, (float128 x, float128 y)) {
- return fputil::generic::add<bfloat16>(x, y);
+ return math::bf16addf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index ef4d78584ef77..9ac0fc0d54a3a 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -26,6 +26,7 @@ add_fp_unittest(
libc.src.__support.math.atanf16
libc.src.__support.math.atanhf
libc.src.__support.math.atanhf16
+ libc.src.__support.math.bf16addf128
libc.src.__support.math.cbrt
libc.src.__support.math.cbrtf
libc.src.__support.math.cos
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 1c8463d9321fc..4587bfe5bf8d6 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -186,6 +186,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
LIBC_NAMESPACE::shared::sqrtf128(float128(1.0)));
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbf128(float128(1.0)));
+
+ EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf128(
+ float128(2.0), float128(3.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 e08d759f063b0..86ce007503a93 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2635,6 +2635,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_bf16addf128",
+ hdrs = ["src/__support/math/bf16addf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_cbrt",
hdrs = ["src/__support/math/cbrt.h"],
@@ -4253,6 +4263,11 @@ libc_math_function(
additional_deps = [":__support_math_atanhf16"],
)
+libc_math_function(
+ name = "bf16addf128",
+ additional_deps = [":__support_math_bf16addf128"],
+)
+
libc_math_function(name = "canonicalize")
libc_math_function(name = "canonicalizef")
More information about the libc-commits
mailing list