Speed up LZSA1 compression with forward arrivals

This commit is contained in:
Emmanuel Marty 2019-09-19 12:57:39 +02:00 committed by GitHub
parent c052a188f2
commit 1495b27f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,23 +214,22 @@ static void lzsa_optimize_arrivals_v1(lzsa_compressor *pCompressor, const int nS
for (j = 0; j < NMATCHES_PER_OFFSET && arrival[(i << MATCHES_PER_OFFSET_SHIFT) + j].from_slot; j++) { for (j = 0; j < NMATCHES_PER_OFFSET && arrival[(i << MATCHES_PER_OFFSET_SHIFT) + j].from_slot; j++) {
int nPrevCost = arrival[(i << MATCHES_PER_OFFSET_SHIFT) + j].cost; int nPrevCost = arrival[(i << MATCHES_PER_OFFSET_SHIFT) + j].cost;
int nCodingChoiceCost = nPrevCost + 8 /* token */ /* the actual cost of the literals themselves accumulates up the chain */ + nMatchOffsetCost + nMatchLenCost; int nCodingChoiceCost = nPrevCost + 8 /* token */ /* the actual cost of the literals themselves accumulates up the chain */ + nMatchOffsetCost + nMatchLenCost;
for (n = 0; n < 3 /* we only need the literals + short match cost + long match cost cases */; n++) {
lzsa_arrival *pDestArrival = &arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n];
if (pDestArrival->from_slot == 0 ||
nCodingChoiceCost <= pDestArrival->cost) {
int exists = 0; int exists = 0;
for (int l = n; l < NMATCHES_PER_OFFSET && arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + l].from_slot && for (n = 0;
arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + l].cost == nCodingChoiceCost; l++) { n < 3 && arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n].from_slot && arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n].cost <= nCodingChoiceCost;
if (lzsa_get_offset_cost_v1(arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + l].rep_offset) == lzsa_get_offset_cost_v1(pMatch[m].offset)) { n++) {
if (lzsa_get_offset_cost_v1(arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n].rep_offset) == lzsa_get_offset_cost_v1(pMatch[m].offset)) {
exists = 1; exists = 1;
break; break;
} }
} }
if (!exists) { for (n = 0; !exists && n < 3 /* we only need the literals + short match cost + long match cost cases */; n++) {
lzsa_arrival *pDestArrival = &arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n];
if (pDestArrival->from_slot == 0 ||
nCodingChoiceCost <= pDestArrival->cost) {
memmove(&arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n + 1], memmove(&arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n + 1],
&arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n], &arrival[((i + k) << MATCHES_PER_OFFSET_SHIFT) + n],
sizeof(lzsa_arrival) * (NMATCHES_PER_OFFSET - n - 1)); sizeof(lzsa_arrival) * (NMATCHES_PER_OFFSET - n - 1));
@ -242,7 +241,6 @@ static void lzsa_optimize_arrivals_v1(lzsa_compressor *pCompressor, const int nS
pDestArrival->match_len = k; pDestArrival->match_len = k;
pDestArrival->num_literals = 0; pDestArrival->num_literals = 0;
pDestArrival->rep_offset = pMatch[m].offset; pDestArrival->rep_offset = pMatch[m].offset;
}
break; break;
} }
} }
@ -255,13 +253,6 @@ static void lzsa_optimize_arrivals_v1(lzsa_compressor *pCompressor, const int nS
pCompressor->match[i << MATCHES_PER_OFFSET_SHIFT].length = 0; pCompressor->match[i << MATCHES_PER_OFFSET_SHIFT].length = 0;
pCompressor->match[i << MATCHES_PER_OFFSET_SHIFT].offset = 0; pCompressor->match[i << MATCHES_PER_OFFSET_SHIFT].offset = 0;
int nEndCost = end_arrival->cost;
int *backward_cost = (int*)pCompressor->pos_data; /* Reuse */
for (i = nStartOffset; i != nEndOffset; i++) {
backward_cost[i] = nEndCost - arrival[(i << MATCHES_PER_OFFSET_SHIFT) + 0].cost;
}
while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0) { while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0) {
pCompressor->match[end_arrival->from_pos << MATCHES_PER_OFFSET_SHIFT].length = end_arrival->match_len; pCompressor->match[end_arrival->from_pos << MATCHES_PER_OFFSET_SHIFT].length = end_arrival->match_len;
pCompressor->match[end_arrival->from_pos << MATCHES_PER_OFFSET_SHIFT].offset = end_arrival->match_offset; pCompressor->match[end_arrival->from_pos << MATCHES_PER_OFFSET_SHIFT].offset = end_arrival->match_offset;