]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Extend the MSVC 2015 AVX2/AVX512 workaround to MSVC 2017.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Mon, 22 Jun 2026 22:36:55 +0000 (18:36 -0400)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 24 Jun 2026 10:27:07 +0000 (12:27 +0200)
The 32-bit MSVC 2015 debug build randomly crashes without this because
the stack ends up not being 16-byte aligned, and MSVC adds a vmovdqa
instruction.

MSVC 2022 and 2026 align the stack properly before using vmovdqa.

arch/x86/chunkset_avx2.c
arch/x86/chunkset_avx512.c

index 4045a945fae8f85312b183b2852e5cf2954679e4..4b44d31b729851dcc708fd4b918ec663e4dfcd9e 100644 (file)
@@ -41,7 +41,7 @@ static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
 
 static inline void chunkmemset_16(uint8_t *from, chunk_t *chunk) {
     /* See explanation in chunkset_avx512.c */
-#if defined(_MSC_VER) && _MSC_VER <= 1900
+#if defined(_MSC_VER) && _MSC_VER < 1920
     halfchunk_t half = _mm_loadu_si128((__m128i*)from);
     *chunk = _mm256_inserti128_si256(_mm256_castsi128_si256(half), half, 1);
 #else
index e32e0b729ac171970b030eecea7a3ab1a9e17f07..85344c6824d8742121743dbde57b68850b45e76c 100644 (file)
@@ -52,12 +52,13 @@ static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
 }
 
 static inline void chunkmemset_16(uint8_t *from, chunk_t *chunk) {
-    /* Unfortunately there seems to be a compiler bug in Visual Studio 2015 where
+    /* Unfortunately there seems to be a compiler bug in Visual Studio 2015/2017 where
      * the load is dumped to the stack with an aligned move for this memory-register
-     * broadcast. The vbroadcasti128 instruction is 2 fewer cycles and this dump to
-     * stack doesn't exist if compiled with optimizations. For the sake of working
+     * broadcast, and the stack isn't 16-byte aligned on i386 in debug builds.
+     * The vbroadcasti128 instruction is 2 fewer cycles and this dump to stack
+     * doesn't exist if compiled with optimizations. For the sake of working
      * properly in a debugger, let's take the 2 cycle penalty */
-#if defined(_MSC_VER) && _MSC_VER <= 1900
+#if defined(_MSC_VER) && _MSC_VER < 1920
     halfchunk_t half = _mm_loadu_si128((__m128i*)from);
     *chunk = _mm256_inserti128_si256(_mm256_castsi128_si256(half), half, 1);
 #else