From: Luboš Luňák Date: Tue, 23 Nov 2021 18:33:34 +0000 (+0100) Subject: fix: Make AVX2 code work also with MSVC (#963) X-Git-Tag: v4.6~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b86803c799b9ab57dd30bd301eeca8b34026ce2;p=thirdparty%2Fccache.git fix: Make AVX2 code work also with MSVC (#963) --- diff --git a/cmake/GenerateConfigurationFile.cmake b/cmake/GenerateConfigurationFile.cmake index ee6716bea..df909337f 100644 --- a/cmake/GenerateConfigurationFile.cmake +++ b/cmake/GenerateConfigurationFile.cmake @@ -73,7 +73,9 @@ include(CheckCXXSourceCompiles) check_cxx_source_compiles( [=[ #include + #ifndef _MSC_VER // MSVC does not need explicit enabling of AVX2. void func() __attribute__((target("avx2"))); + #endif void func() { _mm256_abs_epi8(_mm256_set1_epi32(42)); } int main() { diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 9e30cd019..d61282fcc 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -120,8 +120,10 @@ check_for_temporal_macros_bmh(string_view str) } #ifdef HAVE_AVX2 +# ifndef _MSC_VER // MSVC does not need explicit enabling of AVX2. int check_for_temporal_macros_avx2(string_view str) __attribute__((target("avx2"))); +# endif // The following algorithm, which uses AVX2 instructions to find __DATE__, // __TIME__ and __TIMESTAMP__, is heavily inspired by @@ -157,7 +159,13 @@ check_for_temporal_macros_avx2(string_view str) // A bit set in mask now indicates a possible location for a temporal macro. while (mask != 0) { // The start position + 1 (as we know the first char is _). +# ifndef _MSC_VER const auto start = pos + __builtin_ctz(mask) + 1; +# else + unsigned long index; + _BitScanForward(&index, mask); + const auto start = pos + index + 1; +# endif // Clear the least significant bit set. mask = mask & (mask - 1);