From: Hans Kristian Rosbach Date: Tue, 3 Nov 2015 12:49:58 +0000 (+0100) Subject: Add support for std3_longest_match with MSVC X-Git-Tag: 1.9.9-b1~793^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7549ab9c14157cf02dc17b6c61da98408573b7c5;p=thirdparty%2Fzlib-ng.git Add support for std3_longest_match with MSVC Based on patch by Mat Berchtold. --- diff --git a/match.c b/match.c index 626727301..f6e2cba6e 100644 --- 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 +/* 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). *