-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This include _BitScanReverse support which I sent a PR: google/zopfli#102 and some other minor changes.
- Loading branch information
Showing
2 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,15 +33,22 @@ Author: [email protected] (Jyrki Alakuijala) | |
/* __builtin_clz available beginning with GCC 3.4 */ | ||
#elif __GNUC__ * 100 + __GNUC_MINOR__ >= 304 | ||
# define HAS_BUILTIN_CLZ | ||
/* _BitScanReverse available beginning with Visual Studio 2005 */ | ||
#elif _MSC_VER >= 1400 | ||
# include <intrin.h> | ||
# define HAS_BITSCANREVERSE | ||
#endif | ||
|
||
int ZopfliGetDistExtraBits(int dist) { | ||
#ifdef HAS_BUILTIN_CLZ | ||
if (dist < 5) return 0; | ||
#ifdef HAS_BUILTIN_CLZ | ||
return (31 ^ __builtin_clz(dist - 1)) - 1; /* log2(dist - 1) - 1 */ | ||
#elif defined HAS_BITSCANREVERSE | ||
unsigned long l; | ||
_BitScanReverse(&l, dist - 1); | ||
return l - 1; | ||
#else | ||
if (dist < 5) return 0; | ||
else if (dist < 9) return 1; | ||
if (dist < 9) return 1; | ||
else if (dist < 17) return 2; | ||
else if (dist < 33) return 3; | ||
else if (dist < 65) return 4; | ||
|
@@ -65,6 +72,14 @@ int ZopfliGetDistExtraBitsValue(int dist) { | |
int l = 31 ^ __builtin_clz(dist - 1); /* log2(dist - 1) */ | ||
return (dist - (1 + (1 << l))) & ((1 << (l - 1)) - 1); | ||
} | ||
#elif defined HAS_BITSCANREVERSE | ||
if (dist < 5) { | ||
return 0; | ||
} else { | ||
unsigned long l; | ||
_BitScanReverse(&l, dist - 1); | ||
return (dist - (1 + (1 << l))) & ((1 << (l - 1)) - 1); | ||
} | ||
#else | ||
if (dist < 5) return 0; | ||
else if (dist < 9) return (dist - 5) & 1; | ||
|
@@ -92,6 +107,15 @@ int ZopfliGetDistSymbol(int dist) { | |
int r = ((dist - 1) >> (l - 1)) & 1; | ||
return l * 2 + r; | ||
} | ||
#elif defined HAS_BITSCANREVERSE | ||
if (dist < 5) { | ||
return dist - 1; | ||
} else { | ||
unsigned long l; | ||
_BitScanReverse(&l, dist - 1); | ||
int r = ((dist - 1) >> (l - 1)) & 1; | ||
return l * 2 + r; | ||
} | ||
#else | ||
if (dist < 193) { | ||
if (dist < 13) { /* dist 0..13. */ | ||
|