Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[libc][math] Refactor dmul family to header-only#182151

Open
hulxv wants to merge 4 commits intollvm:mainfrom
hulxv:refactor/header-only/dmul
Open

[libc][math] Refactor dmul family to header-only#182151
hulxv wants to merge 4 commits intollvm:mainfrom
hulxv:refactor/header-only/dmul

Conversation

@hulxv
Copy link
Copy Markdown
Member

@hulxv hulxv commented Feb 18, 2026

Refactors the dmul math family to be header-only.

Closes #182150

Target Functions:

  • dmulf128
  • dmull

@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Feb 18, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 18, 2026

@llvm/pr-subscribers-libc

Author: Mohamed Emad (hulxv)

Changes

Refactors the dmul math family to be header-only.

Closes #182150

Target Functions:

  • dmulf128
  • dmull

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

12 Files Affected:

  • (modified) libc/shared/math.h (+2)
  • (added) libc/shared/math/dmulf128.h (+28)
  • (added) libc/shared/math/dmull.h (+22)
  • (modified) libc/src/__support/math/CMakeLists.txt (+17)
  • (added) libc/src/__support/math/dmulf128.h (+32)
  • (added) libc/src/__support/math/dmull.h (+26)
  • (modified) libc/src/math/generic/CMakeLists.txt (+2-3)
  • (modified) libc/src/math/generic/dmulf128.cpp (+2-4)
  • (modified) libc/src/math/generic/dmull.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 --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..910ea6d39e595 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -54,6 +54,8 @@
 #include "math/cospif16.h"
 #include "math/dfmaf128.h"
 #include "math/dfmal.h"
+#include "math/dmulf128.h"
+#include "math/dmull.h"
 #include "math/dsqrtl.h"
 #include "math/erff.h"
 #include "math/exp.h"
diff --git a/libc/shared/math/dmulf128.h b/libc/shared/math/dmulf128.h
new file mode 100644
index 0000000000000..7a9f88cca6600
--- /dev/null
+++ b/libc/shared/math/dmulf128.h
@@ -0,0 +1,28 @@
+//===-- Shared dmulf128 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_DMULF128_H
+#define LLVM_LIBC_SHARED_MATH_DMULF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/dmulf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::dmulf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_DMULF128_H
diff --git a/libc/shared/math/dmull.h b/libc/shared/math/dmull.h
new file mode 100644
index 0000000000000..494f57074bdb4
--- /dev/null
+++ b/libc/shared/math/dmull.h
@@ -0,0 +1,22 @@
+//===-- Shared dmull 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_DMULL_H
+#define LLVM_LIBC_SHARED_MATH_DMULL_H
+
+#include "src/__support/math/dmull.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::dmull;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_DMULL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..64193b0d83f20 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(
+  dmulf128
+  HDRS
+    dmulf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+add_header_library(
+  dmull
+  HDRS
+    dmull.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
 
 add_header_library(
   dsqrtl
diff --git a/libc/src/__support/math/dmulf128.h b/libc/src/__support/math/dmulf128.h
new file mode 100644
index 0000000000000..519b12b4bf93e
--- /dev/null
+++ b/libc/src/__support/math/dmulf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for dmulf128 ----------------------*- 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_DMULF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DMULF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double dmulf128(float128 x, float128 y) {
+  return fputil::generic::mul<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DMULF128_H
diff --git a/libc/src/__support/math/dmull.h b/libc/src/__support/math/dmull.h
new file mode 100644
index 0000000000000..dacce3ad492e6
--- /dev/null
+++ b/libc/src/__support/math/dmull.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for dmull -------------------------*- 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_DMULL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DMULL_H
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double dmull(long double x, long double y) {
+  return fputil::generic::mul<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DMULL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..768827e45ac0f 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5038,7 +5038,7 @@ add_entrypoint_object(
   HDRS
     ../dmull.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.dmull
 )
 
 add_entrypoint_object(
@@ -5048,8 +5048,7 @@ add_entrypoint_object(
   HDRS
     ../dmulf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.dmulf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/dmulf128.cpp b/libc/src/math/generic/dmulf128.cpp
index 7e6ef95362c09..0e05d8ffaafd9 100644
--- a/libc/src/math/generic/dmulf128.cpp
+++ b/libc/src/math/generic/dmulf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/dmulf128.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/dmulf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, dmulf128, (float128 x, float128 y)) {
-  return fputil::generic::mul<double>(x, y);
+  return math::dmulf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/dmull.cpp b/libc/src/math/generic/dmull.cpp
index 428caa84a9977..36be06f7585a2 100644
--- a/libc/src/math/generic/dmull.cpp
+++ b/libc/src/math/generic/dmull.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/dmull.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/dmull.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, dmull, (long double x, long double y)) {
-  return fputil::generic::mul<double>(x, y);
+  return math::dmull(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..e842b70eb13e2 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -50,6 +50,8 @@ add_fp_unittest(
     libc.src.__support.math.cospif16
     libc.src.__support.math.dfmaf128
     libc.src.__support.math.dfmal
+    libc.src.__support.math.dmulf128
+    libc.src.__support.math.dmull
     libc.src.__support.math.dsqrtl
     libc.src.__support.math.exp10m1f
     libc.src.__support.math.exp10m1f16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7f2f39ac7a285..1b498ef7d652c 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::dmull(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::dmulf128(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..95346c3405add 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_dmulf128",
+    hdrs = ["src/__support/math/dmulf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_dmull",
+    hdrs = ["src/__support/math/dmull.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_dsqrtl",
     hdrs = ["src/__support/math/dsqrtl.h"],
@@ -4751,9 +4770,19 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "dmull")
+libc_math_function(
+    name = "dmull",
+    additional_deps = [
+        ":__support_math_dmull",
+    ],
+)
 
-libc_math_function(name = "dmulf128")
+libc_math_function(
+    name = "dmulf128",
+    additional_deps = [
+        ":__support_math_dmulf128",
+    ],
+)
 
 libc_math_function(
     name = "dsqrtl",

@hulxv hulxv requested a review from bassiounix March 4, 2026 01:38
Comment thread libc/src/__support/math/CMakeLists.txt
Comment thread libc/src/__support/math/dmulf128.h Outdated
Comment thread libc/src/__support/math/dmull.h Outdated
Comment thread libc/shared/math/dmulf128.h
Comment thread libc/shared/math/dmull.h
@hulxv hulxv requested a review from bassiounix March 17, 2026 23:23
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type should be double

hulxv added 2 commits April 13, 2026 16:41
Refactored functions:
  - dmulf128
  - dmull
@hulxv hulxv force-pushed the refactor/header-only/dmul branch from 3d8bab8 to b4cc8e4 Compare April 13, 2026 14:42
@hulxv hulxv requested a review from bassiounix April 13, 2026 14:42
@github-actions
Copy link
Copy Markdown

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/shared/math/dmulf128.h libc/shared/math/dmull.h libc/src/__support/math/dmulf128.h libc/src/__support/math/dmull.h libc/shared/math.h libc/src/math/generic/dmulf128.cpp libc/src/math/generic/dmull.cpp libc/test/shared/shared_math_constexpr_test.cpp libc/test/shared/shared_math_test.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 3a9ac0dc1..e42bb2bde 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -64,7 +64,8 @@ static_assert(float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::copysignf128(float128(0.0),
                                                    float128(0.0)));
-static_assert(0.0 == LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
+static_assert(0.0 ==
+              LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::floorf128(float128(0.0)));
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc][math] Refactor dmul Math Functions to Header Only

3 participants