minor refactor zstd_fast
make hot variables more local
This commit is contained in:
@@ -560,7 +560,9 @@ MEM_STATIC int ZSTD_cParam_withinBounds(ZSTD_cParameter cParam, int value)
|
||||
/* ZSTD_selectAddr:
|
||||
* @return a >= b ? trueAddr : falseAddr,
|
||||
* tries to force branchless codegen. */
|
||||
MEM_STATIC const BYTE* ZSTD_selectAddr(U32 a, U32 b, const BYTE* trueAddr, const BYTE* falseAddr) {
|
||||
MEM_STATIC const BYTE*
|
||||
ZSTD_selectAddr(U32 a, U32 b, const BYTE* trueAddr, const BYTE* falseAddr)
|
||||
{
|
||||
#if defined(__GNUC__) && defined(__x86_64__)
|
||||
__asm__ (
|
||||
"cmp %1, %2\n"
|
||||
|
||||
@@ -166,7 +166,6 @@ size_t ZSTD_compressBlock_fast_noDict_generic(
|
||||
* we load from here instead of from tables, if the index is invalid.
|
||||
* Used to avoid unpredictable branches. */
|
||||
const BYTE dummy[] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0xe2,0xb4};
|
||||
const BYTE *mvalAddr;
|
||||
|
||||
const BYTE* anchor = istart;
|
||||
const BYTE* ip0 = istart;
|
||||
@@ -182,7 +181,6 @@ size_t ZSTD_compressBlock_fast_noDict_generic(
|
||||
size_t hash0; /* hash for ip0 */
|
||||
size_t hash1; /* hash for ip1 */
|
||||
U32 idx; /* match idx for ip0 */
|
||||
U32 mval; /* src value at match idx */
|
||||
|
||||
U32 offcode;
|
||||
const BYTE* match0;
|
||||
@@ -255,23 +253,22 @@ _start: /* Requires: ip0 */
|
||||
* However expression below complies into conditional move. Since
|
||||
* match is unlikely and we only *branch* on idxl0 > prefixLowestIndex
|
||||
* if there is a match, all branches become predictable. */
|
||||
mvalAddr = base + idx;
|
||||
mvalAddr = ZSTD_selectAddr(idx, prefixStartIndex, mvalAddr, &dummy[0]);
|
||||
|
||||
{ const BYTE* mvalAddr = ZSTD_selectAddr(idx, prefixStartIndex, base + idx, &dummy[0]);
|
||||
/* load match for ip[0] */
|
||||
mval = MEM_read32(mvalAddr);
|
||||
U32 const mval = MEM_read32(mvalAddr);
|
||||
|
||||
/* check match at ip[0] */
|
||||
if (MEM_read32(ip0) == mval && idx >= prefixStartIndex) {
|
||||
/* found a match! */
|
||||
|
||||
/* First write next hash table entry; we've already calculated it.
|
||||
* This write is known to be safe because the ip1 == ip0 + 1, so
|
||||
* we know we will resume searching after ip1 */
|
||||
/* Write next hash table entry (it's already calculated).
|
||||
* This write is known to be safe because the ip1 == ip0 + 1,
|
||||
* so searching will resume after ip1 */
|
||||
hashTable[hash1] = (U32)(ip1 - base);
|
||||
|
||||
goto _offset;
|
||||
}
|
||||
}
|
||||
|
||||
/* lookup ip[1] */
|
||||
idx = hashTable[hash1];
|
||||
@@ -289,12 +286,9 @@ _start: /* Requires: ip0 */
|
||||
current0 = (U32)(ip0 - base);
|
||||
hashTable[hash0] = current0;
|
||||
|
||||
mvalAddr = base + idx;
|
||||
mvalAddr = ZSTD_selectAddr(idx, prefixStartIndex, mvalAddr, &dummy[0]);
|
||||
|
||||
{ const BYTE* mvalAddr = ZSTD_selectAddr(idx, prefixStartIndex, base + idx, &dummy[0]);
|
||||
/* load match for ip[0] */
|
||||
mval = MEM_read32(mvalAddr);
|
||||
|
||||
U32 const mval = MEM_read32(mvalAddr);
|
||||
|
||||
/* check match at ip[0] */
|
||||
if (MEM_read32(ip0) == mval && idx >= prefixStartIndex) {
|
||||
@@ -316,6 +310,7 @@ _start: /* Requires: ip0 */
|
||||
|
||||
goto _offset;
|
||||
}
|
||||
}
|
||||
|
||||
/* lookup ip[1] */
|
||||
idx = hashTable[hash1];
|
||||
|
||||
Reference in New Issue
Block a user