[PATCH 6/6] libstdc++: Implement C++26 atomic reductions

soumyaa@nvidia.com soumyaa@nvidia.com
Sat Nov 14 05:45:11 GMT 2026


From: Soumya AR <soumyaa@nvidia.com>

This patch extends std::atomic to support integral reductions. These are
exposed under the __cpp_lib_atomic_reductions (202506L) feature test macro (as
mentioned in P3111R8).

For:
	atomic<int>::store_<op>
<op> = add, sub, and, or, xor, min, max

For:
	atomic<T*>::store_<op>
<op> = add, sub, min, max
Here, the value type for add/sub: ptrdiff_t, min/max: T*

This patch introduces an __atomic_reducible concept to check if (all) the
__atomic_store_<op> builtins are available in the compiler. If yes, we can call
the builtins directly.

If the builtins are not available, we call the corresponding fetch_<op> versions
and discard the result.

For pointer types, we cannot reuse the same concept for two reasons:

  1. Pointers are only supported by store_add/sub/min/max.
  2. For add and sub, the operation takes ptrdiff_t instead of the type
     of the first argument, which is the format for non-pointer ops.

Therefore, this patch introduces __atomic_ptr_reducible to check for the four
builtins supported by pointer types. We could have separate checks for each
individual builtin but that would be a lot of concepts. Maybe that approach
would be better though, if compilers could decide to implement only some of the
builtins. Would appreciate advice on what is more ideal here...

This also means we define the member functions of __atomic_base<_Tp*> to
check __atomic_ptr_reducible and call the fallback appropriately (instead
of just using the __atomic_impl version.)

Similar to fetch_min/max, we forward declare the relevant __atomic_impl helpers
before __atomic_base. We also define the __atomic_ptr_reducible concept there
for pointer versions of __atomic_base and __atomic_ref.

The patch also adds the following non-member functions:

	atomic_store_<op>
	atomic_store_<op>_explicit

These lower to the corresponding atomic member functions.

Bootstrapped and regression tested on aarch64-linux-gnu and
x86_64-linux-gnu.
Cross-compiled and regression tested for arm-linux-gnueabihf-armv7-a and
aarch64-linux-gnu without LSE.

OK for mainline?

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h: Add atomic reduction operations.
	* include/bits/version.def: Add atomic_reductions.
	* include/bits/version.h: Regenerate.
	* include/std/atomic: Add atomic reduction member and non-member
	functions.
	* src/c++23/std.cc.in: Export atomic_store_<op> and
	atomic_store_<op>_explicit.
	* testsuite/29_atomics/atomic/pointer_store_reductions.cc: New test.
	* testsuite/29_atomics/atomic_integral/nonmembers_store_reductions.cc:
	New test.
	* testsuite/29_atomics/atomic_ref/integral_store_reductions.cc:
	New test.
	* testsuite/29_atomics/atomic_ref/pointer_store_reductions.cc:
	New test.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
