[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2f implementation to header-only in src/__support/math folder. (PR #161992)
bassiounix wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/161992?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#161992** https://app.graphite.dev/github/pr/llvm/llvm-project/161992?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/161992?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#161297** https://app.graphite.dev/github/pr/llvm/llvm-project/161297?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161119** https://app.graphite.dev/github/pr/llvm/llvm-project/161119?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#159897** https://app.graphite.dev/github/pr/llvm/llvm-project/159897?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154868** https://app.graphite.dev/github/pr/llvm/llvm-project/154868?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154222** https://app.graphite.dev/github/pr/llvm/llvm-project/154222?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154215** https://app.graphite.dev/github/pr/llvm/llvm-project/154215?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153582** https://app.graphite.dev/github/pr/llvm/llvm-project/153582?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153427** https://app.graphite.dev/github/pr/llvm/llvm-project/153427?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152871** https://app.graphite.dev/github/pr/llvm/llvm-project/152871?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152069** https://app.graphite.dev/github/pr/llvm/llvm-project/152069?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151883** https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151846** https://app.graphite.dev/github/pr/llvm/llvm-project/151846?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151837** https://app.graphite.dev/github/pr/llvm/llvm-project/151837?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151779** https://app.graphite.dev/github/pr/llvm/llvm-project/151779?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151399** https://app.graphite.dev/github/pr/llvm/llvm-project/151399?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151012** https://app.graphite.dev/github/pr/llvm/llvm-project/151012?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150993** https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150968** https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150868** https://app.graphite.dev/github/pr/llvm/llvm-project/150868?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150854** h
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f16 implementation to header-only in src/__support/math folder. (PR #162019)
https://github.com/bassiounix edited https://github.com/llvm/llvm-project/pull/162019 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f16 implementation to header-only in src/__support/math folder. (PR #162019)
https://github.com/bassiounix edited https://github.com/llvm/llvm-project/pull/162019 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f implementation to header-only in src/__support/math folder. (PR #162017)
bassiounix wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/162017?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#162017** https://app.graphite.dev/github/pr/llvm/llvm-project/162017?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/162017?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#161993** https://app.graphite.dev/github/pr/llvm/llvm-project/161993?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161992** https://app.graphite.dev/github/pr/llvm/llvm-project/161992?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161297** https://app.graphite.dev/github/pr/llvm/llvm-project/161297?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161119** https://app.graphite.dev/github/pr/llvm/llvm-project/161119?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#159897** https://app.graphite.dev/github/pr/llvm/llvm-project/159897?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154868** https://app.graphite.dev/github/pr/llvm/llvm-project/154868?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154222** https://app.graphite.dev/github/pr/llvm/llvm-project/154222?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154215** https://app.graphite.dev/github/pr/llvm/llvm-project/154215?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153582** https://app.graphite.dev/github/pr/llvm/llvm-project/153582?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153427** https://app.graphite.dev/github/pr/llvm/llvm-project/153427?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152871** https://app.graphite.dev/github/pr/llvm/llvm-project/152871?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152069** https://app.graphite.dev/github/pr/llvm/llvm-project/152069?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151883** https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151846** https://app.graphite.dev/github/pr/llvm/llvm-project/151846?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151837** https://app.graphite.dev/github/pr/llvm/llvm-project/151837?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151779** https://app.graphite.dev/github/pr/llvm/llvm-project/151779?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151399** https://app.graphite.dev/github/pr/llvm/llvm-project/151399?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151012** https://app.graphite.dev/github/pr/llvm/llvm-project/151012?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150993** https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150968** h
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f implementation to header-only in src/__support/math folder. (PR #162017)
llvmbot wrote:
@llvm/pr-subscribers-libc
Author: Muhammad Bassiouni (bassiounix)
Changes
Part of #147386
in preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
---
Patch is 20.48 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/162017.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/exp2m1f.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+18)
- (added) libc/src/__support/math/exp2m1f.h (+196)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-11)
- (modified) libc/src/math/generic/exp2m1f.cpp (+2-175)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+1)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+17-2)
``diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8bff70f1c5336..0c0e8560bd40f 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -50,6 +50,7 @@
#include "math/exp2.h"
#include "math/exp2f.h"
#include "math/exp2f16.h"
+#include "math/exp2m1f.h"
#include "math/expf.h"
#include "math/expf16.h"
#include "math/frexpf.h"
diff --git a/libc/shared/math/exp2m1f.h b/libc/shared/math/exp2m1f.h
new file mode 100644
index 0..ca9754774f0fc
--- /dev/null
+++ b/libc/shared/math/exp2m1f.h
@@ -0,0 +1,23 @@
+//===-- Shared exp2m1f 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_EXP2M1F_H
+#define LLVM_LIBC_SHARED_MATH_EXP2M1F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/exp2m1f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp2m1f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP2M1F_H
diff --git a/libc/src/__support/math/CMakeLists.txt
b/libc/src/__support/math/CMakeLists.txt
index 185900efa7354..ec2d8948f615b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -767,6 +767,24 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ exp2m1f
+ HDRS
+exp2m1f.h
+ DEPENDS
+.exp10f_utils
+libc.src.errno.errno
+libc.src.__support.common
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.rounding_mode
+libc.src.__support.macros.optimization
+libc.src.__support.macros.properties.cpu_features
+)
+
add_header_library(
exp10
HDRS
diff --git a/libc/src/__support/math/exp2m1f.h
b/libc/src/__support/math/exp2m1f.h
new file mode 100644
index 0..b68304cb1403d
--- /dev/null
+++ b/libc/src/__support/math/exp2m1f.h
@@ -0,0 +1,196 @@
+//===-- Implementation header for exp2m1f -*- 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_EXP2M1F_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP2M1F_H
+
+#include "exp10f_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/rounding_mode.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float exp2m1f(float x) {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+ constexpr size_t N_EXCEPTS_LO = 8;
+
+ constexpr fputil::ExceptValues EXP2M1F_EXCEPTS_LO = {{
+ // (input, RZ output, RU offset, RD offset, RN offset)
+ // x = 0x1.36dc8ep-36, exp2m1f(x) = 0x1.aef212p-37 (RZ)
+ {0x2d9b'6e47U, 0x2d57'7909U, 1U, 0U, 0U},
+ // x = 0x1.224936p-19, exp2m1f(x) = 0x1.926c0ep-20 (RZ)
+ {0x3611'249bU, 0x35c9'3607U, 1U, 0U, 1U},
+ // x = 0x1.d16d2p-20, exp2m1f(x) = 0x1.429becp-20 (RZ)
+ {0x35e8'b690U, 0x35a1'4df6U, 1U, 0U, 1U},
+ // x = 0x1.17949ep-14, exp2m1f(x) = 0x1.8397p-15 (RZ)
+ {0x388b'ca4fU, 0x
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f implementation to header-only in src/__support/math folder. (PR #162017)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/162017
>From 33f208d916bd716834d3f2ee6b94aad337bce2f8 Mon Sep 17 00:00:00 2001
From: bassiounix
Date: Sun, 5 Oct 2025 17:33:45 +0300
Subject: [PATCH] [libc][math] Refactor exp2m1f implementation to header-only
in src/__support/math folder.
---
libc/shared/math.h| 1 +
libc/shared/math/exp2m1f.h| 23 +++
libc/shared/math/exp2m1f16.h | 29 +++
libc/src/__support/math/CMakeLists.txt| 18 ++
libc/src/__support/math/exp2m1f.h | 195 ++
libc/src/__support/math/exp2m1f16.h | 195 ++
libc/src/math/generic/CMakeLists.txt | 12 +-
libc/src/math/generic/exp2m1f.cpp | 177 +---
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
.../llvm-project-overlay/libc/BUILD.bazel | 19 +-
11 files changed, 483 insertions(+), 188 deletions(-)
create mode 100644 libc/shared/math/exp2m1f.h
create mode 100644 libc/shared/math/exp2m1f16.h
create mode 100644 libc/src/__support/math/exp2m1f.h
create mode 100644 libc/src/__support/math/exp2m1f16.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8bff70f1c5336..0c0e8560bd40f 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -50,6 +50,7 @@
#include "math/exp2.h"
#include "math/exp2f.h"
#include "math/exp2f16.h"
+#include "math/exp2m1f.h"
#include "math/expf.h"
#include "math/expf16.h"
#include "math/frexpf.h"
diff --git a/libc/shared/math/exp2m1f.h b/libc/shared/math/exp2m1f.h
new file mode 100644
index 0..ca9754774f0fc
--- /dev/null
+++ b/libc/shared/math/exp2m1f.h
@@ -0,0 +1,23 @@
+//===-- Shared exp2m1f 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_EXP2M1F_H
+#define LLVM_LIBC_SHARED_MATH_EXP2M1F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/exp2m1f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp2m1f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP2M1F_H
diff --git a/libc/shared/math/exp2m1f16.h b/libc/shared/math/exp2m1f16.h
new file mode 100644
index 0..7ee6905fd0d6b
--- /dev/null
+++ b/libc/shared/math/exp2m1f16.h
@@ -0,0 +1,29 @@
+//===-- Shared exp2m1f 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_EXP2M1F16_H
+#define LLVM_LIBC_SHARED_MATH_EXP2M1F16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/exp2m1f16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp2m1f16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP2M1F16_H
diff --git a/libc/src/__support/math/CMakeLists.txt
b/libc/src/__support/math/CMakeLists.txt
index 185900efa7354..ec2d8948f615b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -767,6 +767,24 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ exp2m1f
+ HDRS
+exp2m1f.h
+ DEPENDS
+.exp10f_utils
+libc.src.errno.errno
+libc.src.__support.common
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.rounding_mode
+libc.src.__support.macros.optimization
+libc.src.__support.macros.properties.cpu_features
+)
+
add_header_library(
exp10
HDRS
diff --git a/libc/src/__support/math/exp2m1f.h
b/libc/src/__support/math/exp2m1f.h
new file mode 100644
index 0..e95076c9eac22
--- /dev/null
+++ b/libc/src/__support/math/exp2m1f.h
@@ -0,0 +1,195 @@
+//===-- Implementation header for exp2m1f *-
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
+//
+//===--
[llvm-branch-commits] [libcxx] release/21.x: [libc++][ranges] Fix `ranges::join_view` segmented iterator trait (#158347) (PR #161008)
https://github.com/dyung updated
https://github.com/llvm/llvm-project/pull/161008
>From ec1747045b8209dae756371ca0225c3e1d07b3f0 Mon Sep 17 00:00:00 2001
From: lbonn
Date: Sat, 27 Sep 2025 16:49:54 +0200
Subject: [PATCH] [libc++][ranges] Fix `ranges::join_view` segmented iterator
trait (#158347)
The outer iterator needs to move to the next segment when calling
__compose.
Without this change, `find_segment_if` would never reach the end of the
join_view which caused erroneous result when calling `ranges::find` on a
join_view of bidirectional ranges.
Other specializations using the segmented iterator trait were likely to
be affected as well.
Fixes #158279
Fixes #93180
(cherry picked from commit d1b5607dc113016b74d0a58e95fed00ea9ad7950)
---
libcxx/include/__ranges/join_view.h | 9 +-
.../alg.find/ranges.find.pass.cpp | 121 --
2 files changed, 89 insertions(+), 41 deletions(-)
diff --git a/libcxx/include/__ranges/join_view.h
b/libcxx/include/__ranges/join_view.h
index 327b349f476a7..364f056d8d2cf 100644
--- a/libcxx/include/__ranges/join_view.h
+++ b/libcxx/include/__ranges/join_view.h
@@ -410,8 +410,13 @@ struct __segmented_iterator_traits<_JoinViewIterator> {
static constexpr _LIBCPP_HIDE_FROM_ABI _JoinViewIterator
__compose(__segment_iterator __seg_iter, __local_iterator __local_iter) {
-return _JoinViewIterator(
-std::move(__seg_iter).__get_data(),
std::move(__seg_iter).__get_iter(), std::move(__local_iter));
+auto&& __parent = std::move(__seg_iter).__get_data();
+auto&& __outer = std::move(__seg_iter).__get_iter();
+if (__local_iter == ranges::end(*__outer)) {
+ ++__outer;
+ return _JoinViewIterator(*__parent, __outer);
+}
+return _JoinViewIterator(__parent, __outer, std::move(__local_iter));
}
};
diff --git
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
index d7e6be9928a2d..5f730f0f5bba8 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
@@ -272,57 +272,100 @@ class Comparable {
friend bool operator==(const Comparable& lhs, long long rhs) { return
comparable_data[lhs.index_] == rhs; }
};
-void test_deque() {
- { // empty deque
-std::deque data;
-assert(std::ranges::find(data, 4) == data.end());
-assert(std::ranges::find(data.begin(), data.end(), 4) == data.end());
- }
-
- { // single element - match
-std::deque data = {4};
-assert(std::ranges::find(data, 4) == data.begin());
-assert(std::ranges::find(data.begin(), data.end(), 4) == data.begin());
- }
-
- { // single element - no match
-std::deque data = {3};
-assert(std::ranges::find(data, 4) == data.end());
-assert(std::ranges::find(data.begin(), data.end(), 4) == data.end());
- }
-
- // many elements
- for (auto size : {2, 3, 1023, 1024, 1025, 2047, 2048, 2049}) {
-{ // last element match
+void test_segmented_iterator_types() {
+ // Test the optimized find algorithm for types that implement the segment
iterator trait
+ // deque
+ {
+{ // empty deque
std::deque data;
- data.resize(size);
- std::fill(data.begin(), data.end(), 3);
- data[size - 1] = 4;
- assert(std::ranges::find(data, 4) == data.end() - 1);
- assert(std::ranges::find(data.begin(), data.end(), 4) == data.end() - 1);
+ assert(std::ranges::find(data, 4) == data.end());
+ assert(std::ranges::find(data.begin(), data.end(), 4) == data.end());
}
-{ // second-last element match
- std::deque data;
- data.resize(size);
- std::fill(data.begin(), data.end(), 3);
- data[size - 2] = 4;
- assert(std::ranges::find(data, 4) == data.end() - 2);
- assert(std::ranges::find(data.begin(), data.end(), 4) == data.end() - 2);
+{ // single element - match
+ std::deque data = {4};
+ assert(std::ranges::find(data, 4) == data.begin());
+ assert(std::ranges::find(data.begin(), data.end(), 4) == data.begin());
}
-{ // no match
- std::deque data;
- data.resize(size);
- std::fill(data.begin(), data.end(), 3);
+{ // single element - no match
+ std::deque data = {3};
assert(std::ranges::find(data, 4) == data.end());
assert(std::ranges::find(data.begin(), data.end(), 4) == data.end());
}
+
+// many elements
+for (auto size : {2, 3, 1023, 1024, 1025, 2047, 2048, 2049}) {
+ { // last element match
+std::deque data;
+data.resize(size);
+std::fill(data.begin(), data.end(), 3);
+data[size - 1] = 4;
+assert(std::ranges::find(data, 4) == data.end() - 1);
+assert(std::ranges::find(data.begin(), data.end(), 4) == data.end() -
1);
+ }
+
+ { // second-last element match
+std::deque data;
+data.resize(size)
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor exp2m1f16 implementation to header-only in src/__support/math folder. (PR #162019)
bassiounix wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/162019?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#162019** https://app.graphite.dev/github/pr/llvm/llvm-project/162019?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/162019?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#162017** https://app.graphite.dev/github/pr/llvm/llvm-project/162017?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161993** https://app.graphite.dev/github/pr/llvm/llvm-project/161993?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161992** https://app.graphite.dev/github/pr/llvm/llvm-project/161992?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161297** https://app.graphite.dev/github/pr/llvm/llvm-project/161297?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#161119** https://app.graphite.dev/github/pr/llvm/llvm-project/161119?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#159897** https://app.graphite.dev/github/pr/llvm/llvm-project/159897?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154868** https://app.graphite.dev/github/pr/llvm/llvm-project/154868?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154222** https://app.graphite.dev/github/pr/llvm/llvm-project/154222?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#154215** https://app.graphite.dev/github/pr/llvm/llvm-project/154215?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153582** https://app.graphite.dev/github/pr/llvm/llvm-project/153582?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#153427** https://app.graphite.dev/github/pr/llvm/llvm-project/153427?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152871** https://app.graphite.dev/github/pr/llvm/llvm-project/152871?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#152069** https://app.graphite.dev/github/pr/llvm/llvm-project/152069?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151883** https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151846** https://app.graphite.dev/github/pr/llvm/llvm-project/151846?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151837** https://app.graphite.dev/github/pr/llvm/llvm-project/151837?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151779** https://app.graphite.dev/github/pr/llvm/llvm-project/151779?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151399** https://app.graphite.dev/github/pr/llvm/llvm-project/151399?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#151012** https://app.graphite.dev/github/pr/llvm/llvm-project/151012?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#150993** h
