small decompression speed boost for very small data

This commit is contained in:
Yann Collet 2016-09-22 15:57:28 +02:00
parent 47f3697f32
commit 51f4d566c2
2 changed files with 203 additions and 16 deletions

View File

@ -108,7 +108,8 @@ static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
-1,-1,-1,-1 };
static const U32 LL_defaultNormLog = 6;
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -118,11 +119,13 @@ static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
-1,-1,-1,-1,-1 };
static const U32 ML_defaultNormLog = 6;
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
static const S16 OF_defaultNorm[MaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
static const U32 OF_defaultNormLog = 5;
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
/*-*******************************************

View File

@ -482,23 +482,203 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
}
typedef union {
FSE_decode_t realData;
U32 alignedBy4;
} FSE_decode_t4;
static const FSE_decode_t4 LL_defaultDTable[(1<<LL_DEFAULTNORMLOG)+1] = {
{ { LL_DEFAULTNORMLOG, 1, 1 } }, /* header : tableLog, fastMode, fastMode */
{ { 0, 0, 4 } }, /* 0 : base, symbol, bits */
{ { 16, 0, 4 } },
{ { 32, 1, 5 } },
{ { 0, 3, 5 } },
{ { 0, 4, 5 } },
{ { 0, 6, 5 } },
{ { 0, 7, 5 } },
{ { 0, 9, 5 } },
{ { 0, 10, 5 } },
{ { 0, 12, 5 } },
{ { 0, 14, 6 } },
{ { 0, 16, 5 } },
{ { 0, 18, 5 } },
{ { 0, 19, 5 } },
{ { 0, 21, 5 } },
{ { 0, 22, 5 } },
{ { 0, 24, 5 } },
{ { 32, 25, 5 } },
{ { 0, 26, 5 } },
{ { 0, 27, 6 } },
{ { 0, 29, 6 } },
{ { 0, 31, 6 } },
{ { 32, 0, 4 } },
{ { 0, 1, 4 } },
{ { 0, 2, 5 } },
{ { 32, 4, 5 } },
{ { 0, 5, 5 } },
{ { 32, 7, 5 } },
{ { 0, 8, 5 } },
{ { 32, 10, 5 } },
{ { 0, 11, 5 } },
{ { 0, 13, 6 } },
{ { 32, 16, 5 } },
{ { 0, 17, 5 } },
{ { 32, 19, 5 } },
{ { 0, 20, 5 } },
{ { 32, 22, 5 } },
{ { 0, 23, 5 } },
{ { 0, 25, 4 } },
{ { 16, 25, 4 } },
{ { 32, 26, 5 } },
{ { 0, 28, 6 } },
{ { 0, 30, 6 } },
{ { 48, 0, 4 } },
{ { 16, 1, 4 } },
{ { 32, 2, 5 } },
{ { 32, 3, 5 } },
{ { 32, 5, 5 } },
{ { 32, 6, 5 } },
{ { 32, 8, 5 } },
{ { 32, 9, 5 } },
{ { 32, 11, 5 } },
{ { 32, 12, 5 } },
{ { 0, 15, 6 } },
{ { 32, 17, 5 } },
{ { 32, 18, 5 } },
{ { 32, 20, 5 } },
{ { 32, 21, 5 } },
{ { 32, 23, 5 } },
{ { 32, 24, 5 } },
{ { 0, 35, 6 } },
{ { 0, 34, 6 } },
{ { 0, 33, 6 } },
{ { 0, 32, 6 } },
}; /* LL_defaultDTable */
static const FSE_decode_t4 ML_defaultDTable[(1<<ML_DEFAULTNORMLOG)+1] = {
{ { ML_DEFAULTNORMLOG, 1, 1 } }, /* header : tableLog, fastMode, fastMode */
{ { 0, 0, 6 } }, /* 0 : base, symbol, bits */
{ { 0, 1, 4 } },
{ { 32, 2, 5 } },
{ { 0, 3, 5 } },
{ { 0, 5, 5 } },
{ { 0, 6, 5 } },
{ { 0, 8, 5 } },
{ { 0, 10, 6 } },
{ { 0, 13, 6 } },
{ { 0, 16, 6 } },
{ { 0, 19, 6 } },
{ { 0, 22, 6 } },
{ { 0, 25, 6 } },
{ { 0, 28, 6 } },
{ { 0, 31, 6 } },
{ { 0, 33, 6 } },
{ { 0, 35, 6 } },
{ { 0, 37, 6 } },
{ { 0, 39, 6 } },
{ { 0, 41, 6 } },
{ { 0, 43, 6 } },
{ { 0, 45, 6 } },
{ { 16, 1, 4 } },
{ { 0, 2, 4 } },
{ { 32, 3, 5 } },
{ { 0, 4, 5 } },
{ { 32, 6, 5 } },
{ { 0, 7, 5 } },
{ { 0, 9, 6 } },
{ { 0, 12, 6 } },
{ { 0, 15, 6 } },
{ { 0, 18, 6 } },
{ { 0, 21, 6 } },
{ { 0, 24, 6 } },
{ { 0, 27, 6 } },
{ { 0, 30, 6 } },
{ { 0, 32, 6 } },
{ { 0, 34, 6 } },
{ { 0, 36, 6 } },
{ { 0, 38, 6 } },
{ { 0, 40, 6 } },
{ { 0, 42, 6 } },
{ { 0, 44, 6 } },
{ { 32, 1, 4 } },
{ { 48, 1, 4 } },
{ { 16, 2, 4 } },
{ { 32, 4, 5 } },
{ { 32, 5, 5 } },
{ { 32, 7, 5 } },
{ { 32, 8, 5 } },
{ { 0, 11, 6 } },
{ { 0, 14, 6 } },
{ { 0, 17, 6 } },
{ { 0, 20, 6 } },
{ { 0, 23, 6 } },
{ { 0, 26, 6 } },
{ { 0, 29, 6 } },
{ { 0, 52, 6 } },
{ { 0, 51, 6 } },
{ { 0, 50, 6 } },
{ { 0, 49, 6 } },
{ { 0, 48, 6 } },
{ { 0, 47, 6 } },
{ { 0, 46, 6 } },
}; /* ML_defaultDTable */
static const FSE_decode_t4 OF_defaultDTable[(1<<OF_DEFAULTNORMLOG)+1] = {
{ { OF_DEFAULTNORMLOG, 1, 1 } }, /* header : tableLog, fastMode, fastMode */
{ { 0, 0, 5 } }, /* 0 : base, symbol, bits */
{ { 0, 6, 4 } },
{ { 0, 9, 5 } },
{ { 0, 15, 5 } },
{ { 0, 21, 5 } },
{ { 0, 3, 5 } },
{ { 0, 7, 4 } },
{ { 0, 12, 5 } },
{ { 0, 18, 5 } },
{ { 0, 23, 5 } },
{ { 0, 5, 5 } },
{ { 0, 8, 4 } },
{ { 0, 14, 5 } },
{ { 0, 20, 5 } },
{ { 0, 2, 5 } },
{ { 16, 7, 4 } },
{ { 0, 11, 5 } },
{ { 0, 17, 5 } },
{ { 0, 22, 5 } },
{ { 0, 4, 5 } },
{ { 16, 8, 4 } },
{ { 0, 13, 5 } },
{ { 0, 19, 5 } },
{ { 0, 1, 5 } },
{ { 16, 6, 4 } },
{ { 0, 10, 5 } },
{ { 0, 16, 5 } },
{ { 0, 28, 5 } },
{ { 0, 27, 5 } },
{ { 0, 26, 5 } },
{ { 0, 25, 5 } },
{ { 0, 24, 5 } },
}; /* OF_defaultDTable */
/*! ZSTD_buildSeqTable() :
@return : nb bytes read from src,
or an error code if it fails, testable with ZSTD_isError()
*/
static size_t ZSTD_buildSeqTable(FSE_DTable* DTable, symbolEncodingType_e type, U32 max, U32 maxLog,
static size_t ZSTD_buildSeqTable(FSE_DTable* DTableSpace, const FSE_DTable** DTablePtr,
symbolEncodingType_e type, U32 max, U32 maxLog,
const void* src, size_t srcSize,
const S16* defaultNorm, U32 defaultLog, U32 flagRepeatTable)
const FSE_decode_t4* defaultTable, U32 flagRepeatTable)
{
const void* const tmpPtr = defaultTable; /* bypass strict aliasing */
switch(type)
{
case set_rle :
if (!srcSize) return ERROR(srcSize_wrong);
if ( (*(const BYTE*)src) > max) return ERROR(corruption_detected);
FSE_buildDTable_rle(DTable, *(const BYTE*)src); /* if *src > max, data is corrupted */
FSE_buildDTable_rle(DTableSpace, *(const BYTE*)src);
*DTablePtr = DTableSpace;
return 1;
case set_basic :
FSE_buildDTable(DTable, defaultNorm, max, defaultLog);
*DTablePtr = (const FSE_DTable*)tmpPtr;
return 0;
case set_repeat:
if (!flagRepeatTable) return ERROR(corruption_detected);
@ -510,12 +690,12 @@ static size_t ZSTD_buildSeqTable(FSE_DTable* DTable, symbolEncodingType_e type,
size_t const headerSize = FSE_readNCount(norm, &max, &tableLog, src, srcSize);
if (FSE_isError(headerSize)) return ERROR(corruption_detected);
if (tableLog > maxLog) return ERROR(corruption_detected);
FSE_buildDTable(DTable, norm, max, tableLog);
FSE_buildDTable(DTableSpace, norm, max, tableLog);
*DTablePtr = DTableSpace;
return headerSize;
} }
}
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
const void* src, size_t srcSize)
{
@ -546,21 +726,25 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
ip++;
/* Build DTables */
{ size_t const llhSize = ZSTD_buildSeqTable(dctx->LLTable, LLtype, MaxLL, LLFSELog, ip, iend-ip, LL_defaultNorm, LL_defaultNormLog, dctx->fseEntropy);
{ size_t const llhSize = ZSTD_buildSeqTable(dctx->LLTable, &dctx->LLTptr,
LLtype, MaxLL, LLFSELog,
ip, iend-ip, LL_defaultDTable, dctx->fseEntropy);
if (ZSTD_isError(llhSize)) return ERROR(corruption_detected);
if (LLtype != set_repeat) dctx->LLTptr = dctx->LLTable;
ip += llhSize;
}
{ size_t const ofhSize = ZSTD_buildSeqTable(dctx->OFTable, OFtype, MaxOff, OffFSELog, ip, iend-ip, OF_defaultNorm, OF_defaultNormLog, dctx->fseEntropy);
{ size_t const ofhSize = ZSTD_buildSeqTable(dctx->OFTable, &dctx->OFTptr,
OFtype, MaxOff, OffFSELog,
ip, iend-ip, OF_defaultDTable, dctx->fseEntropy);
if (ZSTD_isError(ofhSize)) return ERROR(corruption_detected);
if (OFtype != set_repeat) dctx->OFTptr = dctx->OFTable;
ip += ofhSize;
}
{ size_t const mlhSize = ZSTD_buildSeqTable(dctx->MLTable, MLtype, MaxML, MLFSELog, ip, iend-ip, ML_defaultNorm, ML_defaultNormLog, dctx->fseEntropy);
{ size_t const mlhSize = ZSTD_buildSeqTable(dctx->MLTable, &dctx->MLTptr,
MLtype, MaxML, MLFSELog,
ip, iend-ip, ML_defaultDTable, dctx->fseEntropy);
if (ZSTD_isError(mlhSize)) return ERROR(corruption_detected);
if (MLtype != set_repeat) dctx->MLTptr = dctx->MLTable;
ip += mlhSize;
} }
}
}
return ip-istart;
}