[libcxx-commits] [libcxx] [libc++] Implement P0493R5: Atomic minimum/maximum (PR #180333)
Connector Switch via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Mar 8 05:06:59 PDT 2026
c8ef wrote:
> > > BTW, I created a patch that tries to make progress on fetch_{min,max} on pointer types #182699
> >
> >
> > Thanks for the quick fix! This is exactly what I like to do. You beat me to it : )
> > > > @huixie90 I'm wondering if it's feasible to split the paper implementation into 2 PRs - one for the integral part, and one for the pointers (which depends on the compiler change). It also looks like GCC doesn't support pointer fetch max/min either.
> > >
> > >
> > > It is OK to split the paper but we will need to correctly update the paper status and release notes, and not to close the Github issue. Alternatively, you can use the fallback CAS loop to implement the pointer version.
> >
> >
> > Even if this fix gets merged quickly, it will still take some time before we can utilize it in CI. If we want to use the builtins, we also need to verify that it supports pointers. Alternatively, we could go with the CAS loop for everything - though that feels a bit odd given that the compiler already provides some support for the builtins.
> > So, WDYT? Should we use CAS to complete the paper, or use the builtins to implement the integral part?
>
> I think we can do something similar to what libstdc++ does.
>
> ```c++
> template <class _Tp>
> concept __atomic_fetch_minmaxable = requires (_Atomic(_Tp) __x, _Tp __y)
> {
> __c11_atomic_fetch_min(&__x, __y, 0);
> __c11_atomic_fetch_max(&__x, __y, 0);
> };
> ```
>
> and then you can in the implementation
>
> ```c++
> if constexpr __atomic_fetch_minmaxable<_Tp>
> // builtin
> else {
> // cas loop
> }
> ```
Sorry for the delayed update.
Since the CAS-based fallback implementations need to be written separately for C11, GCC, and `atomic_ref`, we currently end up duplicating the same logic three times. Given that `atomic_ref` already uses GCC-style intrinsics, I've been exploring ways to consolidate the two - but haven't yet found a clean approach that eliminates the duplication without affecting the ABI.
https://github.com/llvm/llvm-project/pull/180333
More information about the libcxx-commits
mailing list