[libc-commits] [libc] [llvm] [libc][math] Refactor ddiv family to header-only (PR #182149)
Mohamed Emad via libc-commits
libc-commits at lists.llvm.org
Fri Mar 13 17:08:23 PDT 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/182149
>From 27644f95b4ba04188ad92fd9e7b2eb8d9e2ca761 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 18 Feb 2026 23:16:50 +0200
Subject: [PATCH] [libc][math] Refactor ddiv family to header-only
Refactored functions:
- ddivf128
- ddivl
---
libc/shared/math.h | 2 ++
libc/shared/math/ddivf128.h | 28 ++++++++++++++++
libc/shared/math/ddivl.h | 22 +++++++++++++
libc/src/__support/math/CMakeLists.txt | 17 ++++++++++
libc/src/__support/math/ddivf128.h | 32 ++++++++++++++++++
libc/src/__support/math/ddivl.h | 26 +++++++++++++++
libc/src/math/generic/CMakeLists.txt | 5 ++-
libc/src/math/generic/ddivf128.cpp | 6 ++--
libc/src/math/generic/ddivl.cpp | 6 ++--
libc/test/shared/CMakeLists.txt | 2 ++
libc/test/shared/shared_math_test.cpp | 4 +++
.../llvm-project-overlay/libc/BUILD.bazel | 33 +++++++++++++++++--
12 files changed, 170 insertions(+), 13 deletions(-)
create mode 100644 libc/shared/math/ddivf128.h
create mode 100644 libc/shared/math/ddivl.h
create mode 100644 libc/src/__support/math/ddivf128.h
create mode 100644 libc/src/__support/math/ddivl.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..fce598360ef00 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/ddivf128.h"
+#include "math/ddivl.h"
#include "math/dfmaf128.h"
#include "math/dfmal.h"
#include "math/dsqrtl.h"
diff --git a/libc/shared/math/ddivf128.h b/libc/shared/math/ddivf128.h
new file mode 100644
index 0000000000000..8766382b72484
--- /dev/null
+++ b/libc/shared/math/ddivf128.h
@@ -0,0 +1,28 @@
+//===-- Shared ddivf128 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_DDIVF128_H
+#define LLVM_LIBC_SHARED_MATH_DDIVF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/ddivf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ddivf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_DDIVF128_H
diff --git a/libc/shared/math/ddivl.h b/libc/shared/math/ddivl.h
new file mode 100644
index 0000000000000..772adf9023218
--- /dev/null
+++ b/libc/shared/math/ddivl.h
@@ -0,0 +1,22 @@
+//===-- Shared ddivl 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_DDIVL_H
+#define LLVM_LIBC_SHARED_MATH_DDIVL_H
+
+#include "src/__support/math/ddivl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ddivl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_DDIVL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..c8f5f2b34791b 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(
+ ddivf128
+ HDRS
+ ddivf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.generic.div
+ libc.src.__support.macros.config
+)
+add_header_library(
+ ddivl
+ HDRS
+ ddivl.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.div
+ libc.src.__support.macros.config
+)
add_header_library(
dsqrtl
diff --git a/libc/src/__support/math/ddivf128.h b/libc/src/__support/math/ddivf128.h
new file mode 100644
index 0000000000000..a6b6871d5431c
--- /dev/null
+++ b/libc/src/__support/math/ddivf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for ddivf128 ----------------------*- 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_DDIVF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DDIVF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr double ddivf128(float128 x, float128 y) {
+ return fputil::generic::div<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DDIVF128_H
diff --git a/libc/src/__support/math/ddivl.h b/libc/src/__support/math/ddivl.h
new file mode 100644
index 0000000000000..aeb34442923c3
--- /dev/null
+++ b/libc/src/__support/math/ddivl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for ddivl -------------------------*- 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_DDIVL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_DDIVL_H
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr double ddivl(long double x, long double y) {
+ return fputil::generic::div<double>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DDIVL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..486aabaf7ba32 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -222,7 +222,7 @@ add_entrypoint_object(
HDRS
../ddivl.h
DEPENDS
- libc.src.__support.FPUtil.generic.div
+ libc.src.__support.math.ddivl
)
add_entrypoint_object(
@@ -232,8 +232,7 @@ add_entrypoint_object(
HDRS
../ddivf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.div
+ libc.src.__support.math.ddivf128
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ddivf128.cpp b/libc/src/math/generic/ddivf128.cpp
index 1ce4fd66b42cb..e7df2fa8be08a 100644
--- a/libc/src/math/generic/ddivf128.cpp
+++ b/libc/src/math/generic/ddivf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ddivf128.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ddivf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, ddivf128, (float128 x, float128 y)) {
- return fputil::generic::div<double>(x, y);
+ return math::ddivf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ddivl.cpp b/libc/src/math/generic/ddivl.cpp
index 18fc44d6f1648..5fa8e997bb0e0 100644
--- a/libc/src/math/generic/ddivl.cpp
+++ b/libc/src/math/generic/ddivl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ddivl.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ddivl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, ddivl, (long double x, long double y)) {
- return fputil::generic::div<double>(x, y);
+ return math::ddivl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..3b967d9fb6f47 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.ddivf128
+ libc.src.__support.math.ddivl
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..ed9cc9fc87286 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(1.0L, LIBC_NAMESPACE::shared::ddivl(1.0L, 1.0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -238,6 +240,8 @@ 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(1.0L, LIBC_NAMESPACE::shared::ddivf128(1.0L, 1.0L));
}
#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..61abfdf38a89d 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_ddivf128",
+ hdrs = ["src/__support/math/ddivf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ddivl",
+ hdrs = ["src/__support/math/ddivl.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_dsqrtl",
hdrs = ["src/__support/math/dsqrtl.h"],
@@ -4734,9 +4753,19 @@ libc_math_function(name = "daddl")
libc_math_function(name = "daddf128")
-libc_math_function(name = "ddivl")
+libc_math_function(
+ name = "ddivl",
+ additional_deps = [
+ ":__support_math_ddivl",
+ ],
+)
-libc_math_function(name = "ddivf128")
+libc_math_function(
+ name = "ddivf128",
+ additional_deps = [
+ ":__support_math_ddivf128",
+ ],
+)
libc_math_function(
name = "dfmal",
More information about the libc-commits
mailing list