zstdlib 0.14.0-x86-mingw32 → 0.15.0-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/ext/zstdlib_c/extconf.rb +1 -1
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/bits.h +92 -87
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/bitstream.h +26 -29
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/compiler.h +36 -22
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/cpu.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/debug.h +0 -9
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/error_private.c +1 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/error_private.h +0 -10
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/fse.h +2 -17
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/fse_decompress.c +2 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/huf.h +0 -9
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/mem.h +7 -11
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/pool.h +0 -9
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/portability_macros.h +22 -9
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/threading.h +0 -8
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/xxhash.h +93 -19
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/zstd_deps.h +12 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/zstd_internal.h +1 -69
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/zstd_trace.h +5 -12
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/hist.c +10 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/hist.h +7 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress.c +1057 -367
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_internal.h +227 -125
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_literals.c +1 -1
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_sequences.c +7 -7
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_sequences.h +7 -6
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_superblock.c +17 -17
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_cwksp.h +41 -24
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_double_fast.c +58 -50
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_double_fast.h +4 -12
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_fast.c +91 -74
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_fast.h +4 -12
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_lazy.c +64 -64
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_lazy.h +30 -39
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_ldm.c +48 -33
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_ldm.h +6 -14
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_opt.c +55 -51
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_opt.h +8 -16
- data/ext/zstdlib_c/zstd-1.5.7/lib/compress/zstd_preSplit.c +238 -0
- data/ext/zstdlib_c/zstd-1.5.7/lib/compress/zstd_preSplit.h +33 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstdmt_compress.c +134 -93
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstdmt_compress.h +4 -15
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/huf_decompress_amd64.S +10 -3
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_decompress.c +14 -11
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_decompress_block.c +6 -12
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_decompress_internal.h +5 -5
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/zdict.h +15 -8
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/zstd.h +241 -132
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/zstd_errors.h +1 -8
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzwrite.c +2 -1
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/3.1/zstdlib_c.so +0 -0
- data/lib/3.2/zstdlib_c.so +0 -0
- data/lib/3.3/zstdlib_c.so +0 -0
- data/lib/3.4/zstdlib_c.so +0 -0
- metadata +75 -73
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/allocations.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/debug.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/entropy_common.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/pool.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/threading.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/xxhash.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/common/zstd_common.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/clevels.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/fse_compress.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/huf_compress.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_literals.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_compress_superblock.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/compress/zstd_ldm_geartab.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/huf_decompress.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_ddict.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_ddict.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/lib/decompress/zstd_decompress_block.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzclose.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzcompatibility.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzguts.h +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzlib.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/gzread.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/zstd_zlibwrapper.c +0 -0
- data/ext/zstdlib_c/{zstd-1.5.6 → zstd-1.5.7}/zlibWrapper/zstd_zlibwrapper.h +5 -5
| @@ -90,9 +90,9 @@ static unsigned long long GetCurrentClockTimeMicroseconds(void) | |
| 90 90 | 
             
            typedef struct buffer_s {
         | 
| 91 91 | 
             
                void* start;
         | 
| 92 92 | 
             
                size_t capacity;
         | 
| 93 | 
            -
            }  | 
| 93 | 
            +
            } Buffer;
         | 
| 94 94 |  | 
| 95 | 
            -
            static const  | 
| 95 | 
            +
            static const Buffer g_nullBuffer = { NULL, 0 };
         | 
