From f8ce7cabc3c0eb416c6f31e31c431e9910bf2f44 Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Sun, 27 Sep 2020 13:02:46 -0400 Subject: [PATCH] Added more debugging --- lib/compress/zstd_opt.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index f938cce8e..8852fcbe5 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -850,7 +850,7 @@ static int ldm_getNextMatch(rawSeqStore_t* ldmSeqStore, /* Adds an LDM if it's long enough */ static void ldm_maybeAddLdm(ZSTD_match_t* matches, U32* nbMatches, U32 matchStartPosInBlock, U32 matchEndPosInBlock, - U32 matchOffset, U32 currPosInBlock) { + U32 matchOffset, U32 currPosInBlock, U32 curr) { /* Check that current block position is not outside of the match */ if (currPosInBlock < matchStartPosInBlock || currPosInBlock >= matchEndPosInBlock) return; @@ -862,10 +862,10 @@ static void ldm_maybeAddLdm(ZSTD_match_t* matches, U32* nbMatches, U32 matchOffsetAdjusted = matchOffset + posDiff; if (matchLengthAdjusted >= matches[*nbMatches-1].len) { - printf("Adding LDM with of: %u, ml: %u\n", matchOffsetAdjusted, matchLengthAdjusted); + printf("Adding LDM with of: %u, ml: %u @ currposinblock: %u, current: %u\n", matchOffsetAdjusted, matchLengthAdjusted, currPosInBlock, curr); /* Add sifting */ matches[*nbMatches].len = matchLengthAdjusted; - matches[*nbMatches].off = matchOffsetAdjusted; + matches[*nbMatches].off = matchOffsetAdjusted + ZSTD_REP_MOVE; (*nbMatches)++; } } @@ -873,13 +873,13 @@ static void ldm_maybeAddLdm(ZSTD_match_t* matches, U32* nbMatches, /* Wrapper function to call ldm functions as needed */ static void ldm_handleLdm(rawSeqStore_t* ldmSeqStore, ZSTD_match_t* matches, U32* nbMatches, U32* matchStartPosInBlock, U32* matchEndPosInBlock, U32* matchOffset, - U32 currPosInBlock, U32 remainingBytes) { + U32 currPosInBlock, U32 remainingBytes, U32 curr) { if (currPosInBlock >= *matchEndPosInBlock) { int noMoreLdms = ldm_getNextMatch(ldmSeqStore, matchStartPosInBlock, matchEndPosInBlock, matchOffset, currPosInBlock, remainingBytes); } - ldm_maybeAddLdm(matches, nbMatches, *matchStartPosInBlock, *matchEndPosInBlock, *matchOffset, currPosInBlock); + ldm_maybeAddLdm(matches, nbMatches, *matchStartPosInBlock, *matchEndPosInBlock, *matchOffset, currPosInBlock, curr); } @@ -947,12 +947,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, assert(optLevel <= 2); ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize, optLevel); ip += (ip==prefixStart); - - if (ms->ldmSeqStore.size != 0) { - ldm_getNextMatch(&ms->ldmSeqStore, &ldmStartPosInBlock, - &ldmEndPosInBlock, &ldmOffset, - (U32)(ip-istart), (U32)(iend - ip)); - } + /* Match Loop */ while (ip < ilimit) { U32 cur, last_pos = 0; @@ -963,9 +958,9 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, U32 nbMatches = ZSTD_BtGetAllMatches(matches, ms, &nextToUpdate3, ip, iend, dictMode, rep, ll0, minMatch); if (ms->ldmSeqStore.size != 0) { ldm_handleLdm(&ms->ldmSeqStore, matches, - &nbMatches, &ldmStartPosInBlock, - &ldmEndPosInBlock, &ldmOffset, - (U32)(ip-istart), (U32)(iend-ip)); + &nbMatches, &ldmStartPosInBlock, + &ldmEndPosInBlock, &ldmOffset, + (U32)(ip-istart), (U32)(iend - ip), (U32)(ip-base)); } if (!nbMatches) { ip++; continue; } @@ -1087,7 +1082,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, ldm_handleLdm(&ms->ldmSeqStore, matches, &nbMatches, &ldmStartPosInBlock, &ldmEndPosInBlock, &ldmOffset, - (U32)(inr-istart), (U32)(iend-inr)); + (U32)(inr-istart), (U32)(iend-inr), (U32)(ip-base)); } if (!nbMatches) { DEBUGLOG(7, "rPos:%u : no match found", cur); -- 2.47.2