diff --git a/bench.c b/bench.c index 1164373..bd5dc1c 100644 --- a/bench.c +++ b/bench.c @@ -290,6 +290,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles) { // Compression DISPLAY("%1i-%-14.14s : %9i ->\r", loopNb, infilename, (int)benchedsize); + { size_t i; for (i=0; i>3); + #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) + return (__builtin_ctzll(val) >> 3); + #else + static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; + return DeBruijnBytePos[((U64)((val & -val) * 0x0218A392CDABBD3F)) >> 58]; + #endif +} + +inline static int LZ4_NbCommonBytes_BigEndian (register U64 val) +{ + #if defined(_MSC_VER) && !defined(_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanReverse64( &r, val ); + return (int)(r>>3); + #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) + return (__builtin_clzll(val) >> 3); + #else + int r; + if (!(val>>32)) { r=4; } else { r=0; val>>=32; } + if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } + r += (!val); + return r; + #endif +} + +#else + inline static int LZ4_NbCommonBytes_LittleEndian (register U32 val) { #if defined(_MSC_VER) && !defined(_FORCE_SW_BITCOUNT) unsigned long r = 0; _BitScanForward( &r, val ); return (int)(r>>3); - #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) + #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) return (__builtin_ctz(val) >> 3); #else static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; @@ -196,7 +239,7 @@ inline static int LZ4_NbCommonBytes_BigEndian (register U32 val) unsigned long r = 0; _BitScanReverse( &r, val ); return (int)(r>>3); - #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) + #elif defined(__GNUC__) && !defined(_FORCE_SW_BITCOUNT) return (__builtin_clz(val) >> 3); #else int r; @@ -206,6 +249,8 @@ inline static int LZ4_NbCommonBytes_BigEndian (register U32 val) #endif } +#endif + //****************************** // Public Compression functions @@ -289,7 +334,6 @@ int LZ4_compressCtx(void** ctx, // Copy Literals LZ4_BLINDCOPY(anchor, op, length); - _next_match: // Encode Offset LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref); @@ -297,13 +341,14 @@ _next_match: // Start Counting ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified anchor = ip; - while (ipoend-COPYLENGTH) { if (cpy > oend) goto _output_error; @@ -646,23 +691,23 @@ int LZ4_uncompress_unknownOutputSize( if ((length=(token&ML_MASK)) == ML_MASK) { for (;(len=*ip++)==255;length+=255){} length += len; } // copy repeated sequence - if (op-refoend-COPYLENGTH) { if (cpy > oend) goto _output_error;