[libc][math] Refactor dmul family to header-only#182151
Open
[libc][math] Refactor dmul family to header-only#182151
Conversation
Member
|
@llvm/pr-subscribers-libc Author: Mohamed Emad (hulxv) ChangesRefactors the dmul math family to be header-only. Closes #182150 Target Functions:
Full diff: https://github.com/llvm/llvm-project/pull/182151.diff 12 Files Affected:
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",
|
bassiounix
requested changes
Mar 10, 2026
bassiounix
reviewed
Mar 10, 2026
bassiounix
reviewed
Mar 10, 2026
bassiounix
approved these changes
Mar 19, 2026
bassiounix
requested changes
Mar 19, 2026
Member
There was a problem hiding this comment.
return type should be double
Refactored functions: - dmulf128 - dmull
3d8bab8 to
b4cc8e4
Compare
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
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)));
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactors the dmul math family to be header-only.
Closes #182150
Target Functions: