From: Kefu Chai Date: Thu, 9 Dec 2021 17:12:34 +0000 (+0800) Subject: cmake: do not use GCC extension when detecting 16-bit atomic op X-Git-Tag: v18.0.0~837^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4c726846e44884889bdf6f3e76f7dec574dd431e;p=ceph.git cmake: do not use GCC extension when detecting 16-bit atomic op we have following error when trying to compile the C++ source file on mipsel: /usr/bin/c++ -DHAVE_CXX11_ATOMIC -g -O2 -ffile-prefix-map=/<>=. -fstack-protector-strong -Wformat -Werror=format-security -g1 -Wdate-time -D_FORTIFY_SOURCE=2 -std=c++11 -fPIE -o CMakeFiles/cmTC_9f34f.dir/src.cxx.o -c /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx:15:44: error: template argument 1 is invalid 15 | bool atomic16(std::atomic *ptr) | ^ /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx:15:44: error: template argument 1 is invalid /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx:15:44: error: template argument 1 is invalid /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx:15:44: error: template argument 1 is invalid /<>/obj-mipsel-linux-gnu/CMakeFiles/CMakeTmp/src.cxx:15:47: error: ‘ptr’ was not declared in this scope 15 | bool atomic16(std::atomic *ptr) | ^~~ the compiler was GCC 11.2.0. in this change, instead of detecting the architecture, check for the macro of `__SIZEOF_INT128__`, which is respected by GCC and Clang. so it's more readable. also, instead of using the `unsigned __int128` type provided as a GCC extension, use a struct to mimic the use case of boost::lockfree library. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/CheckCxxAtomic.cmake b/cmake/modules/CheckCxxAtomic.cmake index da2be5206d63..02d55612e818 100644 --- a/cmake/modules/CheckCxxAtomic.cmake +++ b/cmake/modules/CheckCxxAtomic.cmake @@ -10,8 +10,9 @@ function(check_cxx_atomics var) check_cxx_source_compiles(" #include #include +#include -#if defined(__s390x__) || defined(__mips__) +#if defined(__SIZEOF_INT128__) // Boost needs 16-byte atomics for tagged pointers. // These are implemented via inline instructions on the platform // if 16-byte alignment can be proven, and are delegated to libatomic @@ -21,13 +22,26 @@ function(check_cxx_atomics var) // We specifically test access via an otherwise unknown pointer here // to ensure we get the most complex case. If this access can be // done without libatomic, then all accesses can be done. -bool atomic16(std::atomic *ptr) +struct tagged_ptr { + int* ptr; + std::size_t tag; +}; + +void atomic16(std::atomic *ptr) { - return *ptr != 0; + tagged_ptr p{nullptr, 1}; + ptr->store(p); + tagged_ptr f = ptr->load(); + tagged_ptr new_tag{nullptr, 0}; + ptr->compare_exchange_strong(f, new_tag); } #endif int main() { +#if defined(__SIZEOF_INT128__) + std::atomic ptr; + atomic16(&ptr); +#endif std::atomic w1; std::atomic w2; std::atomic w4;