From: Radoslaw Zarzynski Date: Thu, 8 Mar 2018 13:40:17 +0000 (+0100) Subject: Fix the selection of the fast CRC32 path in Ceph Luminous. X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fheads%2Fceph-luminous;p=rocksdb.git Fix the selection of the fast CRC32 path in Ceph Luminous. This ugly patch selectively adds the `-msse4.2` for compiling `util/crc32c.cc` file when a building machine's toolchain had successfully compiled a simple test program. The CXXFLAGS are enriched even when `WITH_SSE42` is not set as, in Ceph, there is no possibility to use the global switch because of lack of proper run-time SSE4.2 check in other places IIUC. Although the problem is fixed in `master` of RocksDB, the fix cannot be backported because the CRC32-related stuff diverged too much (`HAVE_POWER8`, `HAVE_PCLMUL`, `NO_THREEWAY_CRC32C`). The patch strictly targets Ceph Luminous branch. Fixes: http://tracker.ceph.com/issues/22534 Signed-off-by: Radoslaw Zarzynski --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f82b33a..983f0be9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,24 @@ else() endif() endif() +include(CheckCXXSourceCompiles) +if(NOT MSVC) + set(CMAKE_REQUIRED_FLAGS "-msse4.2") +endif() +CHECK_CXX_SOURCE_COMPILES(" +#include +#include +int main() { + volatile uint32_t x = _mm_crc32_u32(0, 0); +} +" HAVE_SSE42) +unset(CMAKE_REQUIRED_FLAGS) +if(HAVE_SSE42 AND NOT WITH_SSE42) +set_source_files_properties( + util/crc32c.cc + PROPERTIES COMPILE_FLAGS "-msse4.2") +endif() + option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON) if(FAIL_ON_WARNINGS) if(MSVC) diff --git a/util/crc32c.cc b/util/crc32c.cc index 2c8cb097..2fe2d663 100644 --- a/util/crc32c.cc +++ b/util/crc32c.cc @@ -327,15 +327,6 @@ static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) { table0_[c >> 24]; } -#if defined(HAVE_SSE42) && defined(__GNUC__) -#if defined(__clang__) -#if __has_cpp_attribute(gnu::target) -__attribute__ ((target ("sse4.2"))) -#endif -#else // gcc supports this since 4.4 -__attribute__ ((target ("sse4.2"))) -#endif -#endif static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) { #ifdef __SSE4_2__ #ifdef __LP64__