[libc] [llvm] [libc][math] Refactor ffmaf128 into a header only. (PR #184751)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 23:34:02 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Zorojuro (Sukumarsawant)

<details>
<summary>Changes</summary>

closes #<!-- -->175325 
part of #<!-- -->147386


---
Full diff: https://github.com/llvm/llvm-project/pull/184751.diff


9 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/ffmaf128.h (+29) 
- (modified) libc/src/__support/math/CMakeLists.txt (+11) 
- (added) libc/src/__support/math/ffmaf128.h (+34) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-2) 
- (modified) libc/src/math/generic/ffmaf128.cpp (+2-4) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+2) 
- (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 a7d735ffa1746..ede0ebd5371ac 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -124,6 +124,7 @@
 #include "math/fdimf16.h"
 #include "math/fdiml.h"
 #include "math/ffma.h"
+#include "math/ffmaf128.h"
 #include "math/ffmal.h"
 #include "math/floor.h"
 #include "math/floorbf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
new file mode 100644
index 0000000000000..b22e6a1f08d3e
--- /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"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#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 // 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 79278b6e77a3b..0df8262cfb5f2 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1163,6 +1163,17 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  ffmaf128
+  HDRS
+    ffmaf128.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.fma
+    libc.src.__support.macros.config
+    libc.include.llvm-libc-types.float128
+)
+
 add_header_library(
   ffmal
   HDRS
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
new file mode 100644
index 0000000000000..c4b5a58e145fa
--- /dev/null
+++ b/libc/src/__support/math/ffmaf128.h
@@ -0,0 +1,34 @@
+//===-- 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/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float ffmaf128(float128 x, float128 y, float128 z) {
+  return fputil::fma<float>(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/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8ec25be61d12..418cf85b84a20 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3155,8 +3155,7 @@ add_entrypoint_object(
   HDRS
     ../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..15c0308b0b9c4 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);
+  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 a04a15cdabcb7..c90e5687d8c33 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -121,6 +121,7 @@ add_fp_unittest(
     libc.src.__support.math.fdimf16
     libc.src.__support.math.fdiml
     libc.src.__support.math.ffma
+    libc.src.__support.math.ffmaf128
     libc.src.__support.math.ffmal
     libc.src.__support.math.floor
     libc.src.__support.math.floorbf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 460449e4fcb2e..17045ce5edfdb 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -339,6 +339,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
 
   EXPECT_FP_EQ(float128(0x0p+0),
                LIBC_NAMESPACE::shared::atan2f128(float128(0.0), float128(0.0)));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ffmaf128(
+                            float128(0.0), float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::fsqrtf128(float128(1.0f)));
   EXPECT_FP_EQ_ALL_ROUNDING(float128(0.75), LIBC_NAMESPACE::shared::frexpf128(
                                                 float128(24), &exponent));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 87d1d88e971bf..31a229d94a187 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3915,6 +3915,17 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_ffmaf128",
+    hdrs = ["src/__support/math/ffmaf128.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_fma",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_floor",
     hdrs = ["src/__support/math/floor.h"],
@@ -6694,7 +6705,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/184751


More information about the llvm-commits mailing list