| 96 96 |  | 
| 97 97 | 
             
            typedef struct ZSTDMT_bufferPool_s {
         | 
| 98 98 | 
             
                ZSTD_pthread_mutex_t poolMutex;
         | 
| @@ -100,7 +100,7 @@ typedef struct ZSTDMT_bufferPool_s { | |
| 100 100 | 
             
                unsigned totalBuffers;
         | 
| 101 101 | 
             
                unsigned nbBuffers;
         | 
| 102 102 | 
             
                ZSTD_customMem cMem;
         | 
| 103 | 
            -
                 | 
| 103 | 
            +
                Buffer* buffers;
         | 
| 104 104 | 
             
            } ZSTDMT_bufferPool;
         | 
| 105 105 |  | 
| 106 106 | 
             
            static void ZSTDMT_freeBufferPool(ZSTDMT_bufferPool* bufPool)
         | 
| @@ -128,7 +128,7 @@ static ZSTDMT_bufferPool* ZSTDMT_createBufferPool(unsigned maxNbBuffers, ZSTD_cu | |
| 128 128 | 
             
                    ZSTD_customFree(bufPool, cMem);
         | 
| 129 129 | 
             
                    return NULL;
         | 
| 130 130 | 
             
                }
         | 
| 131 | 
            -
                bufPool->buffers = ( | 
| 131 | 
            +
                bufPool->buffers = (Buffer*)ZSTD_customCalloc(maxNbBuffers * sizeof(Buffer), cMem);
         | 
| 132 132 | 
             
                if (bufPool->buffers==NULL) {
         | 
| 133 133 | 
             
                    ZSTDMT_freeBufferPool(bufPool);
         | 
| 134 134 | 
             
                    return NULL;
         | 
| @@ -144,7 +144,7 @@ static ZSTDMT_bufferPool* ZSTDMT_createBufferPool(unsigned maxNbBuffers, ZSTD_cu | |
| 144 144 | 
             
            static size_t ZSTDMT_sizeof_bufferPool(ZSTDMT_bufferPool* bufPool)
         | 
| 145 145 | 
             
            {
         | 
| 146 146 | 
             
                size_t const poolSize = sizeof(*bufPool);
         | 
| 147 | 
            -
                size_t const arraySize = bufPool->totalBuffers * sizeof( | 
| 147 | 
            +
                size_t const arraySize = bufPool->totalBuffers * sizeof(Buffer);
         | 
| 148 148 | 
             
                unsigned u;
         | 
| 149 149 | 
             
                size_t totalBufferSize = 0;
         | 
| 150 150 | 
             
                ZSTD_pthread_mutex_lock(&bufPool->poolMutex);
         | 
| @@ -189,13 +189,13 @@ static ZSTDMT_bufferPool* ZSTDMT_expandBufferPool(ZSTDMT_bufferPool* srcBufPool, | |
| 189 189 | 
             
             *  assumption : bufPool must be valid
         | 
| 190 190 | 
             
             * @return : a buffer, with start pointer and size
         | 
| 191 191 | 
             
             *  note: allocation may fail, in this case, start==NULL and size==0 */
         | 
| 192 | 
            -
            static  | 
| 192 | 
            +
            static Buffer ZSTDMT_getBuffer(ZSTDMT_bufferPool* bufPool)
         | 
| 193 193 | 
             
            {
         | 
| 194 194 | 
             
                size_t const bSize = bufPool->bufferSize;
         | 
| 195 195 | 
             
                DEBUGLOG(5, "ZSTDMT_getBuffer: bSize = %u", (U32)bufPool->bufferSize);
         | 
| 196 196 | 
             
                ZSTD_pthread_mutex_lock(&bufPool->poolMutex);
         | 
| 197 197 | 
             
                if (bufPool->nbBuffers) {   /* try to use an existing buffer */
         | 
| 198 | 
            -
                     | 
| 198 | 
            +
                    Buffer const buf = bufPool->buffers[--(bufPool->nbBuffers)];
         | 
| 199 199 | 
             
                    size_t const availBufferSize = buf.capacity;
         | 
| 200 200 | 
             
                    bufPool->buffers[bufPool->nbBuffers] = g_nullBuffer;
         | 
| 201 201 | 
             
                    if ((availBufferSize >= bSize) & ((availBufferSize>>3) <= bSize)) {
         | 
| @@ -212,7 +212,7 @@ static buffer_t ZSTDMT_getBuffer(ZSTDMT_bufferPool* bufPool) | |
| 212 212 | 
             
                ZSTD_pthread_mutex_unlock(&bufPool->poolMutex);
         | 
| 213 213 | 
             
                /* create new buffer */
         | 
| 214 214 | 
             
                DEBUGLOG(5, "ZSTDMT_getBuffer: create a new buffer");
         | 
| 215 | 
            -
                {    | 
| 215 | 
            +
                {   Buffer buffer;
         | 
| 216 216 | 
             
                    void* const start = ZSTD_customMalloc(bSize, bufPool->cMem);
         | 
| 217 217 | 
             
                    buffer.start = start;   /* note : start can be NULL if malloc fails ! */
         | 
| 218 218 | 
             
                    buffer.capacity = (start==NULL) ? 0 : bSize;
         | 
| @@ -231,12 +231,12 @@ static buffer_t ZSTDMT_getBuffer(ZSTDMT_bufferPool* bufPool) | |
| 231 231 | 
             
             * @return : a buffer that is at least the buffer pool buffer size.
         | 
| 232 232 | 
             
             *           If a reallocation happens, the data in the input buffer is copied.
         | 
| 233 233 | 
             
             */
         | 
| 234 | 
            -
            static  | 
| 234 | 
            +
            static Buffer ZSTDMT_resizeBuffer(ZSTDMT_bufferPool* bufPool, Buffer buffer)
         | 
| 235 235 | 
             
            {
         | 
| 236 236 | 
             
                size_t const bSize = bufPool->bufferSize;
         | 
| 237 237 | 
             
                if (buffer.capacity < bSize) {
         | 
| 238 238 | 
             
                    void* const start = ZSTD_customMalloc(bSize, bufPool->cMem);
         | 
| 239 | 
            -
                     | 
| 239 | 
            +
                    Buffer newBuffer;
         | 
| 240 240 | 
             
                    newBuffer.start = start;
         | 
| 241 241 | 
             
                    newBuffer.capacity = start == NULL ? 0 : bSize;
         | 
| 242 242 | 
             
                    if (start != NULL) {
         | 
| @@ -252,7 +252,7 @@ static buffer_t ZSTDMT_resizeBuffer(ZSTDMT_bufferPool* bufPool, buffer_t buffer) | |
| 252 252 | 
             
            #endif
         | 
| 253 253 |  | 
| 254 254 | 
             
            /* store buffer for later re-use, up to pool capacity */
         | 
| 255 | 
            -
            static void ZSTDMT_releaseBuffer(ZSTDMT_bufferPool* bufPool,  | 
| 255 | 
            +
            static void ZSTDMT_releaseBuffer(ZSTDMT_bufferPool* bufPool, Buffer buf)
         | 
| 256 256 | 
             
            {
         | 
| 257 257 | 
             
                DEBUGLOG(5, "ZSTDMT_releaseBuffer");
         | 
| 258 258 | 
             
                if (buf.start == NULL) return;   /* compatible with release on NULL */
         | 
| @@ -290,23 +290,23 @@ static size_t ZSTDMT_sizeof_seqPool(ZSTDMT_seqPool* seqPool) | |
| 290 290 | 
             
                return ZSTDMT_sizeof_bufferPool(seqPool);
         | 
| 291 291 | 
             
            }
         | 
| 292 292 |  | 
| 293 | 
            -
            static  | 
| 293 | 
            +
            static RawSeqStore_t bufferToSeq(Buffer buffer)
         | 
| 294 294 | 
             
            {
         | 
| 295 | 
            -
                 | 
| 295 | 
            +
                RawSeqStore_t seq = kNullRawSeqStore;
         | 
| 296 296 | 
             
                seq.seq = (rawSeq*)buffer.start;
         | 
| 297 297 | 
             
                seq.capacity = buffer.capacity / sizeof(rawSeq);
         | 
| 298 298 | 
             
                return seq;
         | 
| 299 299 | 
             
            }
         | 
| 300 300 |  | 
| 301 | 
            -
            static  | 
| 301 | 
            +
            static Buffer seqToBuffer(RawSeqStore_t seq)
         | 
| 302 302 | 
             
            {
         | 
| 303 | 
            -
                 | 
| 303 | 
            +
                Buffer buffer;
         | 
| 304 304 | 
             
                buffer.start = seq.seq;
         | 
| 305 305 | 
             
                buffer.capacity = seq.capacity * sizeof(rawSeq);
         | 
| 306 306 | 
             
                return buffer;
         | 
| 307 307 | 
             
            }
         | 
| 308 308 |  | 
| 309 | 
            -
            static  | 
| 309 | 
            +
            static RawSeqStore_t ZSTDMT_getSeq(ZSTDMT_seqPool* seqPool)
         | 
| 310 310 | 
             
            {
         | 
| 311 311 | 
             
                if (seqPool->bufferSize == 0) {
         | 
| 312 312 | 
             
                    return kNullRawSeqStore;
         | 
| @@ -315,13 +315,13 @@ static rawSeqStore_t ZSTDMT_getSeq(ZSTDMT_seqPool* seqPool) | |
| 315 315 | 
             
            }
         | 
| 316 316 |  | 
| 317 317 | 
             
            #if ZSTD_RESIZE_SEQPOOL
         | 
| 318 | 
            -
            static  | 
| 318 | 
            +
            static RawSeqStore_t ZSTDMT_resizeSeq(ZSTDMT_seqPool* seqPool, RawSeqStore_t seq)
         | 
| 319 319 | 
             
            {
         | 
| 320 320 | 
             
              return bufferToSeq(ZSTDMT_resizeBuffer(seqPool, seqToBuffer(seq)));
         | 
| 321 321 | 
             
            }
         | 
| 322 322 | 
             
            #endif
         | 
| 323 323 |  | 
| 324 | 
            -
            static void ZSTDMT_releaseSeq(ZSTDMT_seqPool* seqPool,  | 
| 324 | 
            +
            static void ZSTDMT_releaseSeq(ZSTDMT_seqPool* seqPool, RawSeqStore_t seq)
         | 
| 325 325 | 
             
            {
         | 
| 326 326 | 
             
              ZSTDMT_releaseBuffer(seqPool, seqToBuffer(seq));
         | 
| 327 327 | 
             
            }
         | 
| @@ -466,7 +466,7 @@ static void ZSTDMT_releaseCCtx(ZSTDMT_CCtxPool* pool, ZSTD_CCtx* cctx) | |
| 466 466 | 
             
            typedef struct {
         | 
| 467 467 | 
             
                void const* start;
         | 
| 468 468 | 
             
                size_t size;
         | 
| 469 | 
            -
            }  | 
| 469 | 
            +
            } Range;
         | 
| 470 470 |  | 
| 471 471 | 
             
            typedef struct {
         | 
| 472 472 | 
             
                /* All variables in the struct are protected by mutex. */
         | 
| @@ -482,10 +482,10 @@ typedef struct { | |
| 482 482 | 
             
                ZSTD_pthread_mutex_t ldmWindowMutex;
         | 
| 483 483 | 
             
                ZSTD_pthread_cond_t ldmWindowCond;  /* Signaled when ldmWindow is updated */
         | 
| 484 484 | 
             
                ZSTD_window_t ldmWindow;  /* A thread-safe copy of ldmState.window */
         | 
| 485 | 
            -
            }  | 
| 485 | 
            +
            } SerialState;
         | 
| 486 486 |  | 
| 487 487 | 
             
            static int
         | 
| 488 | 
            -
            ZSTDMT_serialState_reset( | 
| 488 | 
            +
            ZSTDMT_serialState_reset(SerialState* serialState,
         | 
| 489 489 | 
             
                                     ZSTDMT_seqPool* seqPool,
         | 
| 490 490 | 
             
                                     ZSTD_CCtx_params params,
         | 
| 491 491 | 
             
                                     size_t jobSize,
         | 
| @@ -555,7 +555,7 @@ ZSTDMT_serialState_reset(serialState_t* serialState, | |
| 555 555 | 
             
                return 0;
         | 
| 556 556 | 
             
            }
         | 
| 557 557 |  | 
| 558 | 
            -
            static int ZSTDMT_serialState_init( | 
| 558 | 
            +
            static int ZSTDMT_serialState_init(SerialState* serialState)
         | 
| 559 559 | 
             
            {
         | 
| 560 560 | 
             
                int initError = 0;
         | 
| 561 561 | 
             
                ZSTD_memset(serialState, 0, sizeof(*serialState));
         | 
| @@ -566,7 +566,7 @@ static int ZSTDMT_serialState_init(serialState_t* serialState) | |
| 566 566 | 
             
                return initError;
         | 
| 567 567 | 
             
            }
         | 
| 568 568 |  | 
| 569 | 
            -
            static void ZSTDMT_serialState_free( | 
| 569 | 
            +
            static void ZSTDMT_serialState_free(SerialState* serialState)
         | 
| 570 570 | 
             
            {
         | 
| 571 571 | 
             
                ZSTD_customMem cMem = serialState->params.customMem;
         | 
| 572 572 | 
             
                ZSTD_pthread_mutex_destroy(&serialState->mutex);
         | 
| @@ -577,9 +577,10 @@ static void ZSTDMT_serialState_free(serialState_t* serialState) | |
| 577 577 | 
             
                ZSTD_customFree(serialState->ldmState.bucketOffsets, cMem);
         | 
| 578 578 | 
             
            }
         | 
| 579 579 |  | 
| 580 | 
            -
            static void | 
| 581 | 
            -
             | 
| 582 | 
            -
             | 
| 580 | 
            +
            static void
         | 
| 581 | 
            +
            ZSTDMT_serialState_genSequences(SerialState* serialState,
         | 
| 582 | 
            +
                                            RawSeqStore_t* seqStore,
         | 
| 583 | 
            +
                                            Range src, unsigned jobID)
         | 
| 583 584 | 
             
            {
         | 
| 584 585 | 
             
                /* Wait for our turn */
         | 
| 585 586 | 
             
                ZSTD_PTHREAD_MUTEX_LOCK(&serialState->mutex);
         | 
| @@ -592,12 +593,13 @@ static void ZSTDMT_serialState_update(serialState_t* serialState, | |
| 592 593 | 
             
                    /* It is now our turn, do any processing necessary */
         | 
| 593 594 | 
             
                    if (serialState->params.ldmParams.enableLdm == ZSTD_ps_enable) {
         | 
| 594 595 | 
             
                        size_t error;
         | 
| 595 | 
            -
                         | 
| 596 | 
            -
             | 
| 596 | 
            +
                        DEBUGLOG(6, "ZSTDMT_serialState_genSequences: LDM update");
         | 
| 597 | 
            +
                        assert(seqStore->seq != NULL && seqStore->pos == 0 &&
         | 
| 598 | 
            +
                               seqStore->size == 0 && seqStore->capacity > 0);
         | 
| 597 599 | 
             
                        assert(src.size <= serialState->params.jobSize);
         | 
| 598 600 | 
             
                        ZSTD_window_update(&serialState->ldmState.window, src.start, src.size, /* forceNonContiguous */ 0);
         | 
| 599 601 | 
             
                        error = ZSTD_ldm_generateSequences(
         | 
| 600 | 
            -
                            &serialState->ldmState,  | 
| 602 | 
            +
                            &serialState->ldmState, seqStore,
         | 
| 601 603 | 
             
                            &serialState->params.ldmParams, src.start, src.size);
         | 
| 602 604 | 
             
                        /* We provide a large enough buffer to never fail. */
         | 
| 603 605 | 
             
                        assert(!ZSTD_isError(error)); (void)error;
         | 
| @@ -616,14 +618,22 @@ static void ZSTDMT_serialState_update(serialState_t* serialState, | |
| 616 618 | 
             
                serialState->nextJobID++;
         | 
| 617 619 | 
             
                ZSTD_pthread_cond_broadcast(&serialState->cond);
         | 
| 618 620 | 
             
                ZSTD_pthread_mutex_unlock(&serialState->mutex);
         | 
| 621 | 
            +
            }
         | 
| 619 622 |  | 
| 620 | 
            -
             | 
| 621 | 
            -
             | 
| 622 | 
            -
             | 
| 623 | 
            +
            static void
         | 
| 624 | 
            +
            ZSTDMT_serialState_applySequences(const SerialState* serialState, /* just for an assert() check */
         | 
| 625 | 
            +
                                              ZSTD_CCtx* jobCCtx,
         | 
| 626 | 
            +
                                              const RawSeqStore_t* seqStore)
         | 
| 627 | 
            +
            {
         | 
| 628 | 
            +
                if (seqStore->size > 0) {
         | 
| 629 | 
            +
                    DEBUGLOG(5, "ZSTDMT_serialState_applySequences: uploading %u external sequences", (unsigned)seqStore->size);
         | 
| 630 | 
            +
                    assert(serialState->params.ldmParams.enableLdm == ZSTD_ps_enable); (void)serialState;
         | 
| 631 | 
            +
                    assert(jobCCtx);
         | 
| 632 | 
            +
                    ZSTD_referenceExternalSequences(jobCCtx, seqStore->seq, seqStore->size);
         | 
| 623 633 | 
             
                }
         | 
| 624 634 | 
             
            }
         | 
| 625 635 |  | 
| 626 | 
            -
            static void ZSTDMT_serialState_ensureFinished( | 
| 636 | 
            +
            static void ZSTDMT_serialState_ensureFinished(SerialState* serialState,
         | 
| 627 637 | 
             
                                                          unsigned jobID, size_t cSize)
         | 
| 628 638 | 
             
            {
         | 
| 629 639 | 
             
                ZSTD_PTHREAD_MUTEX_LOCK(&serialState->mutex);
         | 
| @@ -647,28 +657,28 @@ static void ZSTDMT_serialState_ensureFinished(serialState_t* serialState, | |
| 647 657 | 
             
            /* =====          Worker thread         ===== */
         | 
| 648 658 | 
             
            /* ------------------------------------------ */
         | 
| 649 659 |  | 
| 650 | 
            -
            static const  | 
| 660 | 
            +
            static const Range kNullRange = { NULL, 0 };
         | 
| 651 661 |  | 
| 652 662 | 
             
            typedef struct {
         | 
| 653 | 
            -
                size_t   consumed; | 
| 654 | 
            -
                size_t   cSize; | 
| 655 | 
            -
                ZSTD_pthread_mutex_t job_mutex; | 
| 656 | 
            -
                ZSTD_pthread_cond_t job_cond; | 
| 657 | 
            -
                ZSTDMT_CCtxPool* cctxPool; | 
| 658 | 
            -
                ZSTDMT_bufferPool* bufPool; | 
| 659 | 
            -
                ZSTDMT_seqPool* seqPool; | 
| 660 | 
            -
                 | 
| 661 | 
            -
                 | 
| 662 | 
            -
                 | 
| 663 | 
            -
                 | 
| 664 | 
            -
                unsigned jobID; | 
| 665 | 
            -
                unsigned firstJob; | 
| 666 | 
            -
                unsigned lastJob; | 
| 667 | 
            -
                ZSTD_CCtx_params params; | 
| 668 | 
            -
                const ZSTD_CDict* cdict; | 
| 669 | 
            -
                unsigned long long fullFrameSize; | 
| 670 | 
            -
                size_t   dstFlushed; | 
| 671 | 
            -
                unsigned frameChecksumNeeded; | 
| 663 | 
            +
                size_t   consumed;                 /* SHARED - set0 by mtctx, then modified by worker AND read by mtctx */
         | 
| 664 | 
            +
                size_t   cSize;                    /* SHARED - set0 by mtctx, then modified by worker AND read by mtctx, then set0 by mtctx */
         | 
| 665 | 
            +
                ZSTD_pthread_mutex_t job_mutex;    /* Thread-safe - used by mtctx and worker */
         | 
| 666 | 
            +
                ZSTD_pthread_cond_t job_cond;      /* Thread-safe - used by mtctx and worker */
         | 
| 667 | 
            +
                ZSTDMT_CCtxPool* cctxPool;         /* Thread-safe - used by mtctx and (all) workers */
         | 
| 668 | 
            +
                ZSTDMT_bufferPool* bufPool;        /* Thread-safe - used by mtctx and (all) workers */
         | 
| 669 | 
            +
                ZSTDMT_seqPool* seqPool;           /* Thread-safe - used by mtctx and (all) workers */
         | 
| 670 | 
            +
                SerialState* serial;               /* Thread-safe - used by mtctx and (all) workers */
         | 
| 671 | 
            +
                Buffer dstBuff;                    /* set by worker (or mtctx), then read by worker & mtctx, then modified by mtctx => no barrier */
         | 
| 672 | 
            +
                Range prefix;                      /* set by mtctx, then read by worker & mtctx => no barrier */
         | 
| 673 | 
            +
                Range src;                         /* set by mtctx, then read by worker & mtctx => no barrier */
         | 
| 674 | 
            +
                unsigned jobID;                    /* set by mtctx, then read by worker => no barrier */
         | 
| 675 | 
            +
                unsigned firstJob;                 /* set by mtctx, then read by worker => no barrier */
         | 
| 676 | 
            +
                unsigned lastJob;                  /* set by mtctx, then read by worker => no barrier */
         | 
| 677 | 
            +
                ZSTD_CCtx_params params;           /* set by mtctx, then read by worker => no barrier */
         | 
| 678 | 
            +
                const ZSTD_CDict* cdict;           /* set by mtctx, then read by worker => no barrier */
         | 
| 679 | 
            +
                unsigned long long fullFrameSize;  /* set by mtctx, then read by worker => no barrier */
         | 
| 680 | 
            +
                size_t   dstFlushed;               /* used only by mtctx */
         | 
| 681 | 
            +
                unsigned frameChecksumNeeded;      /* used only by mtctx */
         | 
| 672 682 | 
             
            } ZSTDMT_jobDescription;
         | 
| 673 683 |  | 
| 674 684 | 
             
            #define JOB_ERROR(e)                                \
         | 
| @@ -685,10 +695,11 @@ static void ZSTDMT_compressionJob(void* jobDescription) | |
| 685 695 | 
             
                ZSTDMT_jobDescription* const job = (ZSTDMT_jobDescription*)jobDescription;
         | 
| 686 696 | 
             
                ZSTD_CCtx_params jobParams = job->params;   /* do not modify job->params ! copy it, modify the copy */
         | 
| 687 697 | 
             
                ZSTD_CCtx* const cctx = ZSTDMT_getCCtx(job->cctxPool);
         | 
| 688 | 
            -
                 | 
| 689 | 
            -
                 | 
| 698 | 
            +
                RawSeqStore_t rawSeqStore = ZSTDMT_getSeq(job->seqPool);
         | 
| 699 | 
            +
                Buffer dstBuff = job->dstBuff;
         | 
| 690 700 | 
             
                size_t lastCBlockSize = 0;
         | 
| 691 701 |  | 
| 702 | 
            +
                DEBUGLOG(5, "ZSTDMT_compressionJob: job %u", job->jobID);
         | 
| 692 703 | 
             
                /* resources */
         | 
| 693 704 | 
             
                if (cctx==NULL) JOB_ERROR(ERROR(memory_allocation));
         | 
| 694 705 | 
             
                if (dstBuff.start == NULL) {   /* streaming job : doesn't provide a dstBuffer */
         | 
| @@ -710,11 +721,15 @@ static void ZSTDMT_compressionJob(void* jobDescription) | |
| 710 721 |  | 
| 711 722 |  | 
| 712 723 | 
             
                /* init */
         | 
| 724 | 
            +
             | 
| 725 | 
            +
                /* Perform serial step as early as possible */
         | 
| 726 | 
            +
                ZSTDMT_serialState_genSequences(job->serial, &rawSeqStore, job->src, job->jobID);
         | 
| 727 | 
            +
             | 
| 713 728 | 
             
                if (job->cdict) {
         | 
| 714 729 | 
             
                    size_t const initError = ZSTD_compressBegin_advanced_internal(cctx, NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast, job->cdict, &jobParams, job->fullFrameSize);
         | 
| 715 730 | 
             
                    assert(job->firstJob);  /* only allowed for first job */
         | 
| 716 731 | 
             
                    if (ZSTD_isError(initError)) JOB_ERROR(initError);
         | 
| 717 | 
            -
                } else { | 
| 732 | 
            +
                } else {
         | 
| 718 733 | 
             
                    U64 const pledgedSrcSize = job->firstJob ? job->fullFrameSize : job->src.size;
         | 
| 719 734 | 
             
                    {   size_t const forceWindowError = ZSTD_CCtxParams_setParameter(&jobParams, ZSTD_c_forceMaxWindow, !job->firstJob);
         | 
| 720 735 | 
             
                        if (ZSTD_isError(forceWindowError)) JOB_ERROR(forceWindowError);
         | 
| @@ -723,16 +738,17 @@ static void ZSTDMT_compressionJob(void* jobDescription) | |
| 723 738 | 
             
                        size_t const err = ZSTD_CCtxParams_setParameter(&jobParams, ZSTD_c_deterministicRefPrefix, 0);
         | 
| 724 739 | 
             
                        if (ZSTD_isError(err)) JOB_ERROR(err);
         | 
| 725 740 | 
             
                    }
         | 
| 741 | 
            +
                    DEBUGLOG(6, "ZSTDMT_compressionJob: job %u: loading prefix of size %zu", job->jobID, job->prefix.size);
         | 
| 726 742 | 
             
                    {   size_t const initError = ZSTD_compressBegin_advanced_internal(cctx,
         | 
| 727 | 
            -
                                                    job->prefix.start, job->prefix.size, ZSTD_dct_rawContent, | 
| 743 | 
            +
                                                    job->prefix.start, job->prefix.size, ZSTD_dct_rawContent,
         | 
| 728 744 | 
             
                                                    ZSTD_dtlm_fast,
         | 
| 729 745 | 
             
                                                    NULL, /*cdict*/
         | 
| 730 746 | 
             
                                                    &jobParams, pledgedSrcSize);
         | 
| 731 747 | 
             
                        if (ZSTD_isError(initError)) JOB_ERROR(initError);
         | 
| 732 748 | 
             
                }   }
         | 
| 733 749 |  | 
| 734 | 
            -
                /*  | 
| 735 | 
            -
                 | 
| 750 | 
            +
                /* External Sequences can only be applied after CCtx initialization */
         | 
| 751 | 
            +
                ZSTDMT_serialState_applySequences(job->serial, cctx, &rawSeqStore);
         | 
| 736 752 |  | 
| 737 753 | 
             
                if (!job->firstJob) {  /* flush and overwrite frame header when it's not first job */
         | 
| 738 754 | 
             
                    size_t const hSize = ZSTD_compressContinue_public(cctx, dstBuff.start, dstBuff.capacity, job->src.start, 0);
         | 
| @@ -741,7 +757,7 @@ static void ZSTDMT_compressionJob(void* jobDescription) | |
| 741 757 | 
             
                    ZSTD_invalidateRepCodes(cctx);
         | 
| 742 758 | 
             
                }
         | 
| 743 759 |  | 
| 744 | 
            -
                /* compress */
         | 
| 760 | 
            +
                /* compress the entire job by smaller chunks, for better granularity */
         | 
| 745 761 | 
             
                {   size_t const chunkSize = 4*ZSTD_BLOCKSIZE_MAX;
         | 
| 746 762 | 
             
                    int const nbChunks = (int)((job->src.size + (chunkSize-1)) / chunkSize);
         | 
| 747 763 | 
             
                    const BYTE* ip = (const BYTE*) job->src.start;
         | 
| @@ -809,10 +825,10 @@ _endJob: | |
| 809 825 | 
             
            /* ------------------------------------------ */
         | 
| 810 826 |  | 
| 811 827 | 
             
            typedef struct {
         | 
| 812 | 
            -
                 | 
| 813 | 
            -
                 | 
| 828 | 
            +
                Range prefix;         /* read-only non-owned prefix buffer */
         | 
| 829 | 
            +
                Buffer buffer;
         | 
| 814 830 | 
             
                size_t filled;
         | 
| 815 | 
            -
            }  | 
| 831 | 
            +
            } InBuff_t;
         | 
| 816 832 |  | 
| 817 833 | 
             
            typedef struct {
         | 
| 818 834 | 
             
              BYTE* buffer;     /* The round input buffer. All jobs get references
         | 
| @@ -826,9 +842,9 @@ typedef struct { | |
| 826 842 | 
             
                                 * the inBuff is sent to the worker thread.
         | 
| 827 843 | 
             
                                 * pos <= capacity.
         | 
| 828 844 | 
             
                                 */
         | 
| 829 | 
            -
            }  | 
| 845 | 
            +
            } RoundBuff_t;
         | 
| 830 846 |  | 
| 831 | 
            -
            static const  | 
| 847 | 
            +
            static const RoundBuff_t kNullRoundBuff = {NULL, 0, 0};
         | 
| 832 848 |  | 
| 833 849 | 
             
            #define RSYNC_LENGTH 32
         | 
| 834 850 | 
             
            /* Don't create chunks smaller than the zstd block size.
         | 
| @@ -845,7 +861,7 @@ typedef struct { | |
| 845 861 | 
             
              U64 hash;
         | 
| 846 862 | 
             
              U64 hitMask;
         | 
| 847 863 | 
             
              U64 primePower;
         | 
| 848 | 
            -
            }  | 
| 864 | 
            +
            } RSyncState_t;
         | 
| 849 865 |  | 
| 850 866 | 
             
            struct ZSTDMT_CCtx_s {
         | 
| 851 867 | 
             
                POOL_ctx* factory;
         | 
| @@ -857,10 +873,10 @@ struct ZSTDMT_CCtx_s { | |
| 857 873 | 
             
                size_t targetSectionSize;
         | 
| 858 874 | 
             
                size_t targetPrefixSize;
         | 
| 859 875 | 
             
                int jobReady;        /* 1 => one job is already prepared, but pool has shortage of workers. Don't create a new job. */
         | 
| 860 | 
            -
                 | 
| 861 | 
            -
                 | 
| 862 | 
            -
                 | 
| 863 | 
            -
                 | 
| 876 | 
            +
                InBuff_t inBuff;
         | 
| 877 | 
            +
                RoundBuff_t roundBuff;
         | 
| 878 | 
            +
                SerialState serial;
         | 
| 879 | 
            +
                RSyncState_t rsync;
         | 
| 864 880 | 
             
                unsigned jobIDMask;
         | 
| 865 881 | 
             
                unsigned doneJobID;
         | 
| 866 882 | 
             
                unsigned nextJobID;
         | 
| @@ -1245,13 +1261,11 @@ size_t ZSTDMT_initCStream_internal( | |
| 1245 1261 |  | 
| 1246 1262 | 
             
                /* init */
         | 
| 1247 1263 | 
             
                if (params.nbWorkers != mtctx->params.nbWorkers)
         | 
| 1248 | 
            -
                    FORWARD_IF_ERROR( ZSTDMT_resize(mtctx, params.nbWorkers) , "");
         | 
| 1264 | 
            +
                    FORWARD_IF_ERROR( ZSTDMT_resize(mtctx, (unsigned)params.nbWorkers) , "");
         | 
| 1249 1265 |  | 
| 1250 1266 | 
             
                if (params.jobSize != 0 && params.jobSize < ZSTDMT_JOBSIZE_MIN) params.jobSize = ZSTDMT_JOBSIZE_MIN;
         | 
| 1251 1267 | 
             
                if (params.jobSize > (size_t)ZSTDMT_JOBSIZE_MAX) params.jobSize = (size_t)ZSTDMT_JOBSIZE_MAX;
         | 
| 1252 1268 |  | 
| 1253 | 
            -
                DEBUGLOG(4, "ZSTDMT_initCStream_internal: %u workers", params.nbWorkers);
         | 
| 1254 | 
            -
             | 
| 1255 1269 | 
             
                if (mtctx->allJobsCompleted == 0) {   /* previous compression not correctly finished */
         | 
| 1256 1270 | 
             
                    ZSTDMT_waitForAllJobsCompleted(mtctx);
         | 
| 1257 1271 | 
             
                    ZSTDMT_releaseAllJobResources(mtctx);
         | 
| @@ -1260,15 +1274,14 @@ size_t ZSTDMT_initCStream_internal( | |
| 1260 1274 |  | 
| 1261 1275 | 
             
                mtctx->params = params;
         | 
| 1262 1276 | 
             
                mtctx->frameContentSize = pledgedSrcSize;
         | 
| 1277 | 
            +
                ZSTD_freeCDict(mtctx->cdictLocal);
         | 
| 1263 1278 | 
             
                if (dict) {
         | 
| 1264 | 
            -
                    ZSTD_freeCDict(mtctx->cdictLocal);
         | 
| 1265 1279 | 
             
                    mtctx->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize,
         | 
| 1266 1280 | 
             
                                                                ZSTD_dlm_byCopy, dictContentType, /* note : a loadPrefix becomes an internal CDict */
         | 
| 1267 1281 | 
             
                                                                params.cParams, mtctx->cMem);
         | 
| 1268 1282 | 
             
                    mtctx->cdict = mtctx->cdictLocal;
         | 
| 1269 1283 | 
             
                    if (mtctx->cdictLocal == NULL) return ERROR(memory_allocation);
         | 
| 1270 1284 | 
             
                } else {
         | 
| 1271 | 
            -
                    ZSTD_freeCDict(mtctx->cdictLocal);
         | 
| 1272 1285 | 
             
                    mtctx->cdictLocal = NULL;
         | 
| 1273 1286 | 
             
                    mtctx->cdict = cdict;
         | 
| 1274 1287 | 
             
                }
         | 
| @@ -1334,9 +1347,32 @@ size_t ZSTDMT_initCStream_internal( | |
| 1334 1347 | 
             
                mtctx->allJobsCompleted = 0;
         | 
| 1335 1348 | 
             
                mtctx->consumed = 0;
         | 
| 1336 1349 | 
             
                mtctx->produced = 0;
         | 
| 1350 | 
            +
             | 
| 1351 | 
            +
                /* update dictionary */
         | 
| 1352 | 
            +
                ZSTD_freeCDict(mtctx->cdictLocal);
         | 
| 1353 | 
            +
                mtctx->cdictLocal = NULL;
         | 
| 1354 | 
            +
                mtctx->cdict = NULL;
         | 
| 1355 | 
            +
                if (dict) {
         | 
| 1356 | 
            +
                    if (dictContentType == ZSTD_dct_rawContent) {
         | 
| 1357 | 
            +
                        mtctx->inBuff.prefix.start = (const BYTE*)dict;
         | 
| 1358 | 
            +
                        mtctx->inBuff.prefix.size = dictSize;
         | 
| 1359 | 
            +
                    } else {
         | 
| 1360 | 
            +
                        /* note : a loadPrefix becomes an internal CDict */
         | 
| 1361 | 
            +
                        mtctx->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize,
         | 
| 1362 | 
            +
                                                                    ZSTD_dlm_byRef, dictContentType,
         | 
| 1363 | 
            +
                                                                    params.cParams, mtctx->cMem);
         | 
| 1364 | 
            +
                        mtctx->cdict = mtctx->cdictLocal;
         | 
| 1365 | 
            +
                        if (mtctx->cdictLocal == NULL) return ERROR(memory_allocation);
         | 
| 1366 | 
            +
                    }
         | 
| 1367 | 
            +
                } else {
         | 
| 1368 | 
            +
                    mtctx->cdict = cdict;
         | 
| 1369 | 
            +
                }
         | 
| 1370 | 
            +
             | 
| 1337 1371 | 
             
                if (ZSTDMT_serialState_reset(&mtctx->serial, mtctx->seqPool, params, mtctx->targetSectionSize,
         | 
| 1338 1372 | 
             
                                             dict, dictSize, dictContentType))
         | 
| 1339 1373 | 
             
                    return ERROR(memory_allocation);
         | 
| 1374 | 
            +
             | 
| 1375 | 
            +
             | 
| 1340 1376 | 
             
                return 0;
         | 
| 1341 1377 | 
             
            }
         | 
| 1342 1378 |  | 
| @@ -1403,7 +1439,7 @@ static size_t ZSTDMT_createCompressionJob(ZSTDMT_CCtx* mtctx, size_t srcSize, ZS | |
| 1403 1439 | 
             
                    mtctx->roundBuff.pos += srcSize;
         | 
| 1404 1440 | 
             
                    mtctx->inBuff.buffer = g_nullBuffer;
         | 
| 1405 1441 | 
             
                    mtctx->inBuff.filled = 0;
         | 
| 1406 | 
            -
                    /* Set the prefix */
         | 
| 1442 | 
            +
                    /* Set the prefix for next job */
         | 
| 1407 1443 | 
             
                    if (!endFrame) {
         | 
| 1408 1444 | 
             
                        size_t const newPrefixSize = MIN(srcSize, mtctx->targetPrefixSize);
         | 
| 1409 1445 | 
             
                        mtctx->inBuff.prefix.start = src + srcSize - newPrefixSize;
         | 
| @@ -1540,12 +1576,17 @@ static size_t ZSTDMT_flushProduced(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, u | |
| 1540 1576 | 
             
             * If the data of the first job is broken up into two segments, we cover both
         | 
| 1541 1577 | 
             
             * sections.
         | 
| 1542 1578 | 
             
             */
         | 
| 1543 | 
            -
            static  | 
| 1579 | 
            +
            static Range ZSTDMT_getInputDataInUse(ZSTDMT_CCtx* mtctx)
         | 
| 1544 1580 | 
             
            {
         | 
| 1545 1581 | 
             
                unsigned const firstJobID = mtctx->doneJobID;
         | 
| 1546 1582 | 
             
                unsigned const lastJobID = mtctx->nextJobID;
         | 
| 1547 1583 | 
             
                unsigned jobID;
         | 
| 1548 1584 |  | 
| 1585 | 
            +
                /* no need to check during first round */
         | 
| 1586 | 
            +
                size_t roundBuffCapacity = mtctx->roundBuff.capacity;
         | 
| 1587 | 
            +
                size_t nbJobs1stRoundMin = roundBuffCapacity / mtctx->targetSectionSize;
         | 
| 1588 | 
            +
                if (lastJobID < nbJobs1stRoundMin) return kNullRange;
         | 
| 1589 | 
            +
             | 
| 1549 1590 | 
             
                for (jobID = firstJobID; jobID < lastJobID; ++jobID) {
         | 
| 1550 1591 | 
             
                    unsigned const wJobID = jobID & mtctx->jobIDMask;
         | 
| 1551 1592 | 
             
                    size_t consumed;
         | 
| @@ -1555,7 +1596,7 @@ static range_t ZSTDMT_getInputDataInUse(ZSTDMT_CCtx* mtctx) | |
| 1555 1596 | 
             
                    ZSTD_pthread_mutex_unlock(&mtctx->jobs[wJobID].job_mutex);
         | 
| 1556 1597 |  | 
| 1557 1598 | 
             
                    if (consumed < mtctx->jobs[wJobID].src.size) {
         | 
| 1558 | 
            -
                         | 
| 1599 | 
            +
                        Range range = mtctx->jobs[wJobID].prefix;
         | 
| 1559 1600 | 
             
                        if (range.size == 0) {
         | 
| 1560 1601 | 
             
                            /* Empty prefix */
         | 
| 1561 1602 | 
             
                            range = mtctx->jobs[wJobID].src;
         | 
| @@ -1571,7 +1612,7 @@ static range_t ZSTDMT_getInputDataInUse(ZSTDMT_CCtx* mtctx) | |
| 1571 1612 | 
             
            /**
         | 
| 1572 1613 | 
             
             * Returns non-zero iff buffer and range overlap.
         | 
| 1573 1614 | 
             
             */
         | 
| 1574 | 
            -
            static int ZSTDMT_isOverlapped( | 
| 1615 | 
            +
            static int ZSTDMT_isOverlapped(Buffer buffer, Range range)
         | 
| 1575 1616 | 
             
            {
         | 
| 1576 1617 | 
             
                BYTE const* const bufferStart = (BYTE const*)buffer.start;
         | 
| 1577 1618 | 
             
                BYTE const* const rangeStart = (BYTE const*)range.start;
         | 
| @@ -1591,10 +1632,10 @@ static int ZSTDMT_isOverlapped(buffer_t buffer, range_t range) | |
| 1591 1632 | 
             
                }
         | 
| 1592 1633 | 
             
            }
         | 
| 1593 1634 |  | 
| 1594 | 
            -
            static int ZSTDMT_doesOverlapWindow( | 
| 1635 | 
            +
            static int ZSTDMT_doesOverlapWindow(Buffer buffer, ZSTD_window_t window)
         | 
| 1595 1636 | 
             
            {
         | 
| 1596 | 
            -
                 | 
| 1597 | 
            -
                 | 
| 1637 | 
            +
                Range extDict;
         | 
| 1638 | 
            +
                Range prefix;
         | 
| 1598 1639 |  | 
| 1599 1640 | 
             
                DEBUGLOG(5, "ZSTDMT_doesOverlapWindow");
         | 
| 1600 1641 | 
             
                extDict.start = window.dictBase + window.lowLimit;
         | 
| @@ -1613,7 +1654,7 @@ static int ZSTDMT_doesOverlapWindow(buffer_t buffer, ZSTD_window_t window) | |
| 1613 1654 | 
             
                    || ZSTDMT_isOverlapped(buffer, prefix);
         | 
| 1614 1655 | 
             
            }
         | 
| 1615 1656 |  | 
| 1616 | 
            -
            static void ZSTDMT_waitForLdmComplete(ZSTDMT_CCtx* mtctx,  | 
| 1657 | 
            +
            static void ZSTDMT_waitForLdmComplete(ZSTDMT_CCtx* mtctx, Buffer buffer)
         | 
| 1617 1658 | 
             
            {
         | 
| 1618 1659 | 
             
                if (mtctx->params.ldmParams.enableLdm == ZSTD_ps_enable) {
         | 
| 1619 1660 | 
             
                    ZSTD_pthread_mutex_t* mutex = &mtctx->serial.ldmWindowMutex;
         | 
| @@ -1638,16 +1679,16 @@ static void ZSTDMT_waitForLdmComplete(ZSTDMT_CCtx* mtctx, buffer_t buffer) | |
| 1638 1679 | 
             
             */
         | 
| 1639 1680 | 
             
            static int ZSTDMT_tryGetInputRange(ZSTDMT_CCtx* mtctx)
         | 
| 1640 1681 | 
             
            {
         | 
| 1641 | 
            -
                 | 
| 1682 | 
            +
                Range const inUse = ZSTDMT_getInputDataInUse(mtctx);
         | 
| 1642 1683 | 
             
                size_t const spaceLeft = mtctx->roundBuff.capacity - mtctx->roundBuff.pos;
         | 
| 1643 | 
            -
                size_t const  | 
| 1644 | 
            -
                 | 
| 1684 | 
            +
                size_t const spaceNeeded = mtctx->targetSectionSize;
         | 
| 1685 | 
            +
                Buffer buffer;
         | 
| 1645 1686 |  | 
| 1646 1687 | 
             
                DEBUGLOG(5, "ZSTDMT_tryGetInputRange");
         | 
| 1647 1688 | 
             
                assert(mtctx->inBuff.buffer.start == NULL);
         | 
| 1648 | 
            -
                assert(mtctx->roundBuff.capacity >=  | 
| 1689 | 
            +
                assert(mtctx->roundBuff.capacity >= spaceNeeded);
         | 
| 1649 1690 |  | 
| 1650 | 
            -
                if (spaceLeft <  | 
| 1691 | 
            +
                if (spaceLeft < spaceNeeded) {
         | 
| 1651 1692 | 
             
                    /* ZSTD_invalidateRepCodes() doesn't work for extDict variants.
         | 
| 1652 1693 | 
             
                     * Simply copy the prefix to the beginning in that case.
         | 
| 1653 1694 | 
             
                     */
         | 
| @@ -1666,7 +1707,7 @@ static int ZSTDMT_tryGetInputRange(ZSTDMT_CCtx* mtctx) | |
| 1666 1707 | 
             
                    mtctx->roundBuff.pos = prefixSize;
         | 
| 1667 1708 | 
             
                }
         | 
| 1668 1709 | 
             
                buffer.start = mtctx->roundBuff.buffer + mtctx->roundBuff.pos;
         | 
| 1669 | 
            -
                buffer.capacity =  | 
| 1710 | 
            +
                buffer.capacity = spaceNeeded;
         | 
| 1670 1711 |  | 
| 1671 1712 | 
             
                if (ZSTDMT_isOverlapped(buffer, inUse)) {
         | 
| 1672 1713 | 
             
                    DEBUGLOG(5, "Waiting for buffer...");
         | 
| @@ -1693,7 +1734,7 @@ static int ZSTDMT_tryGetInputRange(ZSTDMT_CCtx* mtctx) | |
| 1693 1734 | 
             
            typedef struct {
         | 
| 1694 1735 | 
             
              size_t toLoad;  /* The number of bytes to load from the input. */
         | 
| 1695 1736 | 
             
              int flush;      /* Boolean declaring if we must flush because we found a synchronization point. */
         | 
| 1696 | 
            -
            }  | 
| 1737 | 
            +
            } SyncPoint;
         | 
| 1697 1738 |  | 
| 1698 1739 | 
             
            /**
         | 
| 1699 1740 | 
             
             * Searches through the input for a synchronization point. If one is found, we
         | 
| @@ -1701,14 +1742,14 @@ typedef struct { | |
| 1701 1742 | 
             
             * Otherwise, we will load as many bytes as possible and instruct the caller
         | 
| 1702 1743 | 
             
             * to continue as normal.
         | 
| 1703 1744 | 
             
             */
         | 
| 1704 | 
            -
            static  | 
| 1745 | 
            +
            static SyncPoint
         | 
| 1705 1746 | 
             
            findSynchronizationPoint(ZSTDMT_CCtx const* mtctx, ZSTD_inBuffer const input)
         | 
| 1706 1747 | 
             
            {
         | 
| 1707 1748 | 
             
                BYTE const* const istart = (BYTE const*)input.src + input.pos;
         | 
| 1708 1749 | 
             
                U64 const primePower = mtctx->rsync.primePower;
         | 
| 1709 1750 | 
             
                U64 const hitMask = mtctx->rsync.hitMask;
         | 
| 1710 1751 |  | 
| 1711 | 
            -
                 | 
| 1752 | 
            +
                SyncPoint syncPoint;
         | 
| 1712 1753 | 
             
                U64 hash;
         | 
| 1713 1754 | 
             
                BYTE const* prev;
         | 
| 1714 1755 | 
             
                size_t pos;
         | 
| @@ -1840,7 +1881,7 @@ size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, | |
| 1840 1881 | 
             
                            DEBUGLOG(5, "ZSTDMT_tryGetInputRange completed successfully : mtctx->inBuff.buffer.start = %p", mtctx->inBuff.buffer.start);
         | 
| 1841 1882 | 
             
                    }
         | 
| 1842 1883 | 
             
                    if (mtctx->inBuff.buffer.start != NULL) {
         | 
| 1843 | 
            -
                         | 
| 1884 | 
            +
                        SyncPoint const syncPoint = findSynchronizationPoint(mtctx, *input);
         | 
| 1844 1885 | 
             
                        if (syncPoint.flush && endOp == ZSTD_e_continue) {
         | 
| 1845 1886 | 
             
                            endOp = ZSTD_e_flush;
         | 
| 1846 1887 | 
             
                        }
         | 
| @@ -11,10 +11,10 @@ | |
| 11 11 | 
             
             #ifndef ZSTDMT_COMPRESS_H
         | 
| 12 12 | 
             
             #define ZSTDMT_COMPRESS_H
         | 
| 13 13 |  | 
| 14 | 
            -
              | 
| 15 | 
            -
              | 
| 16 | 
            -
              | 
| 17 | 
            -
             | 
| 14 | 
            +
            /* ===   Dependencies   === */
         | 
| 15 | 
            +
            #include "../common/zstd_deps.h"   /* size_t */
         | 
| 16 | 
            +
            #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_parameters */
         | 
| 17 | 
            +
            #include "../zstd.h"            /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
         | 
| 18 18 |  | 
| 19 19 | 
             
            /* Note : This is an internal API.
         | 
| 20 20 | 
             
             *        These APIs used to be exposed with ZSTDLIB_API,
         | 
| @@ -25,12 +25,6 @@ | |
| 25 25 | 
             
             *        otherwise ZSTDMT_createCCtx*() will fail.
         | 
| 26 26 | 
             
             */
         | 
| 27 27 |  | 
| 28 | 
            -
            /* ===   Dependencies   === */
         | 
| 29 | 
            -
            #include "../common/zstd_deps.h"   /* size_t */
         | 
| 30 | 
            -
            #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_parameters */
         | 
| 31 | 
            -
            #include "../zstd.h"            /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
         | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 28 | 
             
            /* ===   Constants   === */
         | 
| 35 29 | 
             
            #ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */
         | 
| 36 30 | 
             
            #  define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256)
         | 
| @@ -105,9 +99,4 @@ void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_p | |
| 105 99 | 
             
             */
         | 
| 106 100 | 
             
            ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);
         | 
| 107 101 |  | 
| 108 | 
            -
             | 
| 109 | 
            -
            #if defined (__cplusplus)
         | 
| 110 | 
            -
            }
         | 
| 111 | 
            -
            #endif
         | 
| 112 | 
            -
             | 
| 113 102 | 
             
            #endif   /* ZSTDMT_COMPRESS_H */
         | 
| @@ -42,13 +42,11 @@ | |
| 42 42 |  | 
| 43 43 | 
             
            /* Calling convention:
         | 
| 44 44 | 
             
             *
         | 
| 45 | 
            -
             * %rdi contains the first argument: HUF_DecompressAsmArgs*.
         | 
| 45 | 
            +
             * %rdi (or %rcx on Windows) contains the first argument: HUF_DecompressAsmArgs*.
         | 
| 46 46 | 
             
             * %rbp isn't maintained (no frame pointer).
         | 
| 47 47 | 
             
             * %rsp contains the stack pointer that grows down.
         | 
| 48 48 | 
             
             *      No red-zone is assumed, only addresses >= %rsp are used.
         | 
| 49 49 | 
             
             * All register contents are preserved.
         | 
| 50 | 
            -
             *
         | 
| 51 | 
            -
             * TODO: Support Windows calling convention.
         | 
| 52 50 | 
             
             */
         | 
| 53 51 |  | 
| 54 52 | 
             
            ZSTD_HIDE_ASM_FUNCTION(HUF_decompress4X1_usingDTable_internal_fast_asm_loop)
         | 
| @@ -137,7 +135,11 @@ HUF_decompress4X1_usingDTable_internal_fast_asm_loop: | |
| 137 135 | 
             
                push %r15
         | 
| 138 136 |  | 
| 139 137 | 
             
                /* Read HUF_DecompressAsmArgs* args from %rax */
         | 
| 138 | 
            +
            #if defined(_WIN32)
         | 
| 139 | 
            +
                movq %rcx, %rax
         | 
| 140 | 
            +
            #else
         | 
| 140 141 | 
             
                movq %rdi, %rax
         | 
| 142 | 
            +
            #endif
         | 
| 141 143 | 
             
                movq  0(%rax), %ip0
         | 
| 142 144 | 
             
                movq  8(%rax), %ip1
         | 
| 143 145 | 
             
                movq 16(%rax), %ip2
         | 
| @@ -391,7 +393,12 @@ HUF_decompress4X2_usingDTable_internal_fast_asm_loop: | |
| 391 393 | 
             
                push %r14
         | 
| 392 394 | 
             
                push %r15
         | 
| 393 395 |  | 
| 396 | 
            +
                /* Read HUF_DecompressAsmArgs* args from %rax */
         | 
| 397 | 
            +
            #if defined(_WIN32)
         | 
| 398 | 
            +
                movq %rcx, %rax
         | 
| 399 | 
            +
            #else
         | 
| 394 400 | 
             
                movq %rdi, %rax
         | 
| 401 | 
            +
            #endif
         | 
| 395 402 | 
             
                movq  0(%rax), %ip0
         | 
| 396 403 | 
             
                movq  8(%rax), %ip1
         | 
| 397 404 | 
             
                movq 16(%rax), %ip2
         |