faster level 1 at 256 KB

This commit is contained in:
Yann Collet 2016-04-08 02:02:12 +02:00
parent 9e8b09a7bd
commit 0dbf2874ee
3 changed files with 34 additions and 56 deletions

View File

@ -2642,6 +2642,7 @@ size_t ZSTD_compress_usingPreparedCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* prepare
} }
{ size_t const cSize = ZSTD_compressContinue(cctx, dst, dstCapacity, src, srcSize); { size_t const cSize = ZSTD_compressContinue(cctx, dst, dstCapacity, src, srcSize);
if (ZSTD_isError(cSize)) return cSize; if (ZSTD_isError(cSize)) return cSize;
{ size_t const endSize = ZSTD_compressEnd(cctx, (char*)dst+cSize, dstCapacity-cSize); { size_t const endSize = ZSTD_compressEnd(cctx, (char*)dst+cSize, dstCapacity-cSize);
if (ZSTD_isError(endSize)) return endSize; if (ZSTD_isError(endSize)) return endSize;
return cSize + endSize; return cSize + endSize;
@ -2749,7 +2750,7 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
{ /* for srcSize <= 256 KB */ { /* for srcSize <= 256 KB */
/* W, C, H, S, L, T, strat */ /* W, C, H, S, L, T, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 */ { 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 */
{ 18, 14, 15, 1, 6, 4, ZSTD_fast }, /* level 1 */ { 18, 13, 14, 1, 6, 4, ZSTD_fast }, /* level 1 */
{ 18, 14, 16, 1, 5, 4, ZSTD_fast }, /* level 2 */ { 18, 14, 16, 1, 5, 4, ZSTD_fast }, /* level 2 */
{ 18, 14, 17, 1, 5, 4, ZSTD_fast }, /* level 3.*/ { 18, 14, 17, 1, 5, 4, ZSTD_fast }, /* level 3.*/
{ 18, 14, 15, 4, 4, 4, ZSTD_greedy }, /* level 4 */ { 18, 14, 15, 4, 4, 4, ZSTD_greedy }, /* level 4 */

View File

@ -751,23 +751,21 @@ static size_t ZSTD_decompressSequences(
const BYTE* ip = (const BYTE*)seqStart; const BYTE* ip = (const BYTE*)seqStart;
const BYTE* const iend = ip + seqSize; const BYTE* const iend = ip + seqSize;
BYTE* const ostart = (BYTE* const)dst; BYTE* const ostart = (BYTE* const)dst;
BYTE* op = ostart;
BYTE* const oend = ostart + maxDstSize; BYTE* const oend = ostart + maxDstSize;
BYTE* op = ostart;
const BYTE* litPtr = dctx->litPtr; const BYTE* litPtr = dctx->litPtr;
const BYTE* const litLimit_8 = litPtr + dctx->litBufSize - 8; const BYTE* const litLimit_8 = litPtr + dctx->litBufSize - 8;
const BYTE* const litEnd = litPtr + dctx->litSize; const BYTE* const litEnd = litPtr + dctx->litSize;
U32* DTableLL = dctx->LLTable; FSE_DTable* DTableLL = dctx->LLTable;
U32* DTableML = dctx->MLTable; FSE_DTable* DTableML = dctx->MLTable;
U32* DTableOffb = dctx->OffTable; FSE_DTable* DTableOffb = dctx->OffTable;
const BYTE* const base = (const BYTE*) (dctx->base); const BYTE* const base = (const BYTE*) (dctx->base);
const BYTE* const vBase = (const BYTE*) (dctx->vBase); const BYTE* const vBase = (const BYTE*) (dctx->vBase);
const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd); const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd);
int nbSeq; int nbSeq;
/* Build Decoding Tables */ /* Build Decoding Tables */
{ size_t const seqHSize = ZSTD_decodeSeqHeaders(&nbSeq, { size_t const seqHSize = ZSTD_decodeSeqHeaders(&nbSeq, DTableLL, DTableML, DTableOffb, ip, seqSize);
DTableLL, DTableML, DTableOffb,
ip, seqSize);
if (ZSTD_isError(seqHSize)) return seqHSize; if (ZSTD_isError(seqHSize)) return seqHSize;
ip += seqHSize; ip += seqHSize;
} }
@ -779,29 +777,19 @@ static size_t ZSTD_decompressSequences(
memset(&sequence, 0, sizeof(sequence)); memset(&sequence, 0, sizeof(sequence));
sequence.offset = REPCODE_STARTVALUE; sequence.offset = REPCODE_STARTVALUE;
for (U32 i=0; i<ZSTD_REP_INIT; i++) { U32 i; for (i=0; i<ZSTD_REP_INIT; i++) seqState.prevOffset[i] = REPCODE_STARTVALUE; }
seqState.prevOffset[i] = REPCODE_STARTVALUE;
{ size_t const errorCode = BIT_initDStream(&(seqState.DStream), ip, iend-ip); { size_t const errorCode = BIT_initDStream(&(seqState.DStream), ip, iend-ip);
if (ERR_isError(errorCode)) return ERROR(corruption_detected); } if (ERR_isError(errorCode)) return ERROR(corruption_detected); }
FSE_initDState(&(seqState.stateLL), &(seqState.DStream), DTableLL); FSE_initDState(&(seqState.stateLL), &(seqState.DStream), DTableLL);
FSE_initDState(&(seqState.stateOffb), &(seqState.DStream), DTableOffb); FSE_initDState(&(seqState.stateOffb), &(seqState.DStream), DTableOffb);
FSE_initDState(&(seqState.stateML), &(seqState.DStream), DTableML); FSE_initDState(&(seqState.stateML), &(seqState.DStream), DTableML);
for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) { for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq-- ; ) {
size_t oneSeqSize;
nbSeq--;
ZSTD_decodeSequence(&sequence, &seqState); ZSTD_decodeSequence(&sequence, &seqState);
#if 0 /* for debug */ { size_t const oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litLimit_8, base, vBase, dictEnd);
{ U32 pos = (U32)(op-base); if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
// if ((pos > 200802300) && (pos < 200802400)) op += oneSeqSize;
printf("Dpos %6u :%5u literals & match %3u bytes at distance %6u \n", } }
pos, (U32)sequence.litLength, (U32)sequence.matchLength, (U32)sequence.offset);
}
#endif
oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litLimit_8, base, vBase, dictEnd);
if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
op += oneSeqSize;
}
/* check if reached exact end */ /* check if reached exact end */
if (nbSeq) return ERROR(corruption_detected); if (nbSeq) return ERROR(corruption_detected);
@ -839,11 +827,11 @@ static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong); if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong);
/* Decode literals sub-block */ /* Decode literals sub-block */
{ size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize); { size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize);
if (ZSTD_isError(litCSize)) return litCSize; if (ZSTD_isError(litCSize)) return litCSize;
ip += litCSize; ip += litCSize;
srcSize -= litCSize; } srcSize -= litCSize;
}
return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize); return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize);
} }

View File

@ -983,8 +983,7 @@ int main(int argc, char** argv)
if (argc<1) { badusage(exename); return 1; } if (argc<1) { badusage(exename); return 1; }
for(i=1; i<argc; i++) for(i=1; i<argc; i++) {
{
char* argument = argv[i]; char* argument = argv[i];
if(!argument) continue; /* Protection if argument empty */ if(!argument) continue; /* Protection if argument empty */
@ -1016,13 +1015,9 @@ int main(int argc, char** argv)
/* Sample compressibility (when no file provided) */ /* Sample compressibility (when no file provided) */
case 'P': case 'P':
argument++; argument++;
{ { U32 proba32 = 0;
U32 proba32 = 0; while ((argument[0]>= '0') && (argument[0]<= '9'))
while ((argument[0]>= '0') && (argument[0]<= '9')) { proba32 = (proba32*10) + (*argument++ - '0');
proba32 *= 10;
proba32 += argument[0] - '0';
argument++;
}
g_compressibility = (double)proba32 / 100.; g_compressibility = (double)proba32 / 100.;
} }
break; break;
@ -1082,8 +1077,7 @@ int main(int argc, char** argv)
g_params.strategy = (ZSTD_strategy)(*argument++ - '0'); g_params.strategy = (ZSTD_strategy)(*argument++ - '0');
continue; continue;
case 'L': case 'L':
{ { int cLevel = 0;
int cLevel = 0;
argument++; argument++;
while ((*argument>= '0') && (*argument<='9')) while ((*argument>= '0') && (*argument<='9'))
cLevel *= 10, cLevel += *argument++ - '0'; cLevel *= 10, cLevel += *argument++ - '0';
@ -1100,25 +1094,20 @@ int main(int argc, char** argv)
case 'T': case 'T':
argument++; argument++;
g_target = 0; g_target = 0;
while ((*argument >= '0') && (*argument <= '9')) { while ((*argument >= '0') && (*argument <= '9'))
g_target *= 10; g_target = (g_target*10) + (*argument++ - '0');
g_target += *argument - '0';
argument++;
}
break; break;
/* cut input into blocks */ /* cut input into blocks */
case 'B': case 'B':
{ g_blockSize = 0;
g_blockSize = 0; argument++;
argument++; while ((*argument >='0') && (*argument <='9'))
while ((*argument >='0') && (*argument <='9')) g_blockSize = (g_blockSize*10) + (*argument++ - '0');
g_blockSize *= 10, g_blockSize += *argument++ - '0'; if (*argument=='K') g_blockSize<<=10, argument++; /* allows using KB notation */
if (*argument=='K') g_blockSize<<=10, argument++; /* allows using KB notation */ if (*argument=='M') g_blockSize<<=20, argument++;
if (*argument=='M') g_blockSize<<=20, argument++; if (*argument=='B') argument++;
if (*argument=='B') argument++; DISPLAY("using %u KB block size \n", g_blockSize>>10);
DISPLAY("using %u KB block size \n", g_blockSize>>10);
}
break; break;
/* Unknown command */ /* Unknown command */
@ -1126,7 +1115,7 @@ int main(int argc, char** argv)
} }
} }
continue; continue;
} } /* if (argument[0]=='-') */
/* first provided filename is input */ /* first provided filename is input */
if (!input_filename) { input_filename=argument; filenamesStart=i; continue; } if (!input_filename) { input_filename=argument; filenamesStart=i; continue; }