zstd-ruby 1.3.2.0 → 1.3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/zstdruby/libzstd/BUCK +31 -10
  4. data/ext/zstdruby/libzstd/common/bitstream.h +1 -1
  5. data/ext/zstdruby/libzstd/common/mem.h +15 -13
  6. data/ext/zstdruby/libzstd/common/pool.c +1 -2
  7. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -4
  8. data/ext/zstdruby/libzstd/common/zstd_internal.h +52 -170
  9. data/ext/zstdruby/libzstd/compress/zstd_compress.c +434 -337
  10. data/ext/zstdruby/libzstd/compress/{zstd_compress.h → zstd_compress_internal.h} +191 -36
  11. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +1 -0
  12. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +3 -2
  13. data/ext/zstdruby/libzstd/compress/zstd_fast.c +1 -0
  14. data/ext/zstdruby/libzstd/compress/zstd_fast.h +3 -2
  15. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +66 -50
  16. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +3 -2
  17. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +3 -2
  18. data/ext/zstdruby/libzstd/compress/zstd_opt.c +504 -676
  19. data/ext/zstdruby/libzstd/compress/zstd_opt.h +2 -2
  20. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +130 -80
  21. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +15 -7
  22. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +41 -31
  23. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -0
  24. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +1 -1
  25. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +1 -1
  26. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +1 -74
  27. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +1 -74
  28. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +1 -72
  29. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +1 -73
  30. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +1 -77
  31. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +1 -77
  32. data/ext/zstdruby/libzstd/zstd.h +43 -30
  33. data/lib/zstd-ruby/version.rb +1 -1
  34. metadata +4 -4
@@ -827,9 +827,9 @@ typedef struct {
827
827
  FSE_DState_t stateOffb;
828
828
  FSE_DState_t stateML;
829
829
  size_t prevOffset[ZSTD_REP_NUM];
830
- const BYTE* base;
830
+ const BYTE* prefixStart;
831
+ const BYTE* dictEnd;
831
832
  size_t pos;
832
- uPtrDiff gotoDict;
833
833
  } seqState_t;
834
834
 
835
835
 
