[libc-commits] [libc] [llvm] [libc][math] Refactor ffmaf128 into a header only. (PR #177873)
via libc-commits
libc-commits at lists.llvm.org
Mon Jan 26 21:07:22 PST 2026
https://github.com/parthtyagi27 updated https://github.com/llvm/llvm-project/pull/177873
>From b4e978a5e0f8bdb55a4b28f550f15d244dd27cf1 Mon Sep 17 00:00:00 2001
From: Parth Tyagi <parth.27 at outlook.com>
Date: Sun, 25 Jan 2026 12:07:23 -0600
Subject: [PATCH 1/2] init commit to refactor ffmaf128 into a header only,
compiles locally fails the overlay test on tanhf
---
libc/shared/math.h | 1 +
libc/shared/math/ffmaf128.h | 23 ++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 8 ++++++
libc/src/__support/math/ffmaf128.h | 27 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 2 +-
libc/src/math/generic/ffmaf128.cpp | 11 ++++----
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
.../llvm-project-overlay/libc/BUILD.bazel | 10 ++++++-
9 files changed, 77 insertions(+), 7 deletions(-)
create mode 100644 libc/shared/math/ffmaf128.h
create mode 100644 libc/src/__support/math/ffmaf128.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 7fb4c43f509c4..22ad93765fd1a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -60,6 +60,7 @@
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
+#include "math/ffmaf128.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
new file mode 100644
index 0000000000000..f468312a8234f
--- /dev/null
+++ b/libc/shared/math/ffmaf128.h
@@ -0,0 +1,23 @@
+//===-- 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 "shared/libc_common.h"
+#include "src/__support/math/ffmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ffmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FFMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 741da7432c94f..982c1333c41ac 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -594,6 +594,14 @@ add_header_library(
libc.src.__support.math.exp10_float16_constants
)
+add_header_library(
+ ffmaf128
+ HDRS
+ ffmaf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
add_header_library(
frexpf128
HDRS
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
new file mode 100644
index 0000000000000..8c6fdd2690879
--- /dev/null
+++ b/libc/src/__support/math/ffmaf128.h
@@ -0,0 +1,27 @@
+//===-- 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 "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 constexpr float ffmaf128(float128 x, float128 y, float128 z) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 9c0da076b6cf0..7543ddee40a42 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3438,7 +3438,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..442ecd0bb73e6 100644
--- a/libc/src/math/generic/ffmaf128.cpp
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -7,14 +7,15 @@
//===----------------------------------------------------------------------===//
#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/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);
+ // return fputil::fma<float>(x, y, 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 0f23162798a8b..cfa0c744e75bc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -53,6 +53,7 @@ add_fp_unittest(
libc.src.__support.math.exp10f16
libc.src.__support.math.expf
libc.src.__support.math.expf16
+ 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 f823d414e2afd..8103bfac3ee42 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -108,6 +108,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf128(float128(-8), 5));
+ EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::ffmaf128(float128(0.0), float128(0.0), float128(0.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 210c25dddd0b9..f1e8f1a17d4f2 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2804,6 +2804,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmaf128",
+ hdrs = ["src/__support/math/ffmaf128.h"],
+ deps = [
+ ":__support_macros_properties_types",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4013,7 +4021,7 @@ libc_math_function(
libc_math_function(
name = "ffmaf128",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmaf128",
],
)
>From 0882664b068bcd15fa41a2cc99652b0e3e54a3d1 Mon Sep 17 00:00:00 2001
From: Parth Tyagi <parth.27 at outlook.com>
Date: Mon, 26 Jan 2026 23:05:31 -0600
Subject: [PATCH 2/2] changes from pr review, fixed comment length in headers,
removed commented out code, added dependency in the bazel file
---
libc/shared/math.h | 2 +-
libc/shared/math/ffmaf128.h | 2 +-
libc/src/__support/math/ffmaf128.h | 2 +-
libc/src/math/generic/ffmaf128.cpp | 4 ----
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
5 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 22ad93765fd1a..6280cf9409caf 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -57,10 +57,10 @@
#include "math/expm1.h"
#include "math/expm1f.h"
#include "math/expm1f16.h"
+#include "math/ffmaf128.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
-#include "math/ffmaf128.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
index f468312a8234f..e07dfcf1a45d7 100644
--- a/libc/shared/math/ffmaf128.h
+++ b/libc/shared/math/ffmaf128.h
@@ -1,4 +1,4 @@
-//===-- Shared ffmaf128 function ------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
index 8c6fdd2690879..91a33608acd0b 100644
--- a/libc/src/__support/math/ffmaf128.h
+++ b/libc/src/__support/math/ffmaf128.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for ffmaf128 --------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/libc/src/math/generic/ffmaf128.cpp b/libc/src/math/generic/ffmaf128.cpp
index 442ecd0bb73e6..2ddb4192ffb31 100644
--- a/libc/src/math/generic/ffmaf128.cpp
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -7,14 +7,10 @@
//===----------------------------------------------------------------------===//
#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);
return math::ffmaf128(x, y, z);
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index f1e8f1a17d4f2..9726dae552ab7 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2808,6 +2808,7 @@ libc_support_library(
name = "__support_math_ffmaf128",
hdrs = ["src/__support/math/ffmaf128.h"],
deps = [
+ ":__support_fputil_fma",
":__support_macros_properties_types",
],
)
More information about the libc-commits
mailing list