[libc-commits] [libc] [llvm] [libc][math] Refactor dfmaf128 to Header Only (PR #176480)

via libc-commits libc-commits at lists.llvm.org
Fri Jan 16 13:42:23 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Madhur Kumar (MadhurKumar004)

<details>
<summary>Changes</summary>

Closes https://github.com/llvm/llvm-project/issues/175315, Part of https://github.com/llvm/llvm-project/issues/175344

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


9 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/dfmaf128.h (+23) 
- (modified) libc/src/__support/math/CMakeLists.txt (+10) 
- (added) libc/src/__support/math/dfmaf128.h (+26) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-2) 
- (modified) libc/src/math/generic/dfmaf128.cpp (+2-9) 
- (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 (+11-1) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 2e7bbe1ef13be..9069d516cb244 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -39,6 +39,7 @@
 #include "math/coshf16.h"
 #include "math/cospif.h"
 #include "math/cospif16.h"
+#include "math/dfmaf128.h"
 #include "math/dfmal.h"
 #include "math/dsqrtl.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/dfmaf128.h b/libc/shared/math/dfmaf128.h
new file mode 100644
index 0000000000000..2058466afaa52
--- /dev/null
+++ b/libc/shared/math/dfmaf128.h
@@ -0,0 +1,23 @@
+//===-- Shared dfmaf128 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_DFMAF128_H
+#define LLVM_LIBC_SHARED_MATH_DFMAF128_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/dfmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::dfmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_DFMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index b45ccfc0eb3cb..c3e88170676a4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1096,3 +1096,13 @@ add_header_library(
     libc.src.__support.common
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  dfmaf128
+  HDRS
+    dfmaf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.fma
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/math/dfmaf128.h b/libc/src/__support/math/dfmaf128.h
new file mode 100644
index 0000000000000..45de549567c2d
--- /dev/null
+++ b/libc/src/__support/math/dfmaf128.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for dfmaf128 ---------------------------------===//
+//
+// 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_DFMAF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DFMAF128_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 double dfmaf128(float128 x, float128 y, float128 z) {
+  return fputil::fma<double>(x, y, z);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DFMAF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 009a3033083bd..c27c34d44bd10 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -249,8 +249,7 @@ add_entrypoint_object(
   HDRS
     ../dfmaf128.h
   DEPENDS
-    libc.src.__support.FPUtil.fma
-    libc.src.__support.macros.properties.types
+    libc.src.__support.math.dfmaf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/dfmaf128.cpp b/libc/src/math/generic/dfmaf128.cpp
index b6e1bdb085cf7..b8069c6597c64 100644
--- a/libc/src/math/generic/dfmaf128.cpp
+++ b/libc/src/math/generic/dfmaf128.cpp
@@ -6,20 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_MATH_DFMAf128_H
-#define LLVM_LIBC_SRC_MATH_DFMAf128_H
-
 #include "src/math/dfmaf128.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/dfmaf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, dfmaf128, (float128 x, float128 y, float128 z)) {
-  return fputil::fma<double>(x, y, z);
+  return math::dfmaf128(x, y, z);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_MATH_DFMAf128_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 58214bf6f88eb..170fff1716c60 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -35,6 +35,7 @@ add_fp_unittest(
     libc.src.__support.math.coshf16
     libc.src.__support.math.cospif
     libc.src.__support.math.cospif16
+    libc.src.__support.math.dfmaf128
     libc.src.__support.math.dfmal
     libc.src.__support.math.dsqrtl
     libc.src.__support.math.exp10m1f
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 6b78de0281347..ae134063f26de 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -115,6 +115,8 @@ 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(0.0, LIBC_NAMESPACE::shared::dfmaf128(
+                        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 4251f20a5dfcf..3f5a3cb1e2d93 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3164,6 +3164,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_dfmaf128",
+    hdrs = ["src/__support/math/dfmaf128.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_fma",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_range_reduction_double",
     hdrs = [
@@ -3771,7 +3781,7 @@ libc_math_function(
 libc_math_function(
     name = "dfmaf128",
     additional_deps = [
-        ":__support_fputil_fma",
+        ":__support_math_dfmaf128",
     ],
 )
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/176480


More information about the libc-commits mailing list