From ab9a57280d7d56a76a9e9a2d860fe205eb45221f Mon Sep 17 00:00:00 2001 From: Jun He Date: Fri, 9 Jul 2021 16:49:06 +0800 Subject: Fix SSE3 and BMI2 compile error After SHUFFLE code blocks are refactored, "tmmintrin.h" is missed, and bmi2 code part will have build failure as type conflicts. Signed-off-by: Jun He Change-Id: I7800cd7e050f4d349e5a227206b14b9c566e547f --- snappy-internal.h | 35 +++++++++++++++++++++++++++++++++-- snappy.cc | 21 --------------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/snappy-internal.h b/snappy-internal.h index f1aafa9..71d19c0 100644 --- a/snappy-internal.h +++ b/snappy-internal.h @@ -33,13 +33,44 @@ #include "snappy-stubs-internal.h" +#if !defined(SNAPPY_HAVE_BMI2) +// __BMI2__ is defined by GCC and Clang. Visual Studio doesn't target BMI2 +// specifically, but it does define __AVX2__ when AVX2 support is available. +// Fortunately, AVX2 was introduced in Haswell, just like BMI2. +// +// BMI2 is not defined as a subset of AVX2 (unlike SSSE3 and AVX above). So, +// 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 +#endif +#endif // !defined(SNAPPY_HAVE_BMI2) + +#if SNAPPY_HAVE_BMI2 +// Please do not replace with . or with headers that assume more +// advanced SSE versions without checking with all the OWNERS. +#include +#endif + +#if SNAPPY_HAVE_SSSE3 +#include +#endif +#if SNAPPY_HAVE_NEON +#include +#endif + namespace snappy { namespace internal { +#if (SNAPPY_HAVE_SSSE3 || SNAPPY_HAVE_NEON) +#define SNAPPY_HAVE_VECTOR_BYTE_SHUFFLE 1 +#endif #if SNAPPY_HAVE_VECTOR_BYTE_SHUFFLE #if SNAPPY_HAVE_SSSE3 using V128 = __m128i; -#else +#elif SNAPPY_HAVE_NEON using V128 = uint8x16_t; #endif @@ -72,7 +103,7 @@ inline V128 V128_Shuffle(V128 input, V128 shuffle_mask) { inline V128 V128_DupChar(char c) { return _mm_set1_epi8(c); } -#else +#elif SNAPPY_HAVE_NEON inline V128 V128_Load(const V128* src) { return vld1q_u8(reinterpret_cast(src)); } diff --git a/snappy.cc b/snappy.cc index 3f446c6..3b0de12 100644 --- a/snappy.cc +++ b/snappy.cc @@ -30,27 +30,6 @@ #include "snappy-sinksource.h" #include "snappy.h" -#if !defined(SNAPPY_HAVE_BMI2) -// __BMI2__ is defined by GCC and Clang. Visual Studio doesn't target BMI2 -// specifically, but it does define __AVX2__ when AVX2 support is available. -// Fortunately, AVX2 was introduced in Haswell, just like BMI2. -// -// BMI2 is not defined as a subset of AVX2 (unlike SSSE3 and AVX above). So, -// 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 -#endif -#endif // !defined(SNAPPY_HAVE_BMI2) - -#if SNAPPY_HAVE_BMI2 -// Please do not replace with . or with headers that assume more -// advanced SSE versions without checking with all the OWNERS. -#include -#endif - #include #include #include -- cgit v1.2.1 From 734b32bfe3d85675652964d09b59eff33a00f557 Mon Sep 17 00:00:00 2001 From: Jun He Date: Fri, 9 Jul 2021 16:59:45 +0800 Subject: Add config and header file for NEON support Signed-off-by: Jun He Change-Id: I3fade568ff92b4303387705f843d0051d5e88349 --- CMakeLists.txt | 9 +++++++++ cmake/config.h.in | 3 +++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 672561e..6eef485 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,15 @@ int main() { return _bzhi_u32(0, 1); }" SNAPPY_HAVE_BMI2) +check_cxx_source_compiles(" +#include +int main() { + uint8_t val = 3, dup[8]; + uint8x16_t v = vld1q_dup_u8(&val); + vst1q_u8(dup, v); + return 0; +}" SNAPPY_HAVE_NEON) + include(CheckSymbolExists) check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP) check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF) diff --git a/cmake/config.h.in b/cmake/config.h.in index 872bd3c..568f69c 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -49,6 +49,9 @@ /* Define to 1 if you target processors with BMI2+ and have . */ #cmakedefine01 SNAPPY_HAVE_BMI2 +/* Define to 1 if you target processors with NEON and have . */ +#cmakedefine01 SNAPPY_HAVE_NEON + /* Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ #cmakedefine SNAPPY_IS_BIG_ENDIAN 1 -- cgit v1.2.1