@@ -1224,8 +1224,9 @@ seq_t ZSTD_decodeSequenceLong(seqState_t* seqState, ZSTD_longOffset_e const long
1224
1224
  BIT_reloadDStream(&seqState->DStream);
1225
1225
 
1226
1226
  { size_t const pos = seqState->pos + seq.litLength;
1227
- seq.match = seqState->base + pos - seq.offset; /* single memory segment */
1228
- if (seq.offset > pos) seq.match += seqState->gotoDict; /* separate memory segment */
1227
+ const BYTE* const matchBase = (seq.offset > pos) ? seqState->dictEnd : seqState->prefixStart;
1228
+ seq.match = matchBase + pos - seq.offset; /* note : this operation can overflow when seq.offset is really too large, which can only happen when input is corrupted.
1229
+ * No consequence though : no memory access will occur, overly large offset will be detected in ZSTD_execSequenceLong() */
1229
1230
  seqState->pos = pos + seq.matchLength;
1230
1231
  }
1231
1232
 
@@ -1243,7 +1244,7 @@ HINT_INLINE
1243
1244
  size_t ZSTD_execSequenceLong(BYTE* op,
1244
1245
  BYTE* const oend, seq_t sequence,
1245
1246
  const BYTE** litPtr, const BYTE* const litLimit,
1246
- const BYTE* const base, const BYTE* const vBase, const BYTE* const dictEnd)
1247
+ const BYTE* const prefixStart, const BYTE* const dictStart, const BYTE* const dictEnd)
1247
1248
  {
1248
1249
  BYTE* const oLitEnd = op + sequence.litLength;
1249
1250
  size_t const sequenceLength = sequence.litLength + sequence.matchLength;
@@ -1253,21 +1254,21 @@ size_t ZSTD_execSequenceLong(BYTE* op,
1253
1254
  const BYTE* match = sequence.match;
1254
1255
 
1255
1256
  /* check */
1256
- if (oMatchEnd>oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
1257
+ if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
1257
1258
  if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
1258
- if (oLitEnd>oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, base, vBase, dictEnd);
1259
+ if (oLitEnd > oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, dictStart, dictEnd);
1259
1260
 
1260
1261
  /* copy Literals */
1261
- ZSTD_copy8(op, *litPtr);
1262
+ ZSTD_copy8(op, *litPtr); /* note : op <= oLitEnd <= oend_w == oend - 8 */
1262
1263
  if (sequence.litLength > 8)
1263
1264
  ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
1264
1265
  op = oLitEnd;
1265
1266
  *litPtr = iLitEnd; /* update for next sequence */
1266
1267
 
1267
1268
  /* copy Match */
1268
- if (sequence.offset > (size_t)(oLitEnd - base)) {
1269
+ if (sequence.offset > (size_t)(oLitEnd - prefixStart)) {
1269
1270
  /* offset beyond prefix */
1270
- if (sequence.offset > (size_t)(oLitEnd - vBase)) return ERROR(corruption_detected);
1271
+ if (sequence.offset > (size_t)(oLitEnd - dictStart)) return ERROR(corruption_detected);
1271
1272
  if (match + sequence.matchLength <= dictEnd) {
1272
1273
  memmove(oLitEnd, match, sequence.matchLength);
1273
1274
  return sequenceLength;
@@ -1277,7 +1278,7 @@ size_t ZSTD_execSequenceLong(BYTE* op,
1277
1278
  memmove(oLitEnd, match, length1);
1278
1279
  op = oLitEnd + length1;
1279
1280
  sequence.matchLength -= length1;
1280
- match = base;
1281
+ match = prefixStart;
1281
1282
  if (op > oend_w || sequence.matchLength < MINMATCH) {
1282
1283
  U32 i;
1283
1284
  for (i = 0; i < sequence.matchLength; ++i) op[i] = match[i];
@@ -1331,8 +1332,8 @@ static size_t ZSTD_decompressSequencesLong(
1331
1332
  BYTE* op = ostart;
1332
1333
  const BYTE* litPtr = dctx->litPtr;
1333
1334
  const BYTE* const litEnd = litPtr + dctx->litSize;
1334
- const BYTE* const base = (const BYTE*) (dctx->base);
1335
- const BYTE* const vBase = (const BYTE*) (dctx->vBase);
1335
+ const BYTE* const prefixStart = (const BYTE*) (dctx->base);
1336
+ const BYTE* const dictStart = (const BYTE*) (dctx->vBase);
1336
1337
  const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd);
1337
1338
  int nbSeq;
1338
1339
 
@@ -1353,9 +1354,9 @@ static size_t ZSTD_decompressSequencesLong(
1353
1354
  int seqNb;
1354
1355
  dctx->fseEntropy = 1;
1355
1356
  { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) seqState.prevOffset[i] = dctx->entropy.rep[i]; }
1356
- seqState.base = base;
1357
- seqState.pos = (size_t)(op-base);
1358
- seqState.gotoDict = (uPtrDiff)dictEnd - (uPtrDiff)base; /* cast to avoid undefined behaviour */
1357
+ seqState.prefixStart = prefixStart;
1358
+ seqState.pos = (size_t)(op-prefixStart);
1359
+ seqState.dictEnd = dictEnd;
1359
1360
  CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected);
1360
1361
  FSE_initDState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr);
1361
1362
  FSE_initDState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr);
@@ -1370,9 +1371,9 @@ static size_t ZSTD_decompressSequencesLong(
1370
1371
  /* decode and decompress */
1371
1372
  for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && seqNb<nbSeq ; seqNb++) {
1372
1373
  seq_t const sequence = ZSTD_decodeSequenceLong(&seqState, isLongOffset);
1373
- size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[(seqNb-ADVANCED_SEQS) & STOSEQ_MASK], &litPtr, litEnd, base, vBase, dictEnd);
1374
+ size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[(seqNb-ADVANCED_SEQS) & STOSEQ_MASK], &litPtr, litEnd, prefixStart, dictStart, dictEnd);
1374
1375
  if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1375
- PREFETCH(sequence.match);
1376
+ PREFETCH(sequence.match); /* note : it's safe to invoke PREFETCH() on any memory address, including invalid ones */
1376
1377
  sequences[seqNb&STOSEQ_MASK] = sequence;
1377
1378
  op += oneSeqSize;
1378
1379
  }
@@ -1381,7 +1382,7 @@ static size_t ZSTD_decompressSequencesLong(
1381
1382
  /* finish queue */
1382
1383
  seqNb -= seqAdvance;
1383
1384
  for ( ; seqNb<nbSeq ; seqNb++) {
1384
- size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[seqNb&STOSEQ_MASK], &litPtr, litEnd, base, vBase, dictEnd);
1385
+ size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[seqNb&STOSEQ_MASK], &litPtr, litEnd, prefixStart, dictStart, dictEnd);
1385
1386
  if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1386
1387
  op += oneSeqSize;
1387
1388
  }
@@ -2450,14 +2451,16 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2450
2451
  return ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion, output, input);
2451
2452
  }
