[libc-commits] [libc] b093148 - [libc][math] Refactor dmul family to header-only (#182151)

via libc-commits libc-commits at lists.llvm.org
Fri Apr 24 07:49:24 PDT 2026


Author: hulxv
Date: 2026-04-24T17:49:19+03:00
New Revision: b0931483280db3a34c0228a859bd1fcb9af3902f

URL: https://github.com/llvm/llvm-project/commit/b0931483280db3a34c0228a859bd1fcb9af3902f
DIFF: https://github.com/llvm/llvm-project/commit/b0931483280db3a34c0228a859bd1fcb9af3902f.diff

LOG: [libc][math] Refactor dmul family to header-only (#182151)

Refactors the dmul math family to be header-only.

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

Target Functions:
  - dmulf128
  - dmull

Added: 
    libc/shared/math/dmulf128.h
    libc/shared/math/dmull.h
    libc/src/__support/math/dmulf128.h
    libc/src/__support/math/dmull.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/dmulf128.cpp
    libc/src/math/generic/dmull.cpp
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_constexpr_test.cpp
    libc/test/shared/shared_math_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/shared/math.h b/libc/shared/math.h
index e73440121c0be..48ced4440a10a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -89,6 +89,8 @@
 #include "math/daddl.h"
 #include "math/dfmaf128.h"
 #include "math/dfmal.h"
+#include "math/dmulf128.h"
+#include "math/dmull.h"
 #include "math/dsqrtl.h"
 #include "math/erfcf16.h"
 #include "math/erff.h"

diff  --git a/libc/shared/math/dmulf128.h b/libc/shared/math/dmulf128.h
new file mode 100644
index 0000000000000..f255117689daf
--- /dev/null
+++ b/libc/shared/math/dmulf128.h
@@ -0,0 +1,29 @@
+//===-- 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 "shared/libc_common.h"
+#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..a1320ca3339f8
--- /dev/null
+++ b/libc/shared/math/dmull.h
@@ -0,0 +1,23 @@
+//===-- 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 "shared/libc_common.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 0c62bfaf2ad6b..ffd5651d74cab 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1005,6 +1005,25 @@ add_header_library(
     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(
   daddf128
   HDRS

diff  --git a/libc/src/__support/math/dmulf128.h b/libc/src/__support/math/dmulf128.h
new file mode 100644
index 0000000000000..a76f2f1925599
--- /dev/null
+++ b/libc/src/__support/math/dmulf128.h
@@ -0,0 +1,31 @@
+//===-- 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 constexpr 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..bb9529cfe0241
--- /dev/null
+++ b/libc/src/__support/math/dmull.h
@@ -0,0 +1,25 @@
+//===-- 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 constexpr 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 1774ead284769..2ead73076b26e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5017,7 +5017,7 @@ add_entrypoint_object(
   HDRS
     ../dmull.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.dmull
 )
 
 add_entrypoint_object(
@@ -5027,8 +5027,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 8c233e8326b77..ea40834cea495 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -86,6 +86,8 @@ add_fp_unittest(
     libc.src.__support.math.daddl
     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
@@ -290,6 +292,8 @@ add_fp_unittest(
     libc.src.__support.math.copysignf128
     libc.src.__support.math.copysignf16
     libc.src.__support.math.copysignl
+    libc.src.__support.math.dmulf128
+    libc.src.__support.math.dmull
     libc.src.__support.math.floor
     libc.src.__support.math.floorbf16
     libc.src.__support.math.floorf

diff  --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 5e69d981d0473..e42bb2bde857f 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -49,6 +49,7 @@ static_assert(3.0f16 == LIBC_NAMESPACE::shared::floorf16(3.7f16));
 
 static_assert(0.0L == LIBC_NAMESPACE::shared::ceill(0.0L));
 static_assert(0.0L == LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
+static_assert(0.0 == LIBC_NAMESPACE::shared::dmull(0.0L, 1.0L));
 static_assert(0.0L == LIBC_NAMESPACE::shared::floorl(0.0L));
 
 #endif
@@ -63,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(float128(0.0) ==
               LIBC_NAMESPACE::shared::floorf128(float128(0.0)));
 

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index f5a7d218b1592..14c3e37f8d4b4 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -320,6 +320,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::ceill(0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::dmull(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fdiml(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::floorl(0.0L));
@@ -403,6 +404,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                                   float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::daddf128(float128(0.0), float128(0.0)));
+  EXPECT_FP_EQ(0.0,
+               LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::faddf128(float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::floorf128(float128(0.0)));

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 6fa20fb0207bc..ef1a29a36c668 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4062,6 +4062,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"],
@@ -7161,10 +7180,18 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "dmull")
+libc_math_function(
+    name = "dmull",
+    additional_deps = [
+        ":__support_math_dmull",
+    ],
+)
 
 libc_math_function(
     name = "dmulf128",
+    additional_deps = [
+        ":__support_math_dmulf128",
+    ],
 )
 
 libc_math_function(


        


More information about the libc-commits mailing list