[libc-commits] [libc] [llvm] [libc][math] Refactor f16fmaf128 to Header Only (PR #177850)
via libc-commits
libc-commits at lists.llvm.org
Sun Jan 25 03:23:30 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
PR for #<!-- -->175318
In preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
please do check for any edits
---
Full diff: https://github.com/llvm/llvm-project/pull/177850.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/f16fmaf128.h (+30)
- (modified) libc/src/__support/math/CMakeLists.txt (+11)
- (added) libc/src/__support/math/f16fmaf128.h (+34)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-2)
- (modified) libc/src/math/generic/f16fmaf128.cpp (+3-4)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+5)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+13-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bad2b07ecb993..ffd7aabfa5303 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -59,6 +59,7 @@
#include "math/expm1f.h"
#include "math/expm1f16.h"
#include "math/f16fma.h"
+#include "math/f16fmaf128.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
diff --git a/libc/shared/math/f16fmaf128.h b/libc/shared/math/f16fmaf128.h
new file mode 100644
index 0000000000000..31c99d3ff5e22
--- /dev/null
+++ b/libc/shared/math/f16fmaf128.h
@@ -0,0 +1,30 @@
+//===-- Shared f16fmaf128 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_F16FMAF128_H
+#define LLVM_LIBC_SHARED_MATH_F16FMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+
+#include "src/__support/math/f16fmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16fmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_F16FMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index bcc5b1024b8da..e0966d5edc2af 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -648,6 +648,17 @@ add_header_library(
libc.include.llvm-libc-macros.float16_macros
)
+add_header_library(
+ f16fmaf128
+ HDRS
+ f16fmaf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ libc.include.llvm-libc-macros.float128_macros
+)
+
add_header_library(
ilogbf16
HDRS
diff --git a/libc/src/__support/math/f16fmaf128.h b/libc/src/__support/math/f16fmaf128.h
new file mode 100644
index 0000000000000..605c865f580aa
--- /dev/null
+++ b/libc/src/__support/math/f16fmaf128.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for f16fmaf128 ------------------------*- 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_F16FMAF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static float16 f16fmaf128(float128 x, float128 y, float128 z) {
+ return fputil::fma<float16>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6e58434415ead..b6cde300bc836 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5141,8 +5141,7 @@ add_entrypoint_object(
HDRS
../f16fmaf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.fma
+ libc.src.__support.math.f16fmaf128
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/f16fmaf128.cpp b/libc/src/math/generic/f16fmaf128.cpp
index 5c4823c47e79f..75e52a139779b 100644
--- a/libc/src/math/generic/f16fmaf128.cpp
+++ b/libc/src/math/generic/f16fmaf128.cpp
@@ -7,14 +7,13 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16fmaf128.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16fmaf128.h"
+
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16fmaf128, (float128 x, float128 y, float128 z)) {
- return fputil::fma<float16>(x, y, z);
+ return math::f16fmaf128(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 3fc36ed0c2198..acb078dd8aa33 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -55,6 +55,7 @@ add_fp_unittest(
libc.src.__support.math.expf
libc.src.__support.math.expf16
libc.src.__support.math.f16fma
+ libc.src.__support.math.f16fmaf128
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 45ba79de87226..a956412360ad6 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -34,6 +34,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::expm1f16(0.0f16));
EXPECT_FP_EQ(float16(10.0), LIBC_NAMESPACE::shared::f16fma(2.0, 3.0, 4.0));
+
+ #if defined(LIBC_TYPES_HAS_FLOAT128)
+ EXPECT_FP_EQ(float16(10.0), LIBC_NAMESPACE::shared::f16fmaf128(2.0, 3.0, 4.0));
+ #endif
ASSERT_FP_EQ(float16(8 << 5), LIBC_NAMESPACE::shared::ldexpf16(8.0f16, 5));
ASSERT_FP_EQ(float16(-1 * (8 << 5)),
@@ -131,6 +135,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf128(float128(-8), 5));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::logbf128(float128(1.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 2819824a11857..200b8b1c646f7 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2877,6 +2877,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_f16fmaf128",
+ hdrs = ["src/__support/math/f16fmaf128.h"],
+ deps = [
+ ":__support_fputil_fma",
+ ":__support_macros_config",
+ ":__support_common",
+ ":llvm_libc_macros_float128_macros",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4154,7 +4165,8 @@ libc_math_function(
libc_math_function(
name = "f16fmaf128",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_f16fmaf128",
+ ":llvm_libc_types_float128",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/177850
More information about the libc-commits
mailing list