[libc-commits] [libc] [libc][math][c23] Add ddivl C23 math function. (PR #102468)
via libc-commits
libc-commits at lists.llvm.org
Thu Aug 8 06:52:21 PDT 2024
https://github.com/lntue created https://github.com/llvm/llvm-project/pull/102468
None
>From fe7b3b4f68b39393bf1a690c9cb44d876b945dff Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Thu, 8 Aug 2024 13:50:17 +0000
Subject: [PATCH] [libc][math][c23] Add ddivl C23 math function.
---
libc/config/darwin/arm/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/docs/math/index.rst | 2 +-
libc/newhdrgen/yaml/math.yaml | 7 +++++++
libc/src/__support/FPUtil/generic/div.h | 2 +-
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/ddivl.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 12 ++++++++++++
libc/src/math/generic/ddivl.cpp | 20 ++++++++++++++++++++
libc/test/src/math/CMakeLists.txt | 14 +++++++++++++-
libc/test/src/math/DivTest.h | 4 ++--
libc/test/src/math/ddivl_test.cpp | 13 +++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 18 +++++++++++++++---
libc/test/src/math/smoke/ddivl_test.cpp | 13 +++++++++++++
18 files changed, 124 insertions(+), 8 deletions(-)
create mode 100644 libc/src/math/ddivl.h
create mode 100644 libc/src/math/generic/ddivl.cpp
create mode 100644 libc/test/src/math/ddivl_test.cpp
create mode 100644 libc/test/src/math/smoke/ddivl_test.cpp
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index 27822f5013f2fc..78e46b18993a09 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -149,6 +149,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.dfmal
libc.src.math.dsqrtl
libc.src.math.daddl
+ libc.src.math.ddivl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index aa13fb276750fc..49c19571ac4192 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -120,6 +120,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.coshf
#libc.src.math.cosf
#libc.src.math.daddl
+ #libc.src.math.ddivl
#libc.src.math.dfmal
#libc.src.math.dsqrtl
#libc.src.math.dsubl
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index f2ab6c0ba73d74..034db23932a398 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -389,6 +389,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
+ libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a7deccb9ded988..e2d8e9e3249677 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -388,6 +388,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
+ libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6b16843e5027d7..817f4190399aa1 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -391,6 +391,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.dmull
libc.src.math.dsqrtl
libc.src.math.daddl
+ libc.src.math.ddivl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 87531028959ef1..1f36bdf9b21ee8 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -137,6 +137,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.daddl
+ libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dsubl
libc.src.math.erff
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index c0cecdfa1b25ac..a3174c72e86ce1 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -116,7 +116,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dadd | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.1 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+| ddiv | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index c0485428fc559e..1b474b3401ecb5 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -2352,3 +2352,10 @@ functions:
arguments:
- type: long double
- type: int *
+ - name: ddivl
+ standards:
+ - stdc
+ return_type: long double
+ arguments:
+ - type: long double
+ - type: long double
diff --git a/libc/src/__support/FPUtil/generic/div.h b/libc/src/__support/FPUtil/generic/div.h
index dad1772fce7500..f0e405772e9fa3 100644
--- a/libc/src/__support/FPUtil/generic/div.h
+++ b/libc/src/__support/FPUtil/generic/div.h
@@ -35,7 +35,7 @@ div(InType x, InType y) {
using InFPBits = FPBits<InType>;
using InStorageType = typename InFPBits::StorageType;
using DyadicFloat =
- DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::FRACTION_LEN))>;
+ DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::SIG_LEN + 1))>;
InFPBits x_bits(x);
InFPBits y_bits(y);
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 56e9bb60c1e436..a07065c93003f2 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -88,6 +88,7 @@ add_math_entrypoint_object(cospif)
add_math_entrypoint_object(daddl)
add_math_entrypoint_object(daddf128)
+add_math_entrypoint_object(ddivl)
add_math_entrypoint_object(ddivf128)
add_math_entrypoint_object(dmull)
add_math_entrypoint_object(dmulf128)
diff --git a/libc/src/math/ddivl.h b/libc/src/math/ddivl.h
new file mode 100644
index 00000000000000..bf0da2887e330f
--- /dev/null
+++ b/libc/src/math/ddivl.h
@@ -0,0 +1,20 @@
+//===-- 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_MATH_DDIVL_H
+#define LLVM_LIBC_SRC_MATH_DDIVL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+double ddivl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DDIVL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index e5f40673dd5f02..a224bed8c3a14c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -154,6 +154,18 @@ add_entrypoint_object(
libc.src.__support.FPUtil.generic.add_sub
)
+add_entrypoint_object(
+ ddivl
+ SRCS
+ ddivl.cpp
+ HDRS
+ ../ddivl.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.FPUtil.generic.div
+)
+
add_entrypoint_object(
ddivf128
SRCS
diff --git a/libc/src/math/generic/ddivl.cpp b/libc/src/math/generic/ddivl.cpp
new file mode 100644
index 00000000000000..18fc44d6f1648e
--- /dev/null
+++ b/libc/src/math/generic/ddivl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of ddivl function ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/ddivl.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, ddivl, (long double x, long double y)) {
+ return fputil::generic::div<double>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index f3703eb59999b1..d0106972809cc0 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2464,6 +2464,19 @@ add_fp_unittest(
libc.src.stdlib.srand
)
+add_fp_unittest(
+ ddivl_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ ddivl_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.src.math.ddivl
+)
+
add_fp_unittest(
dfmal_test
NEED_MPFR
@@ -2518,7 +2531,6 @@ add_fp_unittest(
libc.src.math.fdivl
)
-
add_fp_unittest(
ffma_test
NEED_MPFR
diff --git a/libc/test/src/math/DivTest.h b/libc/test/src/math/DivTest.h
index 1cdc1398a1a1c1..c14d16fb5773bc 100644
--- a/libc/test/src/math/DivTest.h
+++ b/libc/test/src/math/DivTest.h
@@ -47,7 +47,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
InType x = InFPBits(v).get_val();
InType y = InFPBits(w).get_val();
mpfr::BinaryInput<InType> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
0.5);
}
}
@@ -60,7 +60,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
InType x = InFPBits(v).get_val();
InType y = InFPBits(w).get_val();
mpfr::BinaryInput<InType> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
0.5);
}
}
diff --git a/libc/test/src/math/ddivl_test.cpp b/libc/test/src/math/ddivl_test.cpp
new file mode 100644
index 00000000000000..7768766e30c12a
--- /dev/null
+++ b/libc/test/src/math/ddivl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ddivl -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/math/ddivl.h"
+
+LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 45e1c4c26cc147..ef303228a9fe00 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4615,7 +4615,7 @@ add_fp_unittest(
)
add_fp_unittest(
- daddl
+ daddl_test
SUITE
libc-math-smoke-tests
SRCS
@@ -4627,7 +4627,7 @@ add_fp_unittest(
)
add_fp_unittest(
- daddf128
+ daddf128_test
SUITE
libc-math-smoke-tests
SRCS
@@ -4639,7 +4639,19 @@ add_fp_unittest(
)
add_fp_unittest(
- ddivf128
+ ddivl_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ddivl_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.src.math.ddivl
+)
+
+add_fp_unittest(
+ ddivf128_test
SUITE
libc-math-smoke-tests
SRCS
diff --git a/libc/test/src/math/smoke/ddivl_test.cpp b/libc/test/src/math/smoke/ddivl_test.cpp
new file mode 100644
index 00000000000000..7768766e30c12a
--- /dev/null
+++ b/libc/test/src/math/smoke/ddivl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ddivl -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DivTest.h"
+
+#include "src/math/ddivl.h"
+
+LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)
More information about the libc-commits
mailing list