---
 libstdc++-v3/include/bits/atomic_base.h       | 356 ++++++++++++++++++
 libstdc++-v3/include/bits/version.def         |   8 +
 libstdc++-v3/include/bits/version.h           |  10 +
 libstdc++-v3/include/std/atomic               | 241 ++++++++++++
 libstdc++-v3/src/c++23/std.cc.in              |  16 +
 .../atomic/pointer_store_reductions.cc        |  59 +++
 .../nonmembers_store_reductions.cc            |  73 ++++
 .../atomic_ref/integral_store_reductions.cc   | 115 ++++++
 .../atomic_ref/pointer_store_reductions.cc    |  78 ++++
 9 files changed, 956 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/pointer_store_reductions.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic_integral/nonmembers_store_reductions.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic_ref/integral_store_reductions.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic_ref/pointer_store_reductions.cc

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 1d97ccf57b90..90ce524a9ed2 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -358,6 +358,45 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _Tp
       __fetch_max(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
 #endif
+
+#if __glibcxx_atomic_reductions
+    template<typename _Tp>
+      concept __atomic_ptr_reducible
+	= requires (_Tp __t, ptrdiff_t __d) {
+	    __atomic_store_add(&__t, __d, 0);
+	    __atomic_store_sub(&__t, __d, 0);
+	    __atomic_store_min(&__t, __t, 0);
+	    __atomic_store_max(&__t, __t, 0);
+	  };
+
+    template<typename _Tp>
+      void
+      __store_add(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_sub(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_and(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_or(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_xor(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_min(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+
+    template<typename _Tp>
+      void
+      __store_max(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept;
+#endif
   }
 
   template<typename _ITp>
@@ -725,6 +764,78 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		memory_order __m = memory_order_seq_cst) volatile noexcept
       { return __atomic_impl::__fetch_max(&_M_i, __i, __m); }
 #endif
+
+#if __glibcxx_atomic_reductions
+      _GLIBCXX_ALWAYS_INLINE void
+      store_add(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_add(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_add(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_add(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_sub(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_sub(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_sub(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_sub(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_and(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_and(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_and(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_and(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_or(__int_type __i,
+	       memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_or(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_or(__int_type __i,
+	       memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_or(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_xor(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_xor(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_xor(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_xor(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_min(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_min(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_min(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_min(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_max(__int_type __i,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { __atomic_impl::__store_max(&_M_i, __i, __m); }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_max(__int_type __i,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { __atomic_impl::__store_max(&_M_i, __i, __m); }
+#endif
     };
 
 
@@ -1019,6 +1130,88 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       fetch_max(__pointer_type __p,
 		memory_order __m = memory_order_seq_cst) volatile noexcept
       { return __atomic_impl::__fetch_max(&_M_p, __p, __m); }
+
+#if __glibcxx_atomic_reductions
+      _GLIBCXX_ALWAYS_INLINE void
+      store_add(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_add(&_M_p, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_add(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_add(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_add(&_M_p, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_add(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_sub(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_sub(&_M_p, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_sub(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_sub(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_sub(&_M_p, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_sub(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_min(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_min(&_M_p, __p, int(__m));
+	else
+	  (void) fetch_min(__p, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_min(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_min(&_M_p, __p, int(__m));
+	else
+	  (void) fetch_min(__p, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_max(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_max(&_M_p, __p, int(__m));
+	else
+	  (void) fetch_max(__p, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_max(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<__pointer_type>)
+	  __atomic_store_max(&_M_p, __p, int(__m));
+	else
+	  (void) fetch_max(__p, __m);
+      }
+#endif
 #endif
     };
 
@@ -1407,6 +1600,90 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return __oldval;
 	  }
       }
+
+#if __glibcxx_atomic_reductions
+    template<typename _Tp>
+      concept __atomic_reducible
+	= requires (_Tp __t) {
+	    __atomic_store_add(&__t, __t, 0);
+	    __atomic_store_sub(&__t, __t, 0);
+	    __atomic_store_and(&__t, __t, 0);
+	    __atomic_store_or(&__t, __t, 0);
+	    __atomic_store_xor(&__t, __t, 0);
+	    __atomic_store_min(&__t, __t, 0);
+	    __atomic_store_max(&__t, __t, 0);
+	  };
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_add(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_add(__ptr, __i, int(__m));
+	else
+	  (void) fetch_add(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_sub(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_sub(__ptr, __i, int(__m));
+	else
+	  (void) fetch_sub(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_and(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_and(__ptr, __i, int(__m));
+	else
+	  (void) fetch_and(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_or(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_or(__ptr, __i, int(__m));
+	else
+	  (void) fetch_or(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_xor(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_xor(__ptr, __i, int(__m));
+	else
+	  (void) fetch_xor(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_min(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_min(__ptr, __i, int(__m));
+	else
+	  (void) __fetch_min(__ptr, __i, __m);
+      }
+
+    template<typename _Tp>
+      _GLIBCXX_ALWAYS_INLINE void
+      __store_max(_Tp* __ptr, _Val<_Tp> __i, memory_order __m) noexcept
+      {
+	if constexpr (__atomic_reducible<_Tp>)
+	  __atomic_store_max(__ptr, __i, int(__m));
+	else
+	  (void) __fetch_max(__ptr, __i, __m);
+      }
+#endif
 #endif
   } // namespace __atomic_impl
 
@@ -1904,6 +2181,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return __atomic_impl::__fetch_max(this->_M_ptr, __i, __m); }
 #endif
 
+#if __glibcxx_atomic_reductions
+      void
+      store_add(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_add(this->_M_ptr, __i, __m); }
+
+      void
+      store_sub(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_sub(this->_M_ptr, __i, __m); }
+
+      void
+      store_and(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_and(this->_M_ptr, __i, __m); }
+
+      void
+      store_or(value_type __i,
+	       memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_or(this->_M_ptr, __i, __m); }
+
+      void
+      store_xor(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_xor(this->_M_ptr, __i, __m); }
+
+      void
+      store_min(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_min(this->_M_ptr, __i, __m); }
+
+      void
+      store_max(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      { __atomic_impl::__store_max(this->_M_ptr, __i, __m); }
+#endif
+
       _GLIBCXX_ALWAYS_INLINE value_type
       operator++(int) const noexcept
       { return fetch_add(1); }
@@ -2029,6 +2343,48 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       fetch_max(value_type __i,
 		memory_order __m = memory_order_seq_cst) const noexcept
       { return __atomic_impl::__fetch_max(this->_M_ptr, __i, __m); }
+
+#if __glibcxx_atomic_reductions
+      _GLIBCXX_ALWAYS_INLINE void
+      store_add(difference_type __d,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<value_type>)
+	  __atomic_store_add(this->_M_ptr, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_add(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_sub(difference_type __d,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<value_type>)
+	  __atomic_store_sub(this->_M_ptr, _S_type_size(__d), int(__m));
+	else
+	  (void) fetch_sub(__d, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_min(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<value_type>)
+	  __atomic_store_min(this->_M_ptr, __i, int(__m));
+	else
+	  (void) fetch_min(__i, __m);
+      }
+
+      _GLIBCXX_ALWAYS_INLINE void
+      store_max(value_type __i,
+		memory_order __m = memory_order_seq_cst) const noexcept
+      {
+	if constexpr (__atomic_impl::__atomic_ptr_reducible<value_type>)
+	  __atomic_store_max(this->_M_ptr, __i, int(__m));
+	else
+	  (void) fetch_max(__i, __m);
+      }
+#endif
 #endif
 
       value_type
diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
index 914c1d40db7d..c4f2ce135f6a 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -816,6 +816,14 @@ ftms = {
   };
 };
 
+ftms = {
+  name = atomic_reductions;
+  values = {
+    v = 202506;
+    cxxmin = 26;
+  };
+};
+
 ftms = {
   name = atomic_lock_free_type_aliases;
   values = {
diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
index 2a12a69ed98b..0835b0d93544 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -903,6 +903,16 @@
 #endif /* !defined(__cpp_lib_atomic_min_max) */
 #undef __glibcxx_want_atomic_min_max
 
+#if !defined(__cpp_lib_atomic_reductions)
+# if (__cplusplus >  202302L)
+#  define __glibcxx_atomic_reductions 202506L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_reductions)
+#   define __cpp_lib_atomic_reductions 202506L
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_atomic_reductions) */
+#undef __glibcxx_want_atomic_reductions
+
 #if !defined(__cpp_lib_atomic_lock_free_type_aliases)
 # if (__cplusplus >= 202002L) && ((__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2)
 #  define __glibcxx_atomic_lock_free_type_aliases 201907L
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index b53872c81bd8..d48f2550045d 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -44,6 +44,7 @@
 #define __glibcxx_want_atomic_flag_test
 #define __glibcxx_want_atomic_float
 #define __glibcxx_want_atomic_min_max
+#define __glibcxx_want_atomic_reductions
 #define __glibcxx_want_atomic_ref
 #define __glibcxx_want_atomic_lock_free_type_aliases
 #define __glibcxx_want_atomic_value_initialization
@@ -741,6 +742,60 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		memory_order __m = memory_order_seq_cst) volatile noexcept
       { return _M_b.fetch_max(__p, __m); }
 #endif
+
+#if __glibcxx_atomic_reductions
+      void
+      store_add(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	static_assert( is_object_v<_Tp>, "pointer to object type" );
+	_M_b.store_add(__d, __m);
+      }
+
+      void
+      store_add(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	static_assert( is_object_v<_Tp>, "pointer to object type" );
+	_M_b.store_add(__d, __m);
+      }
+
+      void
+      store_sub(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) noexcept
+      {
+	static_assert( is_object_v<_Tp>, "pointer to object type" );
+	_M_b.store_sub(__d, __m);
+      }
+
+      void
+      store_sub(ptrdiff_t __d,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      {
+	static_assert( is_object_v<_Tp>, "pointer to object type" );
+	_M_b.store_sub(__d, __m);
+      }
+
+      void
+      store_min(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { _M_b.store_min(__p, __m); }
+
+      void
+      store_min(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { _M_b.store_min(__p, __m); }
+
+      void
+      store_max(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) noexcept
+      { _M_b.store_max(__p, __m); }
+
+      void
+      store_max(__pointer_type __p,
+		memory_order __m = memory_order_seq_cst) volatile noexcept
+      { _M_b.store_max(__p, __m); }
+#endif
     };
 
 
@@ -1596,6 +1651,106 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			      memory_order __m) noexcept
     { return __a->fetch_xor(__i, __m); }
 
+#ifdef __cpp_lib_atomic_reductions
+  template<typename _ITp>
+    inline void
+    atomic_store_add_explicit(atomic<_ITp>* __a,
+			      __atomic_diff_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_add(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_add_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_diff_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_add(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_sub_explicit(atomic<_ITp>* __a,
+			      __atomic_diff_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_sub(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_sub_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_diff_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_sub(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_and_explicit(atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_and(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_and_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_and(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_or_explicit(atomic<_ITp>* __a,
+			     __atomic_val_t<_ITp> __i,
+			     memory_order __m) noexcept
+    { __a->store_or(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_or_explicit(volatile atomic<_ITp>* __a,
+			     __atomic_val_t<_ITp> __i,
+			     memory_order __m) noexcept
+    { __a->store_or(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_xor_explicit(atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_xor(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_xor_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_xor(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_min_explicit(atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_min(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_min_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_min(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_max_explicit(atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_max(__i, __m); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_max_explicit(volatile atomic<_ITp>* __a,
+			      __atomic_val_t<_ITp> __i,
+			      memory_order __m) noexcept
+    { __a->store_max(__i, __m); }
+#endif
+
 #ifdef __cpp_lib_atomic_min_max
   template<typename _Tp>
     inline _Tp
@@ -1686,6 +1841,92 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		     __atomic_val_t<_ITp> __i) noexcept
     { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
 
+#ifdef __cpp_lib_atomic_reductions
+  template<typename _ITp>
+    inline void
+    atomic_store_add(atomic<_ITp>* __a,
+		     __atomic_diff_t<_ITp> __i) noexcept
+    { atomic_store_add_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_add(volatile atomic<_ITp>* __a,
+		     __atomic_diff_t<_ITp> __i) noexcept
+    { atomic_store_add_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_sub(atomic<_ITp>* __a,
+		     __atomic_diff_t<_ITp> __i) noexcept
+    { atomic_store_sub_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_sub(volatile atomic<_ITp>* __a,
+		     __atomic_diff_t<_ITp> __i) noexcept
+    { atomic_store_sub_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_and(atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_and_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_and(volatile atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_and_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_or(atomic<_ITp>* __a,
+		    __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_or_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_or(volatile atomic<_ITp>* __a,
+		    __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_or_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_xor(atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_xor_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_xor(volatile atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_xor_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_min(atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_min_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_min(volatile atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_min_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_max(atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_max_explicit(__a, __i, memory_order_seq_cst); }
+
+  template<typename _ITp>
+    inline void
+    atomic_store_max(volatile atomic<_ITp>* __a,
+		     __atomic_val_t<_ITp> __i) noexcept
+    { atomic_store_max_explicit(__a, __i, memory_order_seq_cst); }
+#endif
+
 #ifdef __cpp_lib_atomic_min_max
   template<typename _Tp>
     inline _Tp
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index d05902466d97..547814772309 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -629,6 +629,22 @@ export namespace std
   using std::atomic_size_t;
   using std::atomic_store;
   using std::atomic_store_explicit;
+#ifdef __cpp_lib_atomic_reductions
+  using std::atomic_store_add;
+  using std::atomic_store_add_explicit;
+  using std::atomic_store_and;
+  using std::atomic_store_and_explicit;
+  using std::atomic_store_or;
+  using std::atomic_store_or_explicit;
+  using std::atomic_store_sub;
+  using std::atomic_store_sub_explicit;
+  using std::atomic_store_xor;
+  using std::atomic_store_xor_explicit;
+  using std::atomic_store_min;
+  using std::atomic_store_min_explicit;
+  using std::atomic_store_max;
+  using std::atomic_store_max_explicit;
+#endif
   using std::atomic_thread_fence;
   using std::atomic_uchar;
   using std::atomic_uint;
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/pointer_store_reductions.cc b/libstdc++-v3/testsuite/29_atomics/atomic/pointer_store_reductions.cc
new file mode 100644
index 000000000000..071240a81944
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/pointer_store_reductions.cc
@@ -0,0 +1,59 @@
+// { dg-do run { target c++26 } }
+// { dg-require-atomic-cmpxchg-word "" }
+// { dg-add-options libatomic }
+
+#include <atomic>
+#include <testsuite_hooks.h>
+
+void test01() {
+  long arr[10] = {};
+
+  const auto mo = std::memory_order_relaxed;
+  std::atomic<long *> a(arr);
+
+  atomic_store_add(&a, 3);
+  VERIFY(a == arr + 3);
+  atomic_store_add_explicit(&a, 2, mo);
+  VERIFY(a == arr + 5);
+  atomic_store_sub(&a, 1);
+  VERIFY(a == arr + 4);
+  atomic_store_sub_explicit(&a, 4, mo);
+  VERIFY(a == arr);
+
+  atomic_store_max(&a, arr + 5);
+  VERIFY(a == arr + 5);
+  atomic_store_max_explicit(&a, arr + 2, mo);
+  VERIFY(a == arr + 5);
+
+  atomic_store_min(&a, arr + 3);
+  VERIFY(a == arr + 3);
+  atomic_store_min_explicit(&a, arr + 5, mo);
+  VERIFY(a == arr + 3);
+}
+
+void test02() {
+  char arr[10] = {};
+
+  const auto mo = std::memory_order_relaxed;
+  std::atomic<char *> a(arr);
+
+  atomic_store_add(&a, 3);
+  VERIFY(a == arr + 3);
+  atomic_store_sub_explicit(&a, 1, mo);
+  VERIFY(a == arr + 2);
+
+  atomic_store_max(&a, arr + 5);
+  VERIFY(a == arr + 5);
+  atomic_store_max_explicit(&a, arr + 2, mo);
+  VERIFY(a == arr + 5);
+
+  atomic_store_min(&a, arr + 3);
+  VERIFY(a == arr + 3);
+  atomic_store_min_explicit(&a, arr + 5, mo);
+  VERIFY(a == arr + 3);
+}
+
+int main() {
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_integral/nonmembers_store_reductions.cc b/libstdc++-v3/testsuite/29_atomics/atomic_integral/nonmembers_store_reductions.cc
new file mode 100644
index 000000000000..33faa8e3f3c6
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_integral/nonmembers_store_reductions.cc
@@ -0,0 +1,73 @@
+// { dg-do compile { target c++26 } }
+// { dg-require-atomic-builtins "" }
+
+#include <atomic>
+
+void
+test01()
+{
+  volatile std::atomic<int> v;
+  std::atomic<long> a;
+  const std::memory_order mo = std::memory_order_seq_cst;
+  int i = 0;
+  long l = 0;
+
+  static_assert( std::is_void<decltype(atomic_store_add(&v, i))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_add(&a, l))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_add_explicit(&v, i, mo))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_add_explicit(&a, l, mo))>::value, "" );
+
+  static_assert( std::is_void<decltype(atomic_store_min(&v, i))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_min(&a, l))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_min_explicit(&v, i, mo))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_min_explicit(&a, l, mo))>::value, "" );
+
+  static_assert( std::is_void<decltype(atomic_store_max(&v, i))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_max(&a, l))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_max_explicit(&v, i, mo))>::value, "" );
+  static_assert( std::is_void<decltype(atomic_store_max_explicit(&a, l, mo))>::value, "" );
+}
+
+void
+test02()
+{
+  volatile std::atomic<long> v;
+  std::atomic<long> a;
+  std::memory_order mo = std::memory_order_seq_cst;
+  const int i = 0;
+
+  atomic_store_add(&v, i);
+  atomic_store_add(&a, i);
+  atomic_store_add_explicit(&v, i, mo);
+  atomic_store_add_explicit(&a, i, mo);
+
+  atomic_store_sub(&v, i);
+  atomic_store_sub(&a, i);
+  atomic_store_sub_explicit(&v, i, mo);
+  atomic_store_sub_explicit(&a, i, mo);
+
+  atomic_store_and(&v, i);
+  atomic_store_and(&a, i);
+  atomic_store_and_explicit(&v, i, mo);
+  atomic_store_and_explicit(&a, i, mo);
+
+  atomic_store_or(&v, i);
+  atomic_store_or(&a, i);
+  atomic_store_or_explicit(&v, i, mo);
+  atomic_store_or_explicit(&a, i, mo);
+
+  atomic_store_xor(&v, i);
+  atomic_store_xor(&a, i);
+  atomic_store_xor_explicit(&v, i, mo);
+  atomic_store_xor_explicit(&a, i, mo);
+
+  atomic_store_min(&v, i);
+  atomic_store_min(&a, i);
+  atomic_store_min_explicit(&v, i, mo);
+  atomic_store_min_explicit(&a, i, mo);
+
+  atomic_store_max(&v, i);
+  atomic_store_max(&a, i);
+  atomic_store_max_explicit(&v, i, mo);
+  atomic_store_max_explicit(&a, i, mo);
+}
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/integral_store_reductions.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/integral_store_reductions.cc
new file mode 100644
index 000000000000..864a4e87df29
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/integral_store_reductions.cc
@@ -0,0 +1,115 @@
+// { dg-do run { target c++26 } }
+// { dg-require-atomic-cmpxchg-word "" }
+// { dg-add-options libatomic }
+
+#include <atomic>
+#include <limits.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  int value;
+  const auto mo = std::memory_order_relaxed;
+
+  {
+    std::atomic_ref<int> a(value);
+
+    a = 10;
+    a.store_add(5);
+    VERIFY( a == 15 );
+
+    a.store_sub(3, mo);
+    VERIFY( a == 12 );
+
+    a = 0b1100;
+    a.store_and(0b1010, mo);
+    VERIFY( a == 0b1000 );
+
+    a.store_or(0b0001);
+    VERIFY( a == 0b1001 );
+
+    a.store_xor(0b1111, mo);
+    VERIFY( a == 0b0110 );
+
+    a = 50;
+    a.store_min(25);
+    VERIFY( a == 25 );
+
+    a.store_max(40);
+    VERIFY( a == 40 );
+  }
+
+  VERIFY( value == 40 );
+}
+
+void
+test02()
+{
+  unsigned short value;
+
+  {
+    std::atomic_ref<unsigned short> a(value);
+
+    a = 100;
+    a.store_min(50);
+    VERIFY( a == 50 );
+
+    a.store_max(200);
+    VERIFY( a == 200 );
+  }
+
+  VERIFY( value == 200 );
+}
+
+void
+test03()
+{
+  int value = -5;
+
+  {
+    std::atomic_ref<int> a(value);
+
+    a.store_min(-10);
+    VERIFY( a == -10 );
+
+    a.store_max(5);
+    VERIFY( a == 5 );
+  }
+
+  VERIFY( value == 5 );
+}
+
+void
+test04()
+{
+  int value = INT_MIN;
+
+  {
+    std::atomic_ref<int> a(value);
+
+    a.store_max(INT_MAX);
+    VERIFY( a == INT_MAX );
+
+    a.store_min(INT_MIN);
+    VERIFY( a == INT_MIN );
+
+    a.store_max(INT_MIN);
+    VERIFY( a == INT_MIN );
+
+    a = INT_MAX;
+    a.store_min(INT_MAX);
+    VERIFY( a == INT_MAX );
+  }
+
+  VERIFY( value == INT_MAX );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+}
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/pointer_store_reductions.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/pointer_store_reductions.cc
new file mode 100644
index 000000000000..85d8a2050d15
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/pointer_store_reductions.cc
@@ -0,0 +1,78 @@
+// { dg-do run { target c++26 } }
+// { dg-require-atomic-cmpxchg-word "" }
+// { dg-add-options libatomic }
+
+#include <atomic>
+#include <testsuite_hooks.h>
+
+void test01() {
+  long arr[10] = {};
+  long *value;
+
+  {
+    const auto mo = std::memory_order_relaxed;
+    std::atomic_ref<long *> a(value);
+    bool ok = a.is_lock_free();
+    if constexpr (std::atomic_ref<long *>::is_always_lock_free)
+      VERIFY(ok);
+    a = arr;
+
+    a.store_add(3);
+    VERIFY(a == arr + 3);
+    a.store_add(2, mo);
+    VERIFY(a == arr + 5);
+    a.store_sub(1);
+    VERIFY(a == arr + 4);
+    a.store_sub(4, mo);
+    VERIFY(a == arr);
+
+
+    a.store_max(arr + 5);
+    VERIFY(a == arr + 5);
+    a.store_max(arr + 2, mo);
+    VERIFY(a == arr + 5);
+
+    a.store_min(arr + 3);
+    VERIFY(a == arr + 3);
+    a.store_min(arr + 5, mo);
+    VERIFY(a == arr + 3);
+  }
+
+  VERIFY(value == arr + 3);
+}
+
+void test02() {
+  char arr[10] = {};
+  char *value;
+
+  {
+    const auto mo = std::memory_order_relaxed;
+    std::atomic_ref<char *> a(value);
+    bool ok = a.is_lock_free();
+    if constexpr (std::atomic_ref<char *>::is_always_lock_free)
+      VERIFY(ok);
+    a = arr;
+
+    a.store_add(3);
+    VERIFY(a == arr + 3);
+    a.store_sub(1, mo);
+    VERIFY(a == arr + 2);
+
+    a.store_max(arr + 5);
+    VERIFY(a == arr + 5);
+    a.store_max(arr + 2, mo);
+    VERIFY(a == arr + 5);
+
+    a.store_min(arr + 3);
+    VERIFY(a == arr + 3);
+    a.store_min(arr + 5, mo);
+    VERIFY(a == arr + 3);
+  }
+
+  VERIFY(value == arr + 3);
+}
+
+int main() {
+  test01();
+  test02();
+}
-- 
2.43.0



More information about the Libstdc++ mailing list