[libcxx-commits] [libcxx] [libcxx] p3008 atomic fp min/max (PR #186716)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 21 07:29:03 PDT 2026


================
@@ -372,6 +378,44 @@ struct atomic<_Tp> : __atomic_base<_Tp> {
     return __rmw_op(std::forward<_This>(__self), __operand, __m, __minus, __builtin_op);
   }
 
+  template <class _This>
+  _LIBCPP_HIDE_FROM_ABI static _Tp __fetch_min(_This&& __self, _Tp __operand, memory_order __m) {
+    auto __op = [](_Tp __a, _Tp __b) { return std::__math::fmin(__a, __b); };
----------------
huixie90 wrote:

Could you please explain the reason why the existing builtin does not work? 

the c11 builtin `__c11_atomic_fetch_max` and clang's gcc builtin `__atomic_fetch_max` already supports to generate LLVM IR
```
atomicrmw fmax
```

https://godbolt.org/z/q5j1qb68M

However,  the `x87_80 long double` might not work, in which case you can always do `if constexpr` to check if the builtin is supported and fallback to the CAS loop



https://github.com/llvm/llvm-project/pull/186716


More information about the libcxx-commits mailing list