]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Updated FSE
authorYann Collet <yann.collet.73@gmail.com>
Wed, 26 Aug 2015 18:22:01 +0000 (19:22 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Wed, 26 Aug 2015 18:22:01 +0000 (19:22 +0100)
lib/fse.c

index 6871a19e3209a700ce70e7655e679c5186bb72c1..9221151ac0b105311f949a9dac7af55f56cb61fa 100644 (file)
--- a/lib/fse.c
+++ b/lib/fse.c
@@ -135,7 +135,7 @@ typedef   signed long long  S64;
  * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
  *            This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
  * Method 2 : direct access. This method is portable but violate C standard.
- *            It can generate buggy code on targets which generate assembly depending on alignment.
+ *            It can generate buggy code on targets generating assembly depending on alignment.
  *            But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
  * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
  * Prefer these methods in priority order (0 > 1 > 2)
@@ -1398,6 +1398,7 @@ size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize
     errorCode = FSE_count (count, &maxSymbolValue, ip, srcSize);
     if (FSE_isError(errorCode)) return errorCode;
     if (errorCode == srcSize) return 1;
+    if (errorCode == 1) return 0;   /* each symbol only present once */
     if (errorCode < (srcSize >> 7)) return 0;   /* Heuristic : not compressible enough */
 
     tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
@@ -1534,7 +1535,7 @@ static size_t FSE_lookBits(FSE_DStream_t* bitD, U32 nbBits)
 
 static size_t FSE_lookBitsFast(FSE_DStream_t* bitD, U32 nbBits)   /* only if nbBits >= 1 !! */
 {
-    return (bitD->bitContainer << bitD->bitsConsumed) >> ((sizeof(bitD->bitContainer)*8)-nbBits);
+    return (bitD->bitContainer << (bitD->bitsConsumed & ((sizeof(bitD->bitContainer)*8)-1))) >> ((sizeof(bitD->bitContainer)*8)-nbBits);
 }
 
 static void FSE_skipBits(FSE_DStream_t* bitD, U32 nbBits)