]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
simplified source
authorYann Collet <yann.collet.73@gmail.com>
Thu, 5 Nov 2015 14:03:12 +0000 (15:03 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 5 Nov 2015 14:03:12 +0000 (15:03 +0100)
lib/zstdhc.c

index efe0c2bf3b13aefe721f722b70404cdfc1216038..31e007765c32cc7de62111166941ad56842015f9 100644 (file)
@@ -493,8 +493,7 @@ FORCE_INLINE size_t ZSTD_HC_insertAndFindBestMatch_selectMLS (
 }
 
 
-#if 1
-
+/* common lazy function, to be inlined */
 FORCE_INLINE
 size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
                                      void* dst, size_t maxDstSize, const void* src, size_t srcSize,
@@ -637,350 +636,6 @@ size_t ZSTD_HC_compressBlock_lazy(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSiz
     return ZSTD_HC_compressBlock_lazy_generic(ctx, dst, maxDstSize, src, srcSize, 0, 0);
 }
 
-#else
-
-size_t ZSTD_HC_compressBlock_btlazy2(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
-{
-    seqStore_t* seqStorePtr = &(ctx->seqStore);
-    const BYTE* const istart = (const BYTE*)src;
-    const BYTE* ip = istart;
-    const BYTE* anchor = istart;
-    const BYTE* const iend = istart + srcSize;
-    const BYTE* const ilimit = iend - 8;
-
-    size_t offset_2=REPCODE_STARTVALUE, offset_1=REPCODE_STARTVALUE;
-    const U32 maxSearches = 1 << ctx->params.searchLog;
-    const U32 mls = ctx->params.searchLength;
-
-    /* init */
-    ZSTD_resetSeqStore(seqStorePtr);
-    if (((ip-ctx->base) - ctx->dictLimit) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
-
-    /* Match Loop */
-    while (ip <= ilimit)
-    {
-        size_t matchLength;
-        size_t offset=999999;
-        const BYTE* start;
-
-        /* try to find a first match */
-        if (MEM_read32(ip) == MEM_read32(ip - offset_2))
-        {
-            /* repcode : we take it*/
-            size_t offtmp = offset_2;
-            size_t litLength = ip - anchor;
-            matchLength = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_2, iend);
-            offset_2 = offset_1;
-            offset_1 = offtmp;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, 0, matchLength);
-            ip += matchLength+MINMATCH;
-            anchor = ip;
-            continue;
-        }
-
-        offset_2 = offset_1;
-        matchLength = ZSTD_HC_BtFindBestMatch_selectMLS(ctx, ip, iend, &offset, maxSearches, mls);
-        if (!matchLength) { ip++; continue; }
-
-        /* let's try to find a better solution */
-        start = ip;
-
-        while (ip<ilimit)
-        {
-            ip ++;
-            if (MEM_read32(ip) == MEM_read32(ip - offset_1))
-            {
-                size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
-                int gain2 = (int)(ml2 * 3);
-                int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 1);
-                if (gain2 > gain1)
-                    matchLength = ml2, offset = 0, start = ip;
-            }
-            {
-                size_t offset2=999999;
-                size_t ml2 = ZSTD_HC_BtFindBestMatch_selectMLS(ctx, ip, iend, &offset2, maxSearches, mls);
-                int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 4);
-                if (gain2 > gain1)
-                {
-                    matchLength = ml2, offset = offset2, start = ip;
-                    continue;   /* search a better one */
-                }
-            }
-
-            /* let's find an even better one */
-            if (ip<ilimit)
-            {
-                ip ++;
-                if (MEM_read32(ip) == MEM_read32(ip - offset_1))
-                {
-                    size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
-                    int gain2 = (int)(ml2 * 4);
-                    int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 1);
-                    if (gain2 > gain1)
-                        matchLength = ml2, offset = 0, start = ip;
-                }
-                {
-                    size_t offset2=999999;
-                    size_t ml2 = ZSTD_HC_BtFindBestMatch_selectMLS(ctx, ip, iend, &offset2, maxSearches, mls);
-                    int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                    int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
-                    if (gain2 > gain1)
-                    {
-                        matchLength = ml2, offset = offset2, start = ip;
-                        continue;
-                    }
-                }
-            }
-            break;  /* nothing found : store previous solution */
-        }
-
-        /* store sequence */
-        {
-            size_t litLength = start - anchor;
-            if (offset) offset_1 = offset;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH);
-            ip = start + matchLength;
-            anchor = ip;
-        }
-
-    }
-
-    /* Last Literals */
-    {
-        size_t lastLLSize = iend - anchor;
-        memcpy(seqStorePtr->lit, anchor, lastLLSize);
-        seqStorePtr->lit += lastLLSize;
-    }
-
-    /* Final compression stage */
-    return ZSTD_compressSequences((BYTE*)dst, maxDstSize,
-                                  seqStorePtr, srcSize);
-}
-
-
-size_t ZSTD_HC_compressBlock_hclazy2(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
-{
-    seqStore_t* seqStorePtr = &(ctx->seqStore);
-    const BYTE* const istart = (const BYTE*)src;
-    const BYTE* ip = istart;
-    const BYTE* anchor = istart;
-    const BYTE* const iend = istart + srcSize;
-    const BYTE* const ilimit = iend - 8;
-
-    size_t offset_2=REPCODE_STARTVALUE, offset_1=REPCODE_STARTVALUE;
-    const U32 maxSearches = 1 << ctx->params.searchLog;
-    const U32 mls = ctx->params.searchLength;
-
-    /* init */
-    ZSTD_resetSeqStore(seqStorePtr);
-    if (((ip-ctx->base) - ctx->dictLimit) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
-
-    /* Match Loop */
-    while (ip <= ilimit)
-    {
-        size_t matchLength;
-        size_t offset=999999;
-        const BYTE* start;
-
-        /* try to find a first match */
-        if (MEM_read32(ip) == MEM_read32(ip - offset_2))
-        {
-            /* repcode : we take it*/
-            size_t offtmp = offset_2;
-            size_t litLength = ip - anchor;
-            matchLength = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_2, iend);
-            offset_2 = offset_1;
-            offset_1 = offtmp;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, 0, matchLength);
-            ip += matchLength+MINMATCH;
-            anchor = ip;
-            continue;
-        }
-
-        offset_2 = offset_1;
-        matchLength = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &offset, maxSearches, mls);
-        if (!matchLength) { ip++; continue; }
-
-        /* let's try to find a better solution */
-        start = ip;
-
-        while (ip<ilimit)
-        {
-            ip ++;
-            if (MEM_read32(ip) == MEM_read32(ip - offset_1))
-            {
-                size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
-                int gain2 = (int)(ml2 * 3);
-                int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 1);
-                if (gain2 > gain1)
-                    matchLength = ml2, offset = 0, start = ip;
-            }
-            {
-                size_t offset2=999999;
-                size_t ml2 = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &offset2, maxSearches, mls);
-                int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 4);
-                if (gain2 > gain1)
-                {
-                    matchLength = ml2, offset = offset2, start = ip;
-                    continue;   /* search a better one */
-                }
-            }
-
-            /* let's find an even better one */
-            if (ip<ilimit)
-            {
-                ip ++;
-                if (MEM_read32(ip) == MEM_read32(ip - offset_1))
-                {
-                    size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
-                    int gain2 = (int)(ml2 * 4);
-                    int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 1);
-                    if (gain2 > gain1)
-                        matchLength = ml2, offset = 0, start = ip;
-                }
-                {
-                    size_t offset2=999999;
-                    size_t ml2 = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &offset2, maxSearches, mls);
-                    int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                    int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
-                    if (gain2 > gain1)
-                    {
-                        matchLength = ml2, offset = offset2, start = ip;
-                        continue;
-                    }
-                }
-            }
-            break;  /* nothing found : store previous solution */
-        }
-
-        /* store sequence */
-        {
-            size_t litLength = start - anchor;
-            if (offset) offset_1 = offset;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH);
-            ip = start + matchLength;
-            anchor = ip;
-        }
-
-    }
-
-    /* Last Literals */
-    {
-        size_t lastLLSize = iend - anchor;
-        memcpy(seqStorePtr->lit, anchor, lastLLSize);
-        seqStorePtr->lit += lastLLSize;
-    }
-
-    /* Final compression stage */
-    return ZSTD_compressSequences((BYTE*)dst, maxDstSize,
-                                  seqStorePtr, srcSize);
-}
-
-size_t ZSTD_HC_compressBlock_lazy(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
-{
-    seqStore_t* seqStorePtr = &(ctx->seqStore);
-    const BYTE* const istart = (const BYTE*)src;
-    const BYTE* ip = istart;
-    const BYTE* anchor = istart;
-    const BYTE* const iend = istart + srcSize;
-    const BYTE* const ilimit = iend - 8;
-
-    size_t offset_2=REPCODE_STARTVALUE, offset_1=REPCODE_STARTVALUE;
-    const U32 maxSearches = 1 << ctx->params.searchLog;
-    const U32 mls = ctx->params.searchLength;
-
-    /* init */
-    ZSTD_resetSeqStore(seqStorePtr);
-    if (((ip-ctx->base) - ctx->dictLimit) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
-
-    /* Match Loop */
-    while (ip <= ilimit)
-    {
-        size_t matchLength;
-        size_t offset=0;
-        const BYTE* start;
-
-        /* try to find a first match */
-        if (MEM_read32(ip) == MEM_read32(ip - offset_2))
-        {
-            /* repcode : we take it*/
-            size_t offtmp = offset_2;
-            size_t litLength = ip - anchor;
-            matchLength = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_2, iend);
-            offset_2 = offset_1;
-            offset_1 = offtmp;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, 0, matchLength);
-            ip += matchLength+MINMATCH;
-            anchor = ip;
-            continue;
-        }
-
-        offset_2 = offset_1;
-        matchLength = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &offset, maxSearches, mls);
-        if (!matchLength) { ip++; continue; }
-
-        /* let's try to find a better solution */
-        start = ip;
-
-        while (ip<ilimit)
-        {
-            ip ++;
-            if (MEM_read32(ip) == MEM_read32(ip - offset_1))
-            {
-                size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
-                int gain2 = (int)(ml2 * 3);
-                int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 1);
-                if (gain2 > gain1)
-                {
-                    matchLength = ml2, offset = 0, start = ip;
-
-                }
-            }
-            {
-                size_t offset2=999999;
-                size_t ml2 = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &offset2, maxSearches, mls);
-                int gain2 = (int)(ml2*3 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 3);
-                if (gain2 > gain1)
-                {
-                    matchLength = ml2, offset = offset2, start = ip;
-                    continue;   /* search a better one */
-                }
-            }
-
-            break;  /* nothing found : store previous one */
-        }
-
-        /* store sequence */
-        {
-            size_t litLength = start - anchor;
-            if (offset) offset_1 = offset;
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH);
-            ip = start + matchLength;
-            anchor = ip;
-        }
-
-    }
-
-    /* Last Literals */
-    {
-        size_t lastLLSize = iend - anchor;
-        memcpy(seqStorePtr->lit, anchor, lastLLSize);
-        seqStorePtr->lit += lastLLSize;
-    }
-
-    /* Final compression stage */
-    return ZSTD_compressSequences((BYTE*)dst, maxDstSize,
-                                  seqStorePtr, srcSize);
-}
-
-
-#endif
-
-
-
 
 size_t ZSTD_HC_compressBlock_greedy(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
 {