-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++][atomic_ref] Use __atomic_fetch_{add,sub} builtins on floating-points whenever possible #135685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dalg24
wants to merge
7
commits into
llvm:main
Choose a base branch
from
dalg24:atomic_ref_fetch_add_sub_floating_point
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[libc++][atomic_ref] Use __atomic_fetch_{add,sub} builtins on floating-points whenever possible #135685
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8d9b5a
[libc++][atomic_ref] Use __atomic_fetch_{add,sub} builtins on floatin…
dalg24 246d885
Move x87-fp80 helper into new header and reuse
dalg24 f8de9b0
Merge branch 'main' of https://github.com/llvm/llvm-project into atom…
dalg24 c3453b6
Fixup robust against ADL
dalg24 e3879b3
Add missing pragma GCC system_header
dalg24 b0d63bd
Merge branch 'main' of https://github.com/llvm/llvm-project into atom…
dalg24 ed5f402
Annotate fetch_{add,sub} with XFAIL when using ThreadSanitizer
dalg24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H | ||
#define _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H | ||
|
||
#include <__config> | ||
#include <__type_traits/is_floating_point.h> | ||
#include <__type_traits/is_same.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 20 | ||
|
||
template <class _Tp> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool __is_fp80_long_double() { | ||
// Only x87-fp80 long double has 64-bit mantissa | ||
return __LDBL_MANT_DIG__ == 64 && std::is_same_v<_Tp, long double>; | ||
} | ||
|
||
template <class _Tp> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool __has_rmw_builtin() { | ||
static_assert(std::is_floating_point_v<_Tp>); | ||
# ifndef _LIBCPP_COMPILER_CLANG_BASED | ||
return false; | ||
# else | ||
// The builtin __cxx_atomic_fetch_add errors during compilation for | ||
// long double on platforms with fp80 format. | ||
// 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://github.com/llvm/llvm-project/issues/68602 | ||
// https://reviews.llvm.org/D53965 | ||
return !std::__is_fp80_long_double<_Tp>(); | ||
# endif | ||
} | ||
|
||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from
llvm-project/libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/fetch_add.pass.cpp
Lines 15 to 16 in 08d747c
Note that the #72893 issue referenced in the comment seems to indicate that only
long double
was problematic with ThreadSanitizer but it is not accurate because the instantiation of the tests are commented out forlong double
llvm-project/libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/fetch_add.pass.cpp
Lines 119 to 120 in 08d747c
Per a conversation on Discord with @huixie90, I propose to not hold up this PR and just use the same
XFAIL
annotation that we have in thestd::atomic<Floating>::fetch_{add,sub}
tests.