From 5ed7728b8cd5a3fd77f2154dde5e1707f5cb3a02 Mon Sep 17 00:00:00 2001 From: JayXon Date: Fri, 8 Apr 2016 23:23:27 -0700 Subject: [PATCH] Utilize _BitScanReverse in Visual Studio _BitScanReverse is documented here: https://msdn.microsoft.com/en-us/library/fbxyd7zd.aspx This improves speed of a VS2015 x64 build by more than 10%. --- src/zopfli/symbols.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/zopfli/symbols.h b/src/zopfli/symbols.h index b49df06c..25dba314 100644 --- a/src/zopfli/symbols.h +++ b/src/zopfli/symbols.h @@ -32,6 +32,15 @@ Utilities for using the lz77 symbols of the deflate spec. /* __builtin_clz available beginning with GCC 3.4 */ #elif __GNUC__ * 100 + __GNUC_MINOR__ >= 304 # define ZOPFLI_HAS_BUILTIN_CLZ +/* _BitScanReverse available beginning with Visual Studio 2005 */ +#elif _MSC_VER >= 1400 +# include +# define ZOPFLI_HAS_BUILTIN_CLZ +static int __inline __builtin_clz(unsigned int x) { + unsigned long r; + _BitScanReverse(&r, x); + return 31 ^ r; +} #endif /* Gets the amount of extra bits for the given dist, cfr. the DEFLATE spec. */