[libc-commits] [libc] [llvm] [libc][math] Refactor ffmaf128 implementation to header-only in src/__support/math folder. (PR #177843)
via libc-commits
libc-commits at lists.llvm.org
Sat Jan 24 23:29:50 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Aditya Trivedi (adit4443ya)
<details>
<summary>Changes</summary>
Part of https://github.com/llvm/llvm-project/issues/147386
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
---
Full diff: https://github.com/llvm/llvm-project/pull/177843.diff
10 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/ffmaf128.h (+29)
- (modified) libc/src/__support/math/CMakeLists.txt (+9)
- (added) libc/src/__support/math/ffmaf128.h (+33)
- (modified) libc/src/math/ffmaf128.h (+1-1)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-1)
- (modified) libc/src/math/generic/ffmaf128.cpp (+3-5)
- (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 (+9-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 5126e46c9772e..5496cbe934be7 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -61,6 +61,7 @@
#include "math/expm1f16.h"
#include "math/f16fma.h"
#include "math/f16fmal.h"
+#include "math/ffmaf128.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
new file mode 100644
index 0000000000000..5c76ed36a28e4
--- /dev/null
+++ b/libc/shared/math/ffmaf128.h
@@ -0,0 +1,29 @@
+//===-- Shared ffmaf128 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_FFMAF128_H
+#define LLVM_LIBC_SHARED_MATH_FFMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/ffmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ffmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FFMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index d18ebc03ba7b8..707e94a60daa9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -610,6 +610,15 @@ add_header_library(
libc.src.__support.FPUtil.generic.sqrt
)
+add_header_library(
+ ffmaf128
+ HDRS
+ ffmaf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
+
add_header_library(
inv_trigf_utils
HDRS
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
new file mode 100644
index 0000000000000..fd300d65bc1d2
--- /dev/null
+++ b/libc/src/__support/math/ffmaf128.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for ffmaf128 ----------------------*- 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_FFMAF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FFMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float128 ffmaf128(float128 x, float128 y,
+ float128 z) {
+ return fputil::fma<float128>(x, y, z);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAF128_H
diff --git a/libc/src/math/ffmaf128.h b/libc/src/math/ffmaf128.h
index 741099780b8d5..332b3b5709ecc 100644
--- a/libc/src/math/ffmaf128.h
+++ b/libc/src/math/ffmaf128.h
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE_DECL {
-float ffmaf128(float128 x, float128 y, float128 z);
+float128 ffmaf128(float128 x, float128 y, float128 z);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3addfab6c6603..0f5fffb9d0865 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3373,7 +3373,7 @@ add_entrypoint_object(
../ffmaf128.h
DEPENDS
libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.fma
+ libc.src.__support.math.ffmaf128
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ffmaf128.cpp b/libc/src/math/generic/ffmaf128.cpp
index 55da93020faf3..70e01ce2b3b71 100644
--- a/libc/src/math/generic/ffmaf128.cpp
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ffmaf128.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ffmaf128.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, ffmaf128, (float128 x, float128 y, float128 z)) {
- return fputil::fma<float>(x, y, z);
+LLVM_LIBC_FUNCTION(float128, ffmaf128, (float128 x, float128 y, float128 z)) {
+ return math::ffmaf128(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index dabf5f6b168cc..f5b44b038d534 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -57,6 +57,7 @@ add_fp_unittest(
libc.src.__support.math.expf16
libc.src.__support.math.f16fma
libc.src.__support.math.f16fmal
+ libc.src.__support.math.ffmaf128
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 cd389c41cb7b2..f25c62721aa0b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -127,6 +127,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ(float128(0x0p+0),
LIBC_NAMESPACE::shared::atan2f128(float128(0.0), float128(0.0)));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::fsqrtf128(float128(1.0f)));
+ EXPECT_FP_EQ(float128(0x0p+0),
+ LIBC_NAMESPACE::shared::ffmaf128(float128(0.0), float128(0.0),
+ float128(0.0)));
EXPECT_FP_EQ_ALL_ROUNDING(float128(0.75), LIBC_NAMESPACE::shared::frexpf128(
float128(24), &exponent));
EXPECT_EQ(exponent, 5);
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 346864d2276c0..de99e6b25cf83 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2915,6 +2915,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmaf128",
+ hdrs = ["src/__support/math/ffmaf128.h"],
+ deps = [
+ ":__support_fputil_fma",
+ ],
+)
+
libc_support_library(
name = "__support_math_inv_trigf_utils",
hdrs = ["src/__support/math/inv_trigf_utils.h"],
@@ -4309,7 +4317,7 @@ libc_math_function(
libc_math_function(
name = "ffmaf128",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmaf128",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/177843
More information about the libc-commits
mailing list