[libc-commits] [libc] [llvm] [libc][math] Refactor dadd family to header-only (PR #182142)

via libc-commits libc-commits at lists.llvm.org
Wed Feb 18 12:58:55 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Mohamed Emad (hulxv)

<details>
<summary>Changes</summary>

Refactors the dadd math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182141

Target Functions:
  - daddf128
  - daddl

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


12 Files Affected:

- (modified) libc/shared/math.h (+2) 
- (added) libc/shared/math/daddf128.h (+28) 
- (added) libc/shared/math/daddl.h (+22) 
- (modified) libc/src/__support/math/CMakeLists.txt (+17) 
- (added) libc/src/__support/math/daddf128.h (+32) 
- (added) libc/src/__support/math/daddl.h (+26) 
- (modified) libc/src/math/generic/CMakeLists.txt (+2-3) 
- (modified) libc/src/math/generic/daddf128.cpp (+2-4) 
- (modified) libc/src/math/generic/daddl.cpp (+2-4) 
- (modified) libc/test/shared/CMakeLists.txt (+2) 
- (modified) libc/test/shared/shared_math_test.cpp (+5) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+31-2) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..1777854061f43 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -52,6 +52,8 @@
 #include "math/coshf16.h"
 #include "math/cospif.h"
 #include "math/cospif16.h"
+#include "math/daddf128.h"
+#include "math/daddl.h"
 #include "math/dfmaf128.h"
 #include "math/dfmal.h"
 #include "math/dsqrtl.h"
diff --git a/libc/shared/math/daddf128.h b/libc/shared/math/daddf128.h
new file mode 100644
index 0000000000000..c48b9e329b43b
--- /dev/null
+++ b/libc/shared/math/daddf128.h
@@ -0,0 +1,28 @@
+//===-- Shared daddf128 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_DADDF128_H
+#define LLVM_LIBC_SHARED_MATH_DADDF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/daddf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::daddf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_DADDF128_H
diff --git a/libc/shared/math/daddl.h b/libc/shared/math/daddl.h
new file mode 100644
index 0000000000000..53e0a0ac5149e
--- /dev/null
+++ b/libc/shared/math/daddl.h
@@ -0,0 +1,22 @@
+//===-- Shared daddl 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_DADDL_H
+#define LLVM_LIBC_SHARED_MATH_DADDL_H
+
+#include "src/__support/math/daddl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::daddl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_DADDL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..610b27f2d5474 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -583,6 +583,23 @@ add_header_library(
     libc.src.__support.FPUtil.multiply_add
     libc.src.__support.macros.optimization
 )
+add_header_library(
+  daddf128
+  HDRS
+    daddf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+add_header_library(
+  daddl
+  HDRS
+    daddl.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
 
 add_header_library(
   dsqrtl
diff --git a/libc/src/__support/math/daddf128.h b/libc/src/__support/math/daddf128.h
new file mode 100644
index 0000000000000..8789b85ec02cd
--- /dev/null
+++ b/libc/src/__support/math/daddf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for daddf128 ----------------------*- 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_DADDF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr double daddf128(float128 x, float128 y) {
+  return fputil::generic::add<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H
diff --git a/libc/src/__support/math/daddl.h b/libc/src/__support/math/daddl.h
new file mode 100644
index 0000000000000..ba08b267ffe36
--- /dev/null
+++ b/libc/src/__support/math/daddl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for daddl -------------------------*- 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_DADDL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr double daddl(long double x, long double y) {
+  return fputil::generic::add<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..3c84d65b15858 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -201,7 +201,7 @@ add_entrypoint_object(
   HDRS
     ../daddl.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.daddl
 )
 
 add_entrypoint_object(
@@ -211,8 +211,7 @@ add_entrypoint_object(
   HDRS
     ../daddf128.h
  DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.daddf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/daddf128.cpp b/libc/src/math/generic/daddf128.cpp
index 6edba3b8f5e43..10b3ec6c30c6c 100644
--- a/libc/src/math/generic/daddf128.cpp
+++ b/libc/src/math/generic/daddf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/daddf128.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/daddf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, daddf128, (float128 x, float128 y)) {
-  return fputil::generic::add<double>(x, y);
+  return math::daddf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/daddl.cpp b/libc/src/math/generic/daddl.cpp
index 708de3833869c..3bafa1ee301e0 100644
--- a/libc/src/math/generic/daddl.cpp
+++ b/libc/src/math/generic/daddl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/daddl.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/daddl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, daddl, (long double x, long double y)) {
-  return fputil::generic::add<double>(x, y);
+  return math::daddl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..f9179a1b09620 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -48,6 +48,8 @@ add_fp_unittest(
     libc.src.__support.math.coshf16
     libc.src.__support.math.cospif
     libc.src.__support.math.cospif16
+    libc.src.__support.math.daddf128
+    libc.src.__support.math.daddl
     libc.src.__support.math.dfmaf128
     libc.src.__support.math.dfmal
     libc.src.__support.math.dsqrtl
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7f2f39ac7a285..d27cf9b661e2f 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -203,6 +203,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
                                                      &canonicalizel_x));
   EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
+
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -238,6 +240,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
                                                         &canonicalizef128_x));
   EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
+
+  EXPECT_FP_EQ(float128(0.0),
+               LIBC_NAMESPACE::shared::daddf128(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 b90688af7a1d2..b2277d5834511 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2888,6 +2888,25 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_daddf128",
+    hdrs = ["src/__support/math/daddf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_daddl",
+    hdrs = ["src/__support/math/daddl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_dsqrtl",
     hdrs = ["src/__support/math/dsqrtl.h"],
@@ -4730,9 +4749,19 @@ libc_math_function(
     additional_deps = [":__support_math_cospif16"],
 )
 
-libc_math_function(name = "daddl")
+libc_math_function(
+    name = "daddl",
+    additional_deps = [
+        ":__support_math_daddl",
+    ],
+)
 
-libc_math_function(name = "daddf128")
+libc_math_function(
+    name = "daddf128",
+    additional_deps = [
+        ":__support_math_daddf128",
+    ],
+)
 
 libc_math_function(name = "ddivl")
 

``````````

</details>


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


More information about the libc-commits mailing list