]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Set the MSVC optimization fix to only cover lzma_crc64_clmul().
authorJia Tan <jiat0218@gmail.com>
Wed, 18 Oct 2023 11:57:10 +0000 (19:57 +0800)
committerJia Tan <jiat0218@gmail.com>
Wed, 18 Oct 2023 15:54:41 +0000 (23:54 +0800)
After testing a 32-bit Release build on MSVC, only lzma_crc64_clmul()
has the bug. crc_simd_body() and lzma_crc32_clmul() do not need the
optimizations disabled.

src/liblzma/check/crc_clmul.c

index 404adb82ddc825389ab7426be80154221af9580e..b90f43e31a856d49a82c05fec12a257c8f6acd0f 100644 (file)
        MASK_H(in, mask, high)
 
 
-// MSVC (VS2015 - VS2022) produces bad 32-bit x86 code from the CLMUL CRC
-// code when optimizations are enabled (release build). According to the bug
-// report, the ebx register is corrupted and the calculated result is wrong.
-// Trying to workaround the problem with "__asm mov ebx, ebx" didn't help.
-// The following pragma works and performance is still good. x86-64 builds
-// aren't affected by this problem.
-//
-// NOTE: Another pragma after lzma_crc64_clmul() restores the optimizations.
-// If the #if condition here is updated, the other one must be updated too.
-#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
-               && defined(_M_IX86)
-#      pragma optimize("g", off)
-#endif
-
-
 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
 __attribute__((__target__("ssse3,sse4.1,pclmul")))
 #endif
@@ -314,6 +299,21 @@ calc_hi(uint64_t poly, uint64_t a)
 
 #ifdef HAVE_CHECK_CRC64
 
+// MSVC (VS2015 - VS2022) produces bad 32-bit x86 code from the CLMUL CRC
+// code when optimizations are enabled (release build). According to the bug
+// report, the ebx register is corrupted and the calculated result is wrong.
+// Trying to workaround the problem with "__asm mov ebx, ebx" didn't help.
+// The following pragma works and performance is still good. x86-64 builds
+// and CRC32 CLMUL aren't affected by this problem. The problem does not
+// happen in crc_simd_body() either (which is shared with CRC32 CLMUL anyway).
+//
+// NOTE: Another pragma after lzma_crc64_clmul() restores the optimizations.
+// If the #if condition here is updated, the other one must be updated too.
+#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
+               && defined(_M_IX86)
+#      pragma optimize("g", off)
+#endif
+
 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
 __attribute__((__target__("ssse3,sse4.1,pclmul")))
 #endif