]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make AVX2 code work also with MSVC (#963)
authorLuboš Luňák <l.lunak@centrum.cz>
Tue, 23 Nov 2021 18:33:34 +0000 (19:33 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Nov 2021 18:33:34 +0000 (19:33 +0100)
cmake/GenerateConfigurationFile.cmake
src/hashutil.cpp

index ee6716bea31caa0b66546fd7dda8aba8364796ba..df909337fb89171d87b21a17fa76beda5981f75c 100644 (file)
@@ -73,7 +73,9 @@ include(CheckCXXSourceCompiles)
 check_cxx_source_compiles(
   [=[
     #include <immintrin.h>
+    #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()
     {
index 9e30cd019ea9e163cd818e493a7ee5357a3b6a3e..d61282fcc7cf84c03381fd646a1d1d6753f98133 100644 (file)
@@ -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);