2452
2453
  #endif
2453
- return hSize; /* error */
2454
+ return hSize; /* error */
2454
2455
  }
2455
2456
  if (hSize != 0) { /* need more input */
2456
2457
  size_t const toLoad = hSize - zds->lhSize; /* if hSize!=0, hSize > zds->lhSize */
2457
- if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
2458
- if (iend-ip > 0) {
2459
- memcpy(zds->headerBuffer + zds->lhSize, ip, iend-ip);
2460
- zds->lhSize += iend-ip;
2458
+ size_t const remainingInput = (size_t)(iend-ip);
2459
+ assert(iend >= ip);
2460
+ if (toLoad > remainingInput) { /* not enough input to load full header */
2461
+ if (remainingInput > 0) {
2462
+ memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput);
2463
+ zds->lhSize += remainingInput;
2461
2464
  }
2462
2465
  input->pos = input->size;
2463
2466
  return (MAX(ZSTD_frameHeaderSize_min, hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */
@@ -2472,8 +2475,10 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2472
2475
  && (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
2473
2476
  size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
2474
2477
  if (cSize <= (size_t)(iend-istart)) {
2478
+ /* shortcut : using single-pass mode */
2475
2479
  size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, zds->ddict);
2476
2480
  if (ZSTD_isError(decompressedSize)) return decompressedSize;
2481
+ DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()")
2477
2482
  ip = istart + cSize;
2478
2483
  op += decompressedSize;
2479
2484
  zds->expected = 0;
@@ -2496,8 +2501,9 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2496
2501
  }
2497
2502
 
2498
2503
  /* control buffer memory usage */
2499
- DEBUGLOG(4, "Control max buffer memory usage (max %u KB)",
2500
- (U32)(zds->maxWindowSize >> 10));
2504
+ DEBUGLOG(4, "Control max memory usage (%u KB <= max %u KB)",
2505
+ (U32)(zds->fParams.windowSize >>10),
2506
+ (U32)(zds->maxWindowSize >> 10) );
2501
2507
  zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
2502
2508
  if (zds->fParams.windowSize > zds->maxWindowSize) return ERROR(frameParameter_windowTooLarge);
2503
2509
 
@@ -2555,17 +2561,21 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2555
2561
  /* fall-through */
2556
2562
  case zdss_load:
2557
2563
  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
2558
- size_t const toLoad = neededInSize - zds->inPos; /* should always be <= remaining space within inBuff */
2564
+ size_t const toLoad = neededInSize - zds->inPos;
2565
+ int const isSkipFrame = ZSTD_isSkipFrame(zds);
2559
2566
  size_t loadedSize;
2560
- if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
2561
- loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
2567
+ if (isSkipFrame) {
2568
+ loadedSize = MIN(toLoad, (size_t)(iend-ip));
2569
+ } else {
2570
+ if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
2571
+ loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
2572
+ }
2562
2573
  ip += loadedSize;
2563
2574
  zds->inPos += loadedSize;
2564
2575
  if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
2565
2576
 
2566
2577
  /* decode loaded input */
2567
- { const int isSkipFrame = ZSTD_isSkipFrame(zds);
2568
- size_t const decodedSize = ZSTD_decompressContinue(zds,
2578
+ { size_t const decodedSize = ZSTD_decompressContinue(zds,
2569
2579
  zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart,
2570
2580
  zds->inBuff, neededInSize);
2571
2581
  if (ZSTD_isError(decodedSize)) return decodedSize;
@@ -72,6 +72,7 @@ size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
72
72
  const void* dict, size_t dictSize,
73
73
  ZSTD_parameters params, unsigned long long pledgedSrcSize)
74
74
  {
75
+ if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* preserve "0 == unknown" behavior */
75
76
  return ZSTD_initCStream_advanced(zbc, dict, dictSize, params, pledgedSrcSize);
76
77
  }
77
78
 
@@ -103,7 +103,7 @@ unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize)
103
103
  /*-********************************************************
104
104
  * Dictionary training functions
105
105
  **********************************************************/
106
- static unsigned ZDICT_NbCommonBytes (register size_t val)
106
+ static unsigned ZDICT_NbCommonBytes (size_t val)
107
107
  {
108
108
  if (MEM_isLittleEndian()) {
109
109
  if (MEM_64bits()) {
@@ -339,7 +339,7 @@ typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
339
339
  /****************************************************************
340
340
  * Internal functions
341
341
  ****************************************************************/
342
- FORCE_INLINE unsigned FSE_highbit32 (register U32 val)
342
+ FORCE_INLINE unsigned FSE_highbit32 (U32 val)
343
343
  {
344
344
  # if defined(_MSC_VER) /* Visual */
345
345
  unsigned long r;
@@ -330,18 +330,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
330
330
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
331
331
 
332
332
 
333
- /*
334
- * Start by invoking BIT_initDStream().
335
- * A chunk of the bitStream is then stored into a local register.
336
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
337
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
338
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
339
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
340
- * Otherwise, it can be less than that, so proceed accordingly.
341
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
342
- */
343
-
344
-
345
333
  /******************************************
346
334
  * unsafe API
347
335
  ******************************************/
@@ -353,7 +341,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
353
341
  /****************************************************************
354
342
  * Helper functions
355
343
  ****************************************************************/
356
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
344
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
357
345
  {
358
346
  # if defined(_MSC_VER) /* Visual */
359
347
  unsigned long r=0;
@@ -427,13 +415,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
427
415
  return srcSize;
428
416
  }
429
417
 
430
- /*!BIT_lookBits
431
- * Provides next n bits from local register
432
- * local register is not modified (bits are still present for next read/look)
433
- * On 32-bits, maxNbBits==25
434
- * On 64-bits, maxNbBits==57
435
- * @return : value extracted
436
- */
437
418
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
438
419
  {
439
420
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -453,11 +434,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
453
434
  bitD->bitsConsumed += nbBits;
454
435
  }
455
436
 
456
- /*!BIT_readBits
457
- * Read next n bits from local register.
458
- * pay attention to not read more than nbBits contained into local register.
459
- * @return : extracted value.
460
- */
461
437
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
462
438
  {
463
439
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -695,55 +671,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
695
671
 
696
672
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
697
673
 
698
- /*
699
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
700
- You will decode FSE-encoded symbols from the bitStream,
701
- and also any other bitFields you put in, **in reverse order**.
702
-
703
- You will need a few variables to track your bitStream. They are :
704
-
705
- BIT_DStream_t DStream; // Stream context
706
- FSE_DState_t DState; // State context. Multiple ones are possible
707
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
708
-
709
- The first thing to do is to init the bitStream.
710
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
711
-
712
- You should then retrieve your initial state(s)
713
- (in reverse flushing order if you have several ones) :
714
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
715
-
716
- You can then decode your data, symbol after symbol.
717
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
718
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
719
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
720
-
721
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
722
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
723
- size_t bitField = BIT_readBits(&DStream, nbBits);
724
-
725
- All above operations only read from local register (which size depends on size_t).
726
- Refueling the register from memory is manually performed by the reload method.
727
- endSignal = FSE_reloadDStream(&DStream);
728
-
729
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
730
- BIT_DStream_unfinished : there is still some data left into the DStream.
731
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
732
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
733
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
734
-
735
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
736
- to properly detect the exact end of stream.
737
- After each decoded symbol, check if DStream is fully consumed using this simple test :
738
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
739
-
740
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
741
- Checking if DStream has reached its end is performed by :
742
- BIT_endOfDStream(&DStream);
743
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
744
- FSE_endOfDState(&DState);
745
- */
746
-
747
674
 
748
675
  /******************************************
749
676
  * FSE unsafe API
@@ -332,17 +332,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
332
332
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
333
333
 
334
334
 
335
- /*
336
- * Start by invoking BIT_initDStream().
337
- * A chunk of the bitStream is then stored into a local register.
338
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
339
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
340
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
341
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
342
- * Otherwise, it can be less than that, so proceed accordingly.
343
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
344
- */
345
-
346
335
 
347
336
  /******************************************
348
337
  * unsafe API
@@ -355,7 +344,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
355
344
  /****************************************************************
356
345
  * Helper functions
357
346
  ****************************************************************/
358
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
347
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
359
348
  {
360
349
  # if defined(_MSC_VER) /* Visual */
361
350
  unsigned long r=0;
@@ -428,14 +417,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
428
417
 
429
418
  return srcSize;
430
419
  }
431
-
432
- /*!BIT_lookBits
433
- * Provides next n bits from local register
434
- * local register is not modified (bits are still present for next read/look)
435
- * On 32-bits, maxNbBits==25
436
- * On 64-bits, maxNbBits==57
437
- * @return : value extracted
438
- */
439
420
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
440
421
  {
441
422
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -455,11 +436,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
455
436
  bitD->bitsConsumed += nbBits;
456
437
  }
457
438
 
458
- /*!BIT_readBits
459
- * Read next n bits from local register.
460
- * pay attention to not read more than nbBits contained into local register.
461
- * @return : extracted value.
462
- */
463
439
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
464
440
  {
465
441
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -697,55 +673,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
697
673
 
698
674
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
699
675
 
700
- /*
701
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
702
- You will decode FSE-encoded symbols from the bitStream,
703
- and also any other bitFields you put in, **in reverse order**.
704
-
705
- You will need a few variables to track your bitStream. They are :
706
-
707
- BIT_DStream_t DStream; // Stream context
708
- FSE_DState_t DState; // State context. Multiple ones are possible
709
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
710
-
711
- The first thing to do is to init the bitStream.
712
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
713
-
714
- You should then retrieve your initial state(s)
715
- (in reverse flushing order if you have several ones) :
716
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
717
-
718
- You can then decode your data, symbol after symbol.
719
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
720
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
721
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
722
-
723
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
724
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
725
- size_t bitField = BIT_readBits(&DStream, nbBits);
726
-
727
- All above operations only read from local register (which size depends on size_t).
728
- Refueling the register from memory is manually performed by the reload method.
729
- endSignal = FSE_reloadDStream(&DStream);
730
-
731
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
732
- BIT_DStream_unfinished : there is still some data left into the DStream.
733
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
734
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
735
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
736
-
737
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
738
- to properly detect the exact end of stream.
739
- After each decoded symbol, check if DStream is fully consumed using this simple test :
740
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
741
-
742
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
743
- Checking if DStream has reached its end is performed by :
744
- BIT_endOfDStream(&DStream);
745
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
746
- FSE_endOfDState(&DState);
747
- */
748
-
749
676
 
750
677
  /******************************************
751
678
  * FSE unsafe API
@@ -738,16 +738,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
738
738
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
739
739
 
740
740
 
741
- /*
742
- * Start by invoking BIT_initDStream().
743
- * A chunk of the bitStream is then stored into a local register.
744
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
745
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
746
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
747
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
748
- * Otherwise, it can be less than that, so proceed accordingly.
749
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
750
- */
751
741
 
752
742
 
753
743
  /******************************************
@@ -761,7 +751,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
761
751
  /****************************************************************
762
752
  * Helper functions
763
753
  ****************************************************************/
764
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
754
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
765
755
  {
766
756
  # if defined(_MSC_VER) /* Visual */
767
757
  unsigned long r=0;
@@ -834,13 +824,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
834
824
  return srcSize;
835
825
  }
836
826
 
837
- /*!BIT_lookBits
838
- * Provides next n bits from local register
839
- * local register is not modified (bits are still present for next read/look)
840
- * On 32-bits, maxNbBits==25
841
- * On 64-bits, maxNbBits==57
842
- * @return : value extracted
843
- */
844
827
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
845
828
  {
846
829
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -860,11 +843,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
860
843
  bitD->bitsConsumed += nbBits;
861
844
  }
862
845
 
863
- /*!BIT_readBits
864
- * Read next n bits from local register.
865
- * pay attention to not read more than nbBits contained into local register.
866
- * @return : extracted value.
867
- */
868
846
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
869
847
  {
870
848
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -1011,55 +989,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
1011
989
 
1012
990
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
1013
991
 
1014
- /*!
1015
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
1016
- You will decode FSE-encoded symbols from the bitStream,
1017
- and also any other bitFields you put in, **in reverse order**.
1018
-
1019
- You will need a few variables to track your bitStream. They are :
1020
-
1021
- BIT_DStream_t DStream; // Stream context
1022
- FSE_DState_t DState; // State context. Multiple ones are possible
1023
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
1024
-
1025
- The first thing to do is to init the bitStream.
1026
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
1027
-
1028
- You should then retrieve your initial state(s)
1029
- (in reverse flushing order if you have several ones) :
1030
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
1031
-
1032
- You can then decode your data, symbol after symbol.
1033
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
1034
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
1035
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
1036
-
1037
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
1038
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
1039
- size_t bitField = BIT_readBits(&DStream, nbBits);
1040
-
1041
- All above operations only read from local register (which size depends on size_t).
1042
- Refueling the register from memory is manually performed by the reload method.
1043
- endSignal = FSE_reloadDStream(&DStream);
1044
-
1045
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
1046
- BIT_DStream_unfinished : there is still some data left into the DStream.
1047
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
1048
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
1049
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
1050
-
1051
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
1052
- to properly detect the exact end of stream.
1053
- After each decoded symbol, check if DStream is fully consumed using this simple test :
1054
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
1055
-
1056
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
1057
- Checking if DStream has reached its end is performed by :
1058
- BIT_endOfDStream(&DStream);
1059
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
1060
- FSE_endOfDState(&DState);
1061
- */
1062
-
1063
992
 
1064
993
  /* *****************************************
1065
994
  * FSE unsafe API
@@ -736,18 +736,6 @@ MEM_STATIC BITv05_DStream_status BITv05_reloadDStream(BITv05_DStream_t* bitD);
736
736
  MEM_STATIC unsigned BITv05_endOfDStream(const BITv05_DStream_t* bitD);
737
737
 
738
738
 
739
- /*!
740
- * Start by invoking BITv05_initDStream().
741
- * A chunk of the bitStream is then stored into a local register.
742
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
743
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
744
- * Local register is explicitly reloaded from memory by the BITv05_reloadDStream() method.
745
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BITv05_DStream_unfinished.
746
- * Otherwise, it can be less than that, so proceed accordingly.
747
- * Checking if DStream has reached its end can be performed with BITv05_endOfDStream()
748
- */
749
-
750
-
751
739
  /*-****************************************
752
740
  * unsafe API
753
741
  ******************************************/
@@ -759,7 +747,7 @@ MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits);
759
747
  /*-**************************************************************
760
748
  * Helper functions
761
749
  ****************************************************************/
762
- MEM_STATIC unsigned BITv05_highbit32 (register U32 val)
750
+ MEM_STATIC unsigned BITv05_highbit32 (U32 val)
763
751
  {
764
752
  # if defined(_MSC_VER) /* Visual */
765
753
  unsigned long r=0;
@@ -829,13 +817,6 @@ MEM_STATIC size_t BITv05_initDStream(BITv05_DStream_t* bitD, const void* srcBuff
829
817
  return srcSize;
830
818
  }
831
819
 
832
- /*!BITv05_lookBits
833
- * Provides next n bits from local register
834
- * local register is not modified (bits are still present for next read/look)
835
- * On 32-bits, maxNbBits==25
836
- * On 64-bits, maxNbBits==57
837
- * @return : value extracted
838
- */
839
820
  MEM_STATIC size_t BITv05_lookBits(BITv05_DStream_t* bitD, U32 nbBits)
840
821
  {
841
822
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -855,11 +836,6 @@ MEM_STATIC void BITv05_skipBits(BITv05_DStream_t* bitD, U32 nbBits)
855
836
  bitD->bitsConsumed += nbBits;
856
837
  }
857
838
 
858
- /*!BITv05_readBits
859
- * Read next n bits from local register.
860
- * pay attention to not read more than nbBits contained into local register.
861
- * @return : extracted value.
862
- */
863
839
  MEM_STATIC size_t BITv05_readBits(BITv05_DStream_t* bitD, U32 nbBits)
864
840
  {
865
841
  size_t value = BITv05_lookBits(bitD, nbBits);
@@ -995,54 +971,6 @@ static unsigned char FSEv05_decodeSymbol(FSEv05_DState_t* DStatePtr, BITv05_DStr
995
971
 
996
972
  static unsigned FSEv05_endOfDState(const FSEv05_DState_t* DStatePtr);
997
973
 
998
- /*!
999
- Let's now decompose FSEv05_decompress_usingDTable() into its unitary components.
1000
- You will decode FSEv05-encoded symbols from the bitStream,
1001
- and also any other bitFields you put in, **in reverse order**.
1002
-
1003
- You will need a few variables to track your bitStream. They are :
1004
-
1005
- BITv05_DStream_t DStream; // Stream context
1006
- FSEv05_DState_t DState; // State context. Multiple ones are possible
1007
- FSEv05_DTable* DTablePtr; // Decoding table, provided by FSEv05_buildDTable()
1008
-
1009
- The first thing to do is to init the bitStream.
1010
- errorCode = BITv05_initDStream(&DStream, srcBuffer, srcSize);
1011
-
1012
- You should then retrieve your initial state(s)
1013
- (in reverse flushing order if you have several ones) :
1014
- errorCode = FSEv05_initDState(&DState, &DStream, DTablePtr);
1015
-
1016
- You can then decode your data, symbol after symbol.
1017
- For information the maximum number of bits read by FSEv05_decodeSymbol() is 'tableLog'.
1018
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
1019
- unsigned char symbol = FSEv05_decodeSymbol(&DState, &DStream);
1020
-
1021
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
1022
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
1023
- size_t bitField = BITv05_readBits(&DStream, nbBits);
1024
-
1025
- All above operations only read from local register (which size depends on size_t).
1026
- Refueling the register from memory is manually performed by the reload method.
1027
- endSignal = FSEv05_reloadDStream(&DStream);
1028
-
1029
- BITv05_reloadDStream() result tells if there is still some more data to read from DStream.
1030
- BITv05_DStream_unfinished : there is still some data left into the DStream.
1031
- BITv05_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
1032
- BITv05_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
1033
- BITv05_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
1034
-
1035
- When reaching end of buffer (BITv05_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
1036
- to properly detect the exact end of stream.
1037
- After each decoded symbol, check if DStream is fully consumed using this simple test :
1038
- BITv05_reloadDStream(&DStream) >= BITv05_DStream_completed
1039
-
1040
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
1041
- Checking if DStream has reached its end is performed by :
1042
- BITv05_endOfDStream(&DStream);
1043
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
1044
- FSEv05_endOfDState(&DState);
1045
- */
1046
974
 
1047
975
 
1048
976
  /* *****************************************