Skip to content

Commit b539372

Browse files
authored
Merge pull request ceph#44264 from tchaikov/wip-mipel
cmake: do not use GCC extension when detecting 16-byte atomic op Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents a7c1c50 + 4c72684 commit b539372

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cmake/modules/CheckCxxAtomic.cmake

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ function(check_cxx_atomics var)
1010
check_cxx_source_compiles("
1111
#include <atomic>
1212
#include <cstdint>
13+
#include <cstddef>
1314
14-
#if defined(__s390x__) || defined(__mips__)
15+
#if defined(__SIZEOF_INT128__)
1516
// Boost needs 16-byte atomics for tagged pointers.
1617
// These are implemented via inline instructions on the platform
1718
// if 16-byte alignment can be proven, and are delegated to libatomic
@@ -21,13 +22,26 @@ function(check_cxx_atomics var)
2122
// We specifically test access via an otherwise unknown pointer here
2223
// to ensure we get the most complex case. If this access can be
2324
// done without libatomic, then all accesses can be done.
24-
bool atomic16(std::atomic<unsigned __int128> *ptr)
25+
struct tagged_ptr {
26+
int* ptr;
27+
std::size_t tag;
28+
};
29+
30+
void atomic16(std::atomic<tagged_ptr> *ptr)
2531
{
26-
return *ptr != 0;
32+
tagged_ptr p{nullptr, 1};
33+
ptr->store(p);
34+
tagged_ptr f = ptr->load();
35+
tagged_ptr new_tag{nullptr, 0};
36+
ptr->compare_exchange_strong(f, new_tag);
2737
}
2838
#endif
2939
3040
int main() {
41+
#if defined(__SIZEOF_INT128__)
42+
std::atomic<tagged_ptr> ptr;
43+
atomic16(&ptr);
44+
#endif
3145
std::atomic<uint8_t> w1;
3246
std::atomic<uint16_t> w2;
3347
std::atomic<uint32_t> w4;

0 commit comments

Comments
 (0)