slightly improved lz4opt.h
This commit is contained in:
parent
20183ad7af
commit
fb6c98c856
@ -134,7 +134,7 @@ LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, in
|
|||||||
#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
|
#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
|
||||||
#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
|
#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
|
||||||
|
|
||||||
#define LZ4HC_HASH_LOG (LZ4HC_DICTIONARY_LOGSIZE-2)
|
#define LZ4HC_HASH_LOG 15
|
||||||
#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
|
#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
|
||||||
#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
|
#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
|
||||||
|
|
||||||
|
26
lib/lz4opt.h
26
lib/lz4opt.h
@ -38,7 +38,8 @@
|
|||||||
#define LZ4_LOG_ENCODE(fmt, ...) //printf(fmt, __VA_ARGS__)
|
#define LZ4_LOG_ENCODE(fmt, ...) //printf(fmt, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
#define LZ4_OPT_NUM (1<<12)
|
#define LZ4_OPT_NUM (1<<12)
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -58,7 +59,7 @@ typedef struct
|
|||||||
FORCE_INLINE size_t LZ4HC_GetLiteralsPrice(size_t litlen)
|
FORCE_INLINE size_t LZ4HC_GetLiteralsPrice(size_t litlen)
|
||||||
{
|
{
|
||||||
size_t price = 8*litlen;
|
size_t price = 8*litlen;
|
||||||
if (litlen>=(int)RUN_MASK) { litlen-=RUN_MASK; price+=8*(1+litlen/255); }
|
if (litlen >= (int)RUN_MASK) price+=8*(1+(litlen-RUN_MASK)/255);
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +69,10 @@ FORCE_INLINE size_t LZ4HC_get_price(size_t litlen, size_t mlen)
|
|||||||
size_t price = 16 + 8; /* 16-bit offset + token */
|
size_t price = 16 + 8; /* 16-bit offset + token */
|
||||||
|
|
||||||
price += 8*litlen;
|
price += 8*litlen;
|
||||||
if (litlen >= (int)RUN_MASK) { litlen-=RUN_MASK; price+=8*(1+litlen/255); }
|
if (litlen >= (int)RUN_MASK) price+=8*(1+(litlen-RUN_MASK)/255);
|
||||||
|
|
||||||
mlen -= MINMATCH;
|
mlen -= MINMATCH;
|
||||||
if (mlen >= (int)ML_MASK) { mlen-=ML_MASK; price+=8*(1+mlen/255); }
|
if (mlen >= (int)ML_MASK) price+=8*(1+(mlen-ML_MASK)/255);
|
||||||
|
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
@ -107,7 +108,6 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
|||||||
*HashPos = current;
|
*HashPos = current;
|
||||||
ctx->nextToUpdate++;
|
ctx->nextToUpdate++;
|
||||||
|
|
||||||
// check rest of matches
|
|
||||||
ptr0 = &DELTANEXTMAXD(current*2+1);
|
ptr0 = &DELTANEXTMAXD(current*2+1);
|
||||||
ptr1 = &DELTANEXTMAXD(current*2);
|
ptr1 = &DELTANEXTMAXD(current*2);
|
||||||
delta0 = delta1 = (U16)(current - matchIndex);
|
delta0 = delta1 = (U16)(current - matchIndex);
|
||||||
@ -137,7 +137,6 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
|||||||
if (*(ip+mlt) < *(match+mlt)) {
|
if (*(ip+mlt) < *(match+mlt)) {
|
||||||
*ptr0 = delta0;
|
*ptr0 = delta0;
|
||||||
ptr0 = &DELTANEXTMAXD(matchIndex*2);
|
ptr0 = &DELTANEXTMAXD(matchIndex*2);
|
||||||
/* printf("delta0=%d\n", delta0); */
|
|
||||||
if (*ptr0 == (U16)-1) break;
|
if (*ptr0 == (U16)-1) break;
|
||||||
delta0 = *ptr0;
|
delta0 = *ptr0;
|
||||||
delta1 += delta0;
|
delta1 += delta0;
|
||||||
@ -145,7 +144,6 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
|||||||
} else {
|
} else {
|
||||||
*ptr1 = delta1;
|
*ptr1 = delta1;
|
||||||
ptr1 = &DELTANEXTMAXD(matchIndex*2+1);
|
ptr1 = &DELTANEXTMAXD(matchIndex*2+1);
|
||||||
/* printf("delta1=%d\n", delta1); */
|
|
||||||
if (*ptr1 == (U16)-1) break;
|
if (*ptr1 == (U16)-1) break;
|
||||||
delta1 = *ptr1;
|
delta1 = *ptr1;
|
||||||
delta0 += delta1;
|
delta0 += delta1;
|
||||||
@ -155,7 +153,6 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
|||||||
|
|
||||||
*ptr0 = (U16)-1;
|
*ptr0 = (U16)-1;
|
||||||
*ptr1 = (U16)-1;
|
*ptr1 = (U16)-1;
|
||||||
|
|
||||||
return mnum;
|
return mnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,9 +220,8 @@ static int LZ4HC_compress_optimal (
|
|||||||
LZ4_LOG_PARSER("%d: start Found mlen=%d off=%d best_mlen=%d last_pos=%d\n", (int)(ip-source), matches[i].len, matches[i].off, best_mlen, last_pos);
|
LZ4_LOG_PARSER("%d: start Found mlen=%d off=%d best_mlen=%d last_pos=%d\n", (int)(ip-source), matches[i].len, matches[i].off, best_mlen, last_pos);
|
||||||
while (mlen <= best_mlen) {
|
while (mlen <= best_mlen) {
|
||||||
litlen = 0;
|
litlen = 0;
|
||||||
price = LZ4HC_get_price(llen + litlen, mlen) - 8*llen;
|
price = LZ4HC_get_price(llen + litlen, mlen) - LZ4HC_GetLiteralsPrice(llen);
|
||||||
if (mlen > last_pos || price <= (size_t)opt[mlen].price)
|
SET_PRICE(mlen, mlen, matches[i].off, litlen, price);
|
||||||
SET_PRICE(mlen, mlen, matches[i].off, litlen, price);
|
|
||||||
mlen++;
|
mlen++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,7 +239,7 @@ static int LZ4HC_compress_optimal (
|
|||||||
price = opt[cur - litlen].price + LZ4HC_GetLiteralsPrice(litlen);
|
price = opt[cur - litlen].price + LZ4HC_GetLiteralsPrice(litlen);
|
||||||
LZ4_LOG_PRICE("%d: TRY1 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-source), cur - litlen, opt[cur - litlen].price, price, cur, litlen);
|
LZ4_LOG_PRICE("%d: TRY1 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-source), cur - litlen, opt[cur - litlen].price, price, cur, litlen);
|
||||||
} else {
|
} else {
|
||||||
price = LZ4HC_GetLiteralsPrice(llen + litlen) - 8*llen;
|
price = LZ4HC_GetLiteralsPrice(llen + litlen) - LZ4HC_GetLiteralsPrice(llen);
|
||||||
LZ4_LOG_PRICE("%d: TRY2 price=%d cur=%d litlen=%d llen=%d\n", (int)(inr-source), price, cur, litlen, llen);
|
LZ4_LOG_PRICE("%d: TRY2 price=%d cur=%d litlen=%d llen=%d\n", (int)(inr-source), price, cur, litlen, llen);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -255,7 +251,7 @@ static int LZ4HC_compress_optimal (
|
|||||||
mlen = 1;
|
mlen = 1;
|
||||||
best_mlen = 0;
|
best_mlen = 0;
|
||||||
LZ4_LOG_PARSER("%d: TRY price=%d opt[%d].price=%d\n", (int)(inr-source), price, cur, opt[cur].price);
|
LZ4_LOG_PARSER("%d: TRY price=%d opt[%d].price=%d\n", (int)(inr-source), price, cur, opt[cur].price);
|
||||||
if (cur > last_pos || price < (size_t)opt[cur].price) // || ((price == opt[cur].price) && (opt[cur-1].mlen == 1) && (cur != litlen)))
|
if (cur > last_pos || price < (size_t)opt[cur].price)
|
||||||
SET_PRICE(cur, mlen, best_mlen, litlen, price);
|
SET_PRICE(cur, mlen, best_mlen, litlen, price);
|
||||||
|
|
||||||
if (cur == last_pos) break;
|
if (cur == last_pos) break;
|
||||||
@ -285,14 +281,14 @@ static int LZ4HC_compress_optimal (
|
|||||||
if (cur2 != litlen)
|
if (cur2 != litlen)
|
||||||
price = opt[cur2 - litlen].price + LZ4HC_get_price(litlen, mlen);
|
price = opt[cur2 - litlen].price + LZ4HC_get_price(litlen, mlen);
|
||||||
else
|
else
|
||||||
price = LZ4HC_get_price(llen + litlen, mlen) - 8*llen;
|
price = LZ4HC_get_price(llen + litlen, mlen) - LZ4HC_GetLiteralsPrice(llen);
|
||||||
} else {
|
} else {
|
||||||
litlen = 0;
|
litlen = 0;
|
||||||
price = opt[cur2].price + LZ4HC_get_price(litlen, mlen);
|
price = opt[cur2].price + LZ4HC_get_price(litlen, mlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
LZ4_LOG_PARSER("%d: Found2 mlen=%d best_mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-source), mlen, best_mlen, matches[i].off, price, litlen, cur - litlen, opt[cur - litlen].price);
|
LZ4_LOG_PARSER("%d: Found2 mlen=%d best_mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-source), mlen, best_mlen, matches[i].off, price, litlen, cur - litlen, opt[cur - litlen].price);
|
||||||
if (cur2 + mlen > last_pos || price < (size_t)opt[cur2 + mlen].price) {
|
if (cur2 + mlen > last_pos || price < (size_t)opt[cur2 + mlen].price) { // || (((int)price == opt[cur2 + mlen].price) && (opt[cur2 + mlen-1].mlen == 1))) {
|
||||||
SET_PRICE(cur2 + mlen, mlen, matches[i].off, litlen, price);
|
SET_PRICE(cur2 + mlen, mlen, matches[i].off, litlen, price);
|
||||||
}
|
}
|
||||||
mlen++;
|
mlen++;
|
||||||
|
Loading…
Reference in New Issue
Block a user