1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H
10#define _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H
11
12#include <__config>
13#include <__type_traits/is_floating_point.h>
14#include <__type_traits/is_same.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if _LIBCPP_STD_VER >= 20
23
24template <class _Tp>
25_LIBCPP_HIDE_FROM_ABI constexpr bool __is_fp80_long_double() {
26 // Only x87-fp80 long double has 64-bit mantissa
27 return __LDBL_MANT_DIG__ == 64 && std::is_same_v<_Tp, long double>;
28}
29
30template <class _Tp>
31_LIBCPP_HIDE_FROM_ABI constexpr bool __has_rmw_builtin() {
32 static_assert(std::is_floating_point_v<_Tp>);
33# ifndef _LIBCPP_COMPILER_CLANG_BASED
34 return false;
35# else
36 // The builtin __cxx_atomic_fetch_add errors during compilation for
37 // long double on platforms with fp80 format.
38 // For more details, see
39 // lib/Sema/SemaChecking.cpp function IsAllowedValueType
40 // LLVM Parser does not allow atomicrmw with x86_fp80 type.
41 // if (ValType->isSpecificBuiltinType(BuiltinType::LongDouble) &&
42 // &Context.getTargetInfo().getLongDoubleFormat() ==
43 // &llvm::APFloat::x87DoubleExtended())
44 // For more info
45 // https://llvm.org/PR68602
46 // https://reviews.llvm.org/D53965
47 return !std::__is_fp80_long_double<_Tp>();
48# endif
49}
50
51#endif
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H
56