Skip to content

Availability of the immintrin.h should not implicitly disable support… #105

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ int main() {
return 0;
}" SNAPPY_HAVE_SSSE3)

check_cxx_source_compiles("
#include <immintrin.h>
int main() {
return _bzhi_u32(0, 1);
}" SNAPPY_HAVE_BMI2)
if(SNAPPY_REQUIRE_AVX2)
check_cxx_source_compiles("
#include <immintrin.h>
int main() {
return _bzhi_u32(0, 1);
}" SNAPPY_HAVE_BMI2)
endif(SNAPPY_REQUIRE_AVX2)

check_cxx_source_compiles("
#include <arm_neon.h>
Expand Down
4 changes: 2 additions & 2 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
/* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */
#cmakedefine01 SNAPPY_HAVE_SSSE3

/* Define to 1 if you target processors with BMI2+ and have <bmi2intrin.h>. */
#cmakedefine01 SNAPPY_HAVE_BMI2
/* Define if you target processors with BMI2+ and have <bmi2intrin.h>. */
#cmakedefine SNAPPY_HAVE_BMI2

/* Define to 1 if you target processors with NEON and have <arm_neon.h>. */
#cmakedefine01 SNAPPY_HAVE_NEON
Expand Down
8 changes: 3 additions & 5 deletions snappy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <x86intrin.h>. or with headers that assume more
// advanced SSE versions without checking with all the OWNERS.
#include <immintrin.h>
Expand Down Expand Up @@ -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
Expand Down