Skip to content

Commit 43ef82b

Browse files
committed
Availability of the immintrin.h should not implicitly disable support of all pre-Haswell CPUs. User needs to explicitly specify AVX2 requirement via SNAPPY_REQUIRE_AVX2 if it was their intention.
1 parent 4dd277f commit 43ef82b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

CMakeLists.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,13 @@ int main() {
163163
return 0;
164164
}" SNAPPY_HAVE_SSSE3)
165165

166-
check_cxx_source_compiles("
167-
#include <immintrin.h>
168-
int main() {
169-
return _bzhi_u32(0, 1);
170-
}" SNAPPY_HAVE_BMI2)
166+
if(SNAPPY_REQUIRE_AVX2)
167+
check_cxx_source_compiles("
168+
#include <immintrin.h>
169+
int main() {
170+
return _bzhi_u32(0, 1);
171+
}" SNAPPY_HAVE_BMI2)
172+
endif(SNAPPY_REQUIRE_AVX2)
171173

172174
include(CheckSymbolExists)
173175
check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP)

cmake/config.h.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
/* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */
5050
#cmakedefine01 SNAPPY_HAVE_SSSE3
5151

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

5555
/* Define to 1 if your processor stores words with the most significant byte
5656
first (like Motorola and SPARC, unlike Intel and VAX). */

snappy.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
// GCC and Clang can build code with AVX2 enabled but BMI2 disabled, in which
5151
// case issuing BMI2 instructions results in a compiler error.
5252
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__))
53-
#define SNAPPY_HAVE_BMI2 1
54-
#else
55-
#define SNAPPY_HAVE_BMI2 0
53+
#define SNAPPY_HAVE_BMI2
5654
#endif
5755
#endif // !defined(SNAPPY_HAVE_BMI2)
5856

@@ -62,7 +60,7 @@
6260
#include <tmmintrin.h>
6361
#endif
6462

65-
#if SNAPPY_HAVE_BMI2
63+
#if defined(SNAPPY_HAVE_BMI2)
6664
// Please do not replace with <x86intrin.h>. or with headers that assume more
6765
// advanced SSE versions without checking with all the OWNERS.
6866
#include <immintrin.h>
@@ -749,7 +747,7 @@ static inline void Report(const char *algorithm, size_t compressed_size,
749747
static inline uint32_t ExtractLowBytes(uint32_t v, int n) {
750748
assert(n >= 0);
751749
assert(n <= 4);
752-
#if SNAPPY_HAVE_BMI2
750+
#if defined(SNAPPY_HAVE_BMI2)
753751
return _bzhi_u32(v, 8 * n);
754752
#else
755753
// This needs to be wider than uint32_t otherwise `mask << 32` will be

0 commit comments

Comments
 (0)