Optimize repcode predicate, hardcode hasStep == 0 scenario, cosmetic fixes
This commit is contained in:
+43
-32
@@ -587,7 +587,7 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|||||||
U32* const hashTable = ms->hashTable;
|
U32* const hashTable = ms->hashTable;
|
||||||
U32 const hlog = cParams->hashLog;
|
U32 const hlog = cParams->hashLog;
|
||||||
/* support stepSize of 0 */
|
/* support stepSize of 0 */
|
||||||
U32 const stepSize = cParams->targetLength + !(cParams->targetLength) + 1;
|
size_t const stepSize = hasStep ? (cParams->targetLength + !(cParams->targetLength) + 1) : 2;
|
||||||
const BYTE* const base = ms->window.base;
|
const BYTE* const base = ms->window.base;
|
||||||
const BYTE* const dictBase = ms->window.dictBase;
|
const BYTE* const dictBase = ms->window.dictBase;
|
||||||
const BYTE* const istart = (const BYTE*)src;
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
@@ -625,14 +625,18 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|||||||
const BYTE* nextStep;
|
const BYTE* nextStep;
|
||||||
const size_t kStepIncr = (1 << (kSearchStrength - 1));
|
const size_t kStepIncr = (1 << (kSearchStrength - 1));
|
||||||
|
|
||||||
(void)hasStep; /* not currently specialized on whether it's accelerated */
|
|
||||||
|
|
||||||
DEBUGLOG(5, "ZSTD_compressBlock_fast_extDict_generic (offset_1=%u)", offset_1);
|
DEBUGLOG(5, "ZSTD_compressBlock_fast_extDict_generic (offset_1=%u)", offset_1);
|
||||||
|
|
||||||
/* switch to "regular" variant if extDict is invalidated due to maxDistance */
|
/* switch to "regular" variant if extDict is invalidated due to maxDistance */
|
||||||
if (prefixStartIndex == dictStartIndex)
|
if (prefixStartIndex == dictStartIndex)
|
||||||
return ZSTD_compressBlock_fast(ms, seqStore, rep, src, srcSize);
|
return ZSTD_compressBlock_fast(ms, seqStore, rep, src, srcSize);
|
||||||
|
|
||||||
|
{ U32 const curr = (U32)(ip0 - base);
|
||||||
|
U32 const maxRep = curr - dictStartIndex;
|
||||||
|
if (offset_2 >= maxRep) offset_2 = 0;
|
||||||
|
if (offset_1 >= maxRep) offset_1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* start each op */
|
/* start each op */
|
||||||
_start: /* Requires: ip0 */
|
_start: /* Requires: ip0 */
|
||||||
|
|
||||||
@@ -655,16 +659,13 @@ _start: /* Requires: ip0 */
|
|||||||
idxBase = idx < prefixStartIndex ? dictBase : base;
|
idxBase = idx < prefixStartIndex ? dictBase : base;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
U32 mval; /* src or dict value at match idx */
|
{ /* load repcode match for ip[2] */
|
||||||
|
U32 const current2 = (U32)(ip2 - base);
|
||||||
/* load repcode match for ip[2] */
|
U32 const repIndex = current2 - offset_1;
|
||||||
const U32 current2 = (U32)(ip2 - base);
|
|
||||||
const U32 repIndex = current2 - offset_1;
|
|
||||||
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
||||||
U32 rval;
|
U32 rval;
|
||||||
assert(offset_1 > 0);
|
if ( ((U32)(prefixStartIndex - repIndex) >= 4) /* intentional underflow */
|
||||||
if ( ( ((U32)(prefixStartIndex - repIndex) >= 4) /* intentional underflow */
|
& (offset_1 > 0) ) {
|
||||||
& (offset_1 < current2 - dictStartIndex) ) ) {
|
|
||||||
rval = MEM_read32(repBase + repIndex);
|
rval = MEM_read32(repBase + repIndex);
|
||||||
} else {
|
} else {
|
||||||
rval = MEM_read32(ip2) ^ 1; /* guaranteed to not match. */
|
rval = MEM_read32(ip2) ^ 1; /* guaranteed to not match. */
|
||||||
@@ -686,20 +687,16 @@ _start: /* Requires: ip0 */
|
|||||||
offcode = REPCODE1_TO_OFFBASE;
|
offcode = REPCODE1_TO_OFFBASE;
|
||||||
mLength += 4;
|
mLength += 4;
|
||||||
goto _match;
|
goto _match;
|
||||||
}
|
} }
|
||||||
|
|
||||||
/* load match for ip[0] */
|
{ /* load match for ip[0] */
|
||||||
if (idx >= dictStartIndex) {
|
U32 const mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
||||||
mval = MEM_read32(idxBase + idx);
|
|
||||||
} else {
|
|
||||||
mval = MEM_read32(ip0) ^ 1; /* guaranteed to not match. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check match at ip[0] */
|
/* check match at ip[0] */
|
||||||
if (MEM_read32(ip0) == mval) {
|
if (MEM_read32(ip0) == mval) {
|
||||||
/* found a match! */
|
/* found a match! */
|
||||||
goto _offset;
|
goto _offset;
|
||||||
}
|
} }
|
||||||
|
|
||||||
/* lookup ip[1] */
|
/* lookup ip[1] */
|
||||||
idx = hashTable[hash1];
|
idx = hashTable[hash1];
|
||||||
@@ -718,18 +715,14 @@ _start: /* Requires: ip0 */
|
|||||||
current0 = (U32)(ip0 - base);
|
current0 = (U32)(ip0 - base);
|
||||||
hashTable[hash0] = current0;
|
hashTable[hash0] = current0;
|
||||||
|
|
||||||
/* load match for ip[0] */
|
{ /* load match for ip[0] */
|
||||||
if (idx >= dictStartIndex) {
|
U32 const mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
||||||
mval = MEM_read32(idxBase + idx);
|
|
||||||
} else {
|
|
||||||
mval = MEM_read32(ip0) ^ 1; /* guaranteed to not match. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check match at ip[0] */
|
/* check match at ip[0] */
|
||||||
if (MEM_read32(ip0) == mval) {
|
if (MEM_read32(ip0) == mval) {
|
||||||
/* found a match! */
|
/* found a match! */
|
||||||
goto _offset;
|
goto _offset;
|
||||||
}
|
} }
|
||||||
|
|
||||||
/* lookup ip[1] */
|
/* lookup ip[1] */
|
||||||
idx = hashTable[hash1];
|
idx = hashTable[hash1];
|
||||||
@@ -760,8 +753,8 @@ _cleanup:
|
|||||||
* them. So let's not. */
|
* them. So let's not. */
|
||||||
|
|
||||||
/* save reps for next block */
|
/* save reps for next block */
|
||||||
rep[0] = offset_1;
|
rep[0] = offset_1 ? offset_1 : rep[0];
|
||||||
rep[1] = offset_2;
|
rep[1] = offset_2 ? offset_2 : rep[1];
|
||||||
|
|
||||||
/* Return the last literals size */
|
/* Return the last literals size */
|
||||||
return (size_t)(iend - anchor);
|
return (size_t)(iend - anchor);
|
||||||
@@ -808,11 +801,10 @@ _match: /* Requires: ip0, match0, offcode, matchEnd */
|
|||||||
hashTable[ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2; /* here because current+2 could be > iend-8 */
|
hashTable[ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2; /* here because current+2 could be > iend-8 */
|
||||||
hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
|
hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
|
||||||
|
|
||||||
assert(offset_2 > 0);
|
|
||||||
while (ip0 <= ilimit) {
|
while (ip0 <= ilimit) {
|
||||||
U32 const repIndex2 = (U32)(ip0-base) - offset_2;
|
U32 const repIndex2 = (U32)(ip0-base) - offset_2;
|
||||||
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
||||||
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 <= (U32)(ip0-base) - dictStartIndex)) /* intentional overflow */
|
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 > 0)) /* intentional underflow */
|
||||||
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
|
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
|
||||||
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
||||||
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
||||||
@@ -829,6 +821,11 @@ _match: /* Requires: ip0, match0, offcode, matchEnd */
|
|||||||
goto _start;
|
goto _start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZSTD_GEN_FAST_FN(extDict, 4, 1)
|
||||||
|
ZSTD_GEN_FAST_FN(extDict, 5, 1)
|
||||||
|
ZSTD_GEN_FAST_FN(extDict, 6, 1)
|
||||||
|
ZSTD_GEN_FAST_FN(extDict, 7, 1)
|
||||||
|
|
||||||
ZSTD_GEN_FAST_FN(extDict, 4, 0)
|
ZSTD_GEN_FAST_FN(extDict, 4, 0)
|
||||||
ZSTD_GEN_FAST_FN(extDict, 5, 0)
|
ZSTD_GEN_FAST_FN(extDict, 5, 0)
|
||||||
ZSTD_GEN_FAST_FN(extDict, 6, 0)
|
ZSTD_GEN_FAST_FN(extDict, 6, 0)
|
||||||
@@ -839,8 +836,21 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|||||||
void const* src, size_t srcSize)
|
void const* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
U32 const mls = ms->cParams.minMatch;
|
U32 const mls = ms->cParams.minMatch;
|
||||||
switch(mls)
|
assert(ms->dictMatchState == NULL);
|
||||||
{
|
if (ms->cParams.targetLength > 1) {
|
||||||
|
switch (mls) {
|
||||||
|
default: /* includes case 3 */
|
||||||
|
case 4 :
|
||||||
|
return ZSTD_compressBlock_fast_extDict_4_1(ms, seqStore, rep, src, srcSize);
|
||||||
|
case 5 :
|
||||||
|
return ZSTD_compressBlock_fast_extDict_5_1(ms, seqStore, rep, src, srcSize);
|
||||||
|
case 6 :
|
||||||
|
return ZSTD_compressBlock_fast_extDict_6_1(ms, seqStore, rep, src, srcSize);
|
||||||
|
case 7 :
|
||||||
|
return ZSTD_compressBlock_fast_extDict_7_1(ms, seqStore, rep, src, srcSize);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (mls) {
|
||||||
default: /* includes case 3 */
|
default: /* includes case 3 */
|
||||||
case 4 :
|
case 4 :
|
||||||
return ZSTD_compressBlock_fast_extDict_4_0(ms, seqStore, rep, src, srcSize);
|
return ZSTD_compressBlock_fast_extDict_4_0(ms, seqStore, rep, src, srcSize);
|
||||||
@@ -852,3 +862,4 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|||||||
return ZSTD_compressBlock_fast_extDict_7_0(ms, seqStore, rep, src, srcSize);
|
return ZSTD_compressBlock_fast_extDict_7_0(ms, seqStore, rep, src, srcSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user