[libcxx-commits] [libcxx] [libc++] Implement P0493R5: Atomic minimum/maximum (PR #180333)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Feb 22 01:23:30 PST 2026
huixie90 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.
```cpp
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
```cpp
if constexpr __atomic_fetch_minmaxable<_Tp>
// builtin
else {
// cas loop
}
```
https://github.com/llvm/llvm-project/pull/180333
More information about the libcxx-commits
mailing list