]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add support for std3_longest_match with MSVC
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 3 Nov 2015 12:49:58 +0000 (13:49 +0100)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 3 Nov 2015 12:51:35 +0000 (13:51 +0100)
Based on patch by Mat Berchtold.

match.c

diff --git a/match.c b/match.c
index 62672730164e6d033de98b535ba5217af7112e11..f6e2cba6edd52663882f6a74777b1a8b91d1ccd6 100644 (file)
--- a/match.c
+++ b/match.c
@@ -17,6 +17,8 @@
 #  if defined(__GNUC__) && defined(HAVE_BUILTIN_CTZL) && ((__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
         || defined(__LITTLE_ENDIAN__))
 #    define std3_longest_match
+#  elif(defined(_MSC_VER) && defined(_WIN32))
+#    define std3_longest_match
 #  else
 #    define std2_longest_match
 #  endif
@@ -267,6 +269,19 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) {
 
 #ifdef std3_longest_match
 
+#ifdef _MSC_VER
+#include <intrin.h>
+/* This is not a general purpose replacement for __builtin_ctzl. The function expects that value is != 0
+ * Because of that assumption trailing_zero is not initialized and the return value of _BitScanForward is not checked
+ */
+static __forceinline unsigned long __builtin_ctzl(unsigned long value)
+{
+       unsigned long trailing_zero;
+       _BitScanForward(&trailing_zero, value);
+       return trailing_zero;
+}
+#endif
+
 /* longest_match() with minor change to improve performance (in terms of
  * execution time).
  *