diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eef485..b3d9b69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,11 +172,13 @@ int main() { return 0; }" SNAPPY_HAVE_SSSE3) -check_cxx_source_compiles(" -#include -int main() { - return _bzhi_u32(0, 1); -}" SNAPPY_HAVE_BMI2) +if(SNAPPY_REQUIRE_AVX2) + check_cxx_source_compiles(" + #include + int main() { + return _bzhi_u32(0, 1); + }" SNAPPY_HAVE_BMI2) +endif(SNAPPY_REQUIRE_AVX2) check_cxx_source_compiles(" #include diff --git a/cmake/config.h.in b/cmake/config.h.in index 5ea2b5a..9520670 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -46,8 +46,8 @@ /* Define to 1 if you target processors with SSSE3+ and have . */ #cmakedefine01 SNAPPY_HAVE_SSSE3 -/* Define to 1 if you target processors with BMI2+ and have . */ -#cmakedefine01 SNAPPY_HAVE_BMI2 +/* Define if you target processors with BMI2+ and have . */ +#cmakedefine SNAPPY_HAVE_BMI2 /* Define to 1 if you target processors with NEON and have . */ #cmakedefine01 SNAPPY_HAVE_NEON diff --git a/snappy.cc b/snappy.cc index 670b87e..9002b3d 100644 --- a/snappy.cc +++ b/snappy.cc @@ -39,13 +39,11 @@ // GCC and Clang can build code with AVX2 enabled but BMI2 disabled, in which // case issuing BMI2 instructions results in a compiler error. #if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) -#define SNAPPY_HAVE_BMI2 1 -#else -#define SNAPPY_HAVE_BMI2 0 +#define SNAPPY_HAVE_BMI2 #endif #endif // !defined(SNAPPY_HAVE_BMI2) -#if SNAPPY_HAVE_BMI2 +#if defined(SNAPPY_HAVE_BMI2) // Please do not replace with . or with headers that assume more // advanced SSE versions without checking with all the OWNERS. #include @@ -957,7 +955,7 @@ static inline void Report(const char *algorithm, size_t compressed_size, static inline uint32_t ExtractLowBytes(uint32_t v, int n) { assert(n >= 0); assert(n <= 4); -#if SNAPPY_HAVE_BMI2 +#if defined(SNAPPY_HAVE_BMI2) return _bzhi_u32(v, 8 * n); #else // This needs to be wider than uint32_t otherwise `mask << 32` will be