[libc-commits] [libc] [llvm] [libc][math] Refactor f16fmaf to Header Only. (PR #178851)
via libc-commits
libc-commits at lists.llvm.org
Fri Jan 30 01:29:09 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
closes #<!-- -->175319
please do check for any improvements
---
Full diff: https://github.com/llvm/llvm-project/pull/178851.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/f16fmaf.h (+31)
- (modified) libc/src/__support/math/CMakeLists.txt (+10)
- (added) libc/src/__support/math/f16fmaf.h (+33)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-2)
- (modified) libc/src/math/generic/f16fmaf.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+3)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+12-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index b58d29d1ee480..7757c18056ed7 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -60,6 +60,7 @@
#include "math/expm1f.h"
#include "math/expm1f16.h"
#include "math/f16fma.h"
+#include "math/f16fmaf.h"
#include "math/f16fmal.h"
#include "math/f16sqrt.h"
#include "math/f16sqrtl.h"
diff --git a/libc/shared/math/f16fmaf.h b/libc/shared/math/f16fmaf.h
new file mode 100644
index 0000000000000..bafbb4b4803b6
--- /dev/null
+++ b/libc/shared/math/f16fmaf.h
@@ -0,0 +1,31 @@
+//===-- Shared f16fmaf 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_F16FMAF_H
+#define LLVM_LIBC_SHARED_MATH_F16FMAF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16fmaf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace shared {
+
+using math::f16fmaf;
+
+} // namespace shared
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16FMAF_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 58e4040911f8e..f837d2f22776f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -675,6 +675,16 @@ add_header_library(
libc.include.llvm-libc-macros.float16_macros
)
+add_header_library(
+ f16fmaf
+ HDRS
+ f16fmaf.h
+ DEPENDS
+ libc.src.__support.macros.config
+ libc.src.__support.FPUtil.fma
+ libc.include.llvm-libc-macros.float16_macros
+)
+
add_header_library(
f16fmal
HDRS
diff --git a/libc/src/__support/math/f16fmaf.h b/libc/src/__support/math/f16fmaf.h
new file mode 100644
index 0000000000000..e4e0e346bb8d3
--- /dev/null
+++ b/libc/src/__support/math/f16fmaf.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for f16fmaf -----------------------*- 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_F16FMAF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static float16 f16fmaf(float x, float y, float z) {
+ return fputil::fma<float16>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 1b18388ed60f8..266a71ba403d3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5038,8 +5038,7 @@ add_entrypoint_object(
HDRS
../f16fmaf.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.fma
+ libc.src.__support.math.f16fmaf
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/f16fmaf.cpp b/libc/src/math/generic/f16fmaf.cpp
index bd0b56b1ab31b..1c2c6d80934c8 100644
--- a/libc/src/math/generic/f16fmaf.cpp
+++ b/libc/src/math/generic/f16fmaf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16fmaf.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16fmaf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16fmaf, (float x, float y, float z)) {
- return fputil::fma<float16>(x, y, z);
+ return math::f16fmaf(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 07ccd0ca1bc4b..a1db7c05331bc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -56,6 +56,7 @@ add_fp_unittest(
libc.src.__support.math.expf
libc.src.__support.math.expf16
libc.src.__support.math.f16fma
+ libc.src.__support.math.f16fmaf
libc.src.__support.math.f16fmal
libc.src.__support.math.f16sqrt
libc.src.__support.math.f16sqrtl
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index ec70025f0f4ea..d404b1b4afc9d 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -38,6 +38,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(float16(10.0), LIBC_NAMESPACE::shared::f16fma(2.0, 3.0, 4.0));
+ EXPECT_FP_EQ(float16(10.0),
+ LIBC_NAMESPACE::shared::f16fmaf(2.0f, 3.0f, 4.0f));
+
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrt(0.0));
EXPECT_FP_EQ(float16(10.0),
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 83b752ce1214b..27646783247e0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2908,6 +2908,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_f16fmaf",
+ hdrs = ["src/__support/math/f16fmaf.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_fma",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
libc_support_library(
name = "__support_math_f16fmal",
hdrs = ["src/__support/math/f16fmal.h"],
@@ -4438,7 +4449,7 @@ libc_math_function(
libc_math_function(
name = "f16fmaf",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_f16fmaf",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/178851
More information about the libc-commits
mailing list