Skip to content

Include immintrin.h When MemCopy64 Uses AVX Intrinsics - #273

Open
Richard-Durkee wants to merge 1 commit into
google:mainfrom
Richard-Durkee:include-immintrin-for-avx-memcopy
Open

Richard-Durkee wants to merge 1 commit into
google:mainfrom
Richard-Durkee:include-immintrin-for-avx-memcopy

Conversation

@Richard-Durkee

Copy link
Copy Markdown

MemCopy64 uses AVX intrinsics (__m256i, _mm256_lddqu_si256, _mm256_storeu_si256) whenever __x86_64__ and __AVX__ are defined, but snappy.cc only includes <immintrin.h> when SNAPPY_HAVE_BMI2 or SNAPPY_HAVE_X86_CRC32 is set. A build with AVX enabled and both of those off doesn't compile:

snappy.cc:1264:3: error: '__m256i' was not declared in this scope
snappy.cc:1265:40: error: '__m256i' does not name a type

This happens, for example, with vcpkg's snappy port, which passes -DSNAPPY_HAVE_BMI2=OFF -DSNAPPY_HAVE_X86_CRC32=OFF (and SNAPPY_HAVE_SSSE3=OFF), on a toolchain or with flags that enable AVX. It reproduces with GCC 15.2 on Ubuntu 26.04:

CXXFLAGS=-mavx2 cmake -S . -B build -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF \
    -DSNAPPY_HAVE_SSSE3=OFF -DSNAPPY_HAVE_X86_CRC32=OFF -DSNAPPY_HAVE_BMI2=OFF
cmake --build build

The fix includes <immintrin.h> under the same condition MemCopy64 uses. With it, snappy builds with no flags, -mavx, -mavx2 and -march=x86-64-v3, both with those three options off and with the defaults.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant