CMake: Fix illegal instruction on MSVC - #261
Open
khuiqel wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CMakeLists.txtchecksSNAPPY_HAVE_BMI2by compiling a function with_bzhi_u32. On Clang and GCC,SNAPPY_HAVE_BMI2will be 0 if BMI2 is not enabled. On MSVC, the result will always be 1 on x86 regardless of the microarchitecture level. On CPUs without AVX2/BMI2, this will result in an illegal instruction (insnappy::ExtractLowBytes()). Presumably this also occurs withSNAPPY_HAVE_SSSE3andSNAPPY_HAVE_X86_CRC32, as well asSNAPPY_HAVE_NEON_CRC32andSNAPPY_HAVE_NEONon ARM, but I couldn't verify that. Can be reproduced with theBM_UFlatbenchmarks.The BMI2 check was added in 4f0adca, which noted the
__BMI2__preprocessor macro doesn't exist on MSVC. Did not test MSVC+Clang.Solution
It's very much a band-aid, but wrap the instruction checks in
if(NOT MSVC). This solves the illegal instruction issue, but SSSE3/CRC32/BMI2 intrinsics will no longer generate.All 25 test pass with this patch. The following tests fail without this patch (on a CPU without BMI2):
Checking for SSSE3 and SSE4.2 (x86 CRC32) support on MSVC is impossible because MSVC only defines
__AVX__,__AVX2__, and AVX-512 macros with no plan to change. So a proper solution for MSVC would involve addingSNAPPY_HAVE_XXXXoptions like AVX/AVX2 for SSSE3 and SSE4.2, like Highway does.Somewhat related to #254