[libcxx-commits] [libcxx] [libc++][In progress] Floating Point Atomic (PR #67799)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 2 08:59:18 PDT 2023
================
@@ -136,6 +140,114 @@ struct atomic<_Tp*>
atomic& operator=(const atomic&) volatile = delete;
};
+#if _LIBCPP_STD_VER >= 20
+template <class _Tp> requires is_floating_point_v<_Tp>
+struct atomic<_Tp>
+ : public __atomic_base<_Tp>
+{
+ private:
+ // The builtin __cxx_atomic_fetch_add does not work for
+ // long double on some platforms with fp80 type
+ // There is no way on the libc++ side to test whether it is
+ // ok to use the builtin for a certain type.
+ // Therefore, we do not use the builtin here
+ // For more details, see
+ // lib/Sema/SemaChecking.cpp function IsAllowedValueType
+ // LLVM Parser does not allow atomicrmw with x86_fp80 type.
+ // if (ValType->isSpecificBuiltinType(BuiltinType::LongDouble) &&
+ // &Context.getTargetInfo().getLongDoubleFormat() ==
+ // &llvm::APFloat::x87DoubleExtended())
+ // For more info
+ // https://reviews.llvm.org/D53965
+
+ template <class _This, class _Operation>
+ _LIBCPP_HIDE_FROM_ABI static _Tp __rmw_op(_This&& __self, _Tp __operand, memory_order __m, _Operation __operation) {
+ _Tp __old = __self.load(memory_order_relaxed);
+ _Tp __new = __operation(__old, __operand);
+ while(!__self.compare_exchange_weak(__old, __new, __m, memory_order_relaxed)) {
+ if constexpr (std::is_same_v<_Tp, long double>){
+ // https://bugs.llvm.org/show_bug.cgi?id=48634
----------------
ldionne wrote:
Let's link to this instead: https://github.com/llvm/llvm-project/issues/47978, since it's the newer version of it.
https://github.com/llvm/llvm-project/pull/67799
More information about the libcxx-commits
mailing list