zstd-ruby 1.5.1.1 → 1.5.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -204,7 +204,8 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
204
204
  1, 1, 1, 1, 1, 1, 1, 1,
205
205
  1, 1, 1, 1
206
206
  };
207
- ZSTD_memcpy(optPtr->litLengthFreq, baseLLfreqs, sizeof(baseLLfreqs)); optPtr->litLengthSum = sum_u32(baseLLfreqs, MaxLL+1);
207
+ ZSTD_memcpy(optPtr->litLengthFreq, baseLLfreqs, sizeof(baseLLfreqs));
208
+ optPtr->litLengthSum = sum_u32(baseLLfreqs, MaxLL+1);
208
209
  }
209
210
 
210
211
  { unsigned ml;
@@ -219,7 +220,8 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
219
220
  1, 1, 1, 1, 1, 1, 1, 1,
220
221
  1, 1, 1, 1, 1, 1, 1, 1
221
222
  };
222
- ZSTD_memcpy(optPtr->offCodeFreq, baseOFCfreqs, sizeof(baseOFCfreqs)); optPtr->offCodeSum = sum_u32(baseOFCfreqs, MaxOff+1);
223
+ ZSTD_memcpy(optPtr->offCodeFreq, baseOFCfreqs, sizeof(baseOFCfreqs));
224
+ optPtr->offCodeSum = sum_u32(baseOFCfreqs, MaxOff+1);
223
225
  }
224
226
 
225
227
 
@@ -267,7 +269,16 @@ static U32 ZSTD_rawLiteralsCost(const BYTE* const literals, U32 const litLength,
267
269
  * cost of literalLength symbol */
268
270
  static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optPtr, int optLevel)
269
271
  {
270
- if (optPtr->priceType == zop_predef) return WEIGHT(litLength, optLevel);
272
+ assert(litLength <= ZSTD_BLOCKSIZE_MAX);
273
+ if (optPtr->priceType == zop_predef)
274
+ return WEIGHT(litLength, optLevel);
275
+ /* We can't compute the litLength price for sizes >= ZSTD_BLOCKSIZE_MAX
276
+ * because it isn't representable in the zstd format. So instead just
277
+ * call it 1 bit more than ZSTD_BLOCKSIZE_MAX - 1. In this case the block
278
+ * would be all literals.
279
+ */
280
+ if (litLength == ZSTD_BLOCKSIZE_MAX)
281
+ return BITCOST_MULTIPLIER + ZSTD_litLengthPrice(ZSTD_BLOCKSIZE_MAX - 1, optPtr, optLevel);
271
282
 
272
283
  /* dynamic statistics */
273
284
  { U32 const llCode = ZSTD_LLcode(litLength);
@@ -280,15 +291,17 @@ static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optP
280
291
  /* ZSTD_getMatchPrice() :
281
292
  * Provides the cost of the match part (offset + matchLength) of a sequence
282
293
  * Must be combined with ZSTD_fullLiteralsCost() to get the full cost of a sequence.
283
- * optLevel: when <2, favors small offset for decompression speed (improved cache efficiency) */
294
+ * @offcode : expects a scale where 0,1,2 are repcodes 1-3, and 3+ are real_offsets+2
295
+ * @optLevel: when <2, favors small offset for decompression speed (improved cache efficiency)
296
+ */
284
297
  FORCE_INLINE_TEMPLATE U32
285
- ZSTD_getMatchPrice(U32 const offset,
298
+ ZSTD_getMatchPrice(U32 const offcode,
286
299
  U32 const matchLength,
287
300
  const optState_t* const optPtr,
288
301
  int const optLevel)
289
302
  {
290
303
  U32 price;
291
- U32 const offCode = ZSTD_highbit32(offset+1);
304
+ U32 const offCode = ZSTD_highbit32(STORED_TO_OFFBASE(offcode));
292
305
  U32 const mlBase = matchLength - MINMATCH;
293
306
  assert(matchLength >= MINMATCH);
294
307
 
@@ -331,8 +344,8 @@ static void ZSTD_updateStats(optState_t* const optPtr,
331
344
  optPtr->litLengthSum++;
332
345
  }
333
346
 
334
- /* match offset code (0-2=>repCode; 3+=>offset+2) */
335
- { U32 const offCode = ZSTD_highbit32(offsetCode+1);
347
+ /* offset code : expected to follow storeSeq() numeric representation */
348
+ { U32 const offCode = ZSTD_highbit32(STORED_TO_OFFBASE(offsetCode));
336
349
  assert(offCode <= MaxOff);
337
350
  optPtr->offCodeFreq[offCode]++;
338
351
  optPtr->offCodeSum++;
@@ -631,7 +644,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
631
644
  DEBUGLOG(8, "found repCode %u (ll0:%u, offset:%u) of length %u",
632
645
  repCode, ll0, repOffset, repLen);
633
646
  bestLength = repLen;
634
- matches[mnum].off = repCode - ll0;
647
+ matches[mnum].off = STORE_REPCODE(repCode - ll0 + 1); /* expect value between 1 and 3 */
635
648
  matches[mnum].len = (U32)repLen;
636
649
  mnum++;
637
650
  if ( (repLen > sufficient_len)
@@ -660,7 +673,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
660
673
  bestLength = mlen;
661
674
  assert(curr > matchIndex3);
662
675
  assert(mnum==0); /* no prior solution */
663
- matches[0].off = (curr - matchIndex3) + ZSTD_REP_MOVE;
676
+ matches[0].off = STORE_OFFSET(curr - matchIndex3);
664
677
  matches[0].len = (U32)mlen;
665
678
  mnum = 1;
666
679
  if ( (mlen > sufficient_len) |
@@ -694,12 +707,12 @@ U32 ZSTD_insertBtAndGetAllMatches (
694
707
 
695
708
  if (matchLength > bestLength) {
696
709
  DEBUGLOG(8, "found match of length %u at distance %u (offCode=%u)",
697
- (U32)matchLength, curr - matchIndex, curr - matchIndex + ZSTD_REP_MOVE);
710
+ (U32)matchLength, curr - matchIndex, STORE_OFFSET(curr - matchIndex));
698
711
  assert(matchEndIdx > matchIndex);
699
712
  if (matchLength > matchEndIdx - matchIndex)
700
713
  matchEndIdx = matchIndex + (U32)matchLength;
701
714
  bestLength = matchLength;
702
- matches[mnum].off = (curr - matchIndex) + ZSTD_REP_MOVE;
715
+ matches[mnum].off = STORE_OFFSET(curr - matchIndex);
703
716
  matches[mnum].len = (U32)matchLength;
704
717
  mnum++;
705
718
  if ( (matchLength > ZSTD_OPT_NUM)
@@ -742,11 +755,11 @@ U32 ZSTD_insertBtAndGetAllMatches (
742
755
  if (matchLength > bestLength) {
743
756
  matchIndex = dictMatchIndex + dmsIndexDelta;
744
757
  DEBUGLOG(8, "found dms match of length %u at distance %u (offCode=%u)",
745
- (U32)matchLength, curr - matchIndex, curr - matchIndex + ZSTD_REP_MOVE);
758
+ (U32)matchLength, curr - matchIndex, STORE_OFFSET(curr - matchIndex));
746
759
  if (matchLength > matchEndIdx - matchIndex)
747
760
  matchEndIdx = matchIndex + (U32)matchLength;
748
761
  bestLength = matchLength;
749
- matches[mnum].off = (curr - matchIndex) + ZSTD_REP_MOVE;
762
+ matches[mnum].off = STORE_OFFSET(curr - matchIndex);
750
763
  matches[mnum].len = (U32)matchLength;
751
764
  mnum++;
752
765
  if ( (matchLength > ZSTD_OPT_NUM)
@@ -835,7 +848,8 @@ GEN_ZSTD_BT_GET_ALL_MATCHES(dictMatchState)
835
848
  ZSTD_BT_GET_ALL_MATCHES_FN(dictMode, 6) \
836
849
  }
837
850
 
838
- static ZSTD_getAllMatchesFn ZSTD_selectBtGetAllMatches(ZSTD_matchState_t const* ms, ZSTD_dictMode_e const dictMode)
851
+ static ZSTD_getAllMatchesFn
852
+ ZSTD_selectBtGetAllMatches(ZSTD_matchState_t const* ms, ZSTD_dictMode_e const dictMode)
839
853
  {
840
854
  ZSTD_getAllMatchesFn const getAllMatchesFns[3][4] = {
841
855
  ZSTD_BT_GET_ALL_MATCHES_ARRAY(noDict),
@@ -854,16 +868,18 @@ static ZSTD_getAllMatchesFn ZSTD_selectBtGetAllMatches(ZSTD_matchState_t const*
854
868
 
855
869
  /* Struct containing info needed to make decision about ldm inclusion */
856
870
  typedef struct {
857
- rawSeqStore_t seqStore; /* External match candidates store for this block */
858
- U32 startPosInBlock; /* Start position of the current match candidate */
859
- U32 endPosInBlock; /* End position of the current match candidate */
860
- U32 offset; /* Offset of the match candidate */
871
+ rawSeqStore_t seqStore; /* External match candidates store for this block */
872
+ U32 startPosInBlock; /* Start position of the current match candidate */
873
+ U32 endPosInBlock; /* End position of the current match candidate */
874
+ U32 offset; /* Offset of the match candidate */
861
875
  } ZSTD_optLdm_t;
862
876
 
863
877
  /* ZSTD_optLdm_skipRawSeqStoreBytes():
864
- * Moves forward in rawSeqStore by nbBytes, which will update the fields 'pos' and 'posInSequence'.
878
+ * Moves forward in @rawSeqStore by @nbBytes,
879
+ * which will update the fields 'pos' and 'posInSequence'.
865
880
  */
866
- static void ZSTD_optLdm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes) {
881
+ static void ZSTD_optLdm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes)
882
+ {
867
883
  U32 currPos = (U32)(rawSeqStore->posInSequence + nbBytes);
868
884
  while (currPos && rawSeqStore->pos < rawSeqStore->size) {
869
885
  rawSeq currSeq = rawSeqStore->seq[rawSeqStore->pos];
@@ -884,8 +900,10 @@ static void ZSTD_optLdm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t
884
900
  * Calculates the beginning and end of the next match in the current block.
885
901
  * Updates 'pos' and 'posInSequence' of the ldmSeqStore.
886
902
  */
887
- static void ZSTD_opt_getNextMatchAndUpdateSeqStore(ZSTD_optLdm_t* optLdm, U32 currPosInBlock,
888
- U32 blockBytesRemaining) {
903
+ static void
904
+ ZSTD_opt_getNextMatchAndUpdateSeqStore(ZSTD_optLdm_t* optLdm, U32 currPosInBlock,
905
+ U32 blockBytesRemaining)
906
+ {
889
907
  rawSeq currSeq;
890
908
  U32 currBlockEndPos;
891
909
  U32 literalsBytesRemaining;
@@ -897,8 +915,8 @@ static void ZSTD_opt_getNextMatchAndUpdateSeqStore(ZSTD_optLdm_t* optLdm, U32 cu
897
915
  optLdm->endPosInBlock = UINT_MAX;
898
916
  return;
899
917
  }
900
- /* Calculate appropriate bytes left in matchLength and litLength after adjusting
901
- based on ldmSeqStore->posInSequence */
918
+ /* Calculate appropriate bytes left in matchLength and litLength
919
+ * after adjusting based on ldmSeqStore->posInSequence */
902
920
  currSeq = optLdm->seqStore.seq[optLdm->seqStore.pos];
903
921
  assert(optLdm->seqStore.posInSequence <= currSeq.litLength + currSeq.matchLength);
904
922
  currBlockEndPos = currPosInBlock + blockBytesRemaining;
@@ -934,15 +952,16 @@ static void ZSTD_opt_getNextMatchAndUpdateSeqStore(ZSTD_optLdm_t* optLdm, U32 cu
934
952
  }
935
953
 
936
954
  /* ZSTD_optLdm_maybeAddMatch():
937
- * Adds a match if it's long enough, based on it's 'matchStartPosInBlock'
938
- * and 'matchEndPosInBlock', into 'matches'. Maintains the correct ordering of 'matches'
955
+ * Adds a match if it's long enough,
956
+ * based on it's 'matchStartPosInBlock' and 'matchEndPosInBlock',
957
+ * into 'matches'. Maintains the correct ordering of 'matches'.
939
958
  */
940
959
  static void ZSTD_optLdm_maybeAddMatch(ZSTD_match_t* matches, U32* nbMatches,
941
- ZSTD_optLdm_t* optLdm, U32 currPosInBlock) {
942
- U32 posDiff = currPosInBlock - optLdm->startPosInBlock;
960
+ const ZSTD_optLdm_t* optLdm, U32 currPosInBlock)
961
+ {
962
+ U32 const posDiff = currPosInBlock - optLdm->startPosInBlock;
943
963
  /* Note: ZSTD_match_t actually contains offCode and matchLength (before subtracting MINMATCH) */
944
- U32 candidateMatchLength = optLdm->endPosInBlock - optLdm->startPosInBlock - posDiff;
945
- U32 candidateOffCode = optLdm->offset + ZSTD_REP_MOVE;
964
+ U32 const candidateMatchLength = optLdm->endPosInBlock - optLdm->startPosInBlock - posDiff;
946
965
 
947
966
  /* Ensure that current block position is not outside of the match */
948
967
  if (currPosInBlock < optLdm->startPosInBlock
@@ -952,6 +971,7 @@ static void ZSTD_optLdm_maybeAddMatch(ZSTD_match_t* matches, U32* nbMatches,
952
971
  }
953
972
 
954
973
  if (*nbMatches == 0 || ((candidateMatchLength > matches[*nbMatches-1].len) && *nbMatches < ZSTD_OPT_NUM)) {
974
+ U32 const candidateOffCode = STORE_OFFSET(optLdm->offset);
955
975
  DEBUGLOG(6, "ZSTD_optLdm_maybeAddMatch(): Adding ldm candidate match (offCode: %u matchLength %u) at block position=%u",
956
976
  candidateOffCode, candidateMatchLength, currPosInBlock);
957
977
  matches[*nbMatches].len = candidateMatchLength;
@@ -963,8 +983,11 @@ static void ZSTD_optLdm_maybeAddMatch(ZSTD_match_t* matches, U32* nbMatches,
963
983
  /* ZSTD_optLdm_processMatchCandidate():
964
984
  * Wrapper function to update ldm seq store and call ldm functions as necessary.
965
985
  */
966
- static void ZSTD_optLdm_processMatchCandidate(ZSTD_optLdm_t* optLdm, ZSTD_match_t* matches, U32* nbMatches,
967
- U32 currPosInBlock, U32 remainingBytes) {
986
+ static void
987
+ ZSTD_optLdm_processMatchCandidate(ZSTD_optLdm_t* optLdm,
988
+ ZSTD_match_t* matches, U32* nbMatches,
989
+ U32 currPosInBlock, U32 remainingBytes)
990
+ {
968
991
  if (optLdm->seqStore.size == 0 || optLdm->seqStore.pos >= optLdm->seqStore.size) {
969
992
  return;
970
993
  }
@@ -975,7 +998,7 @@ static void ZSTD_optLdm_processMatchCandidate(ZSTD_optLdm_t* optLdm, ZSTD_match_
975
998
  * at the end of a match from the ldm seq store, and will often be some bytes
976
999
  * over beyond matchEndPosInBlock. As such, we need to correct for these "overshoots"
977
1000
  */
978
- U32 posOvershoot = currPosInBlock - optLdm->endPosInBlock;
1001
+ U32 const posOvershoot = currPosInBlock - optLdm->endPosInBlock;
979
1002
  ZSTD_optLdm_skipRawSeqStoreBytes(&optLdm->seqStore, posOvershoot);
980
1003
  }
981
1004
  ZSTD_opt_getNextMatchAndUpdateSeqStore(optLdm, currPosInBlock, remainingBytes);
@@ -1075,14 +1098,14 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
1075
1098
 
1076
1099
  /* large match -> immediate encoding */
1077
1100
  { U32 const maxML = matches[nbMatches-1].len;
1078
- U32 const maxOffset = matches[nbMatches-1].off;
1101
+ U32 const maxOffcode = matches[nbMatches-1].off;
1079
1102
  DEBUGLOG(6, "found %u matches of maxLength=%u and maxOffCode=%u at cPos=%u => start new series",
1080
- nbMatches, maxML, maxOffset, (U32)(ip-prefixStart));
1103
+ nbMatches, maxML, maxOffcode, (U32)(ip-prefixStart));
1081
1104
 
1082
1105
  if (maxML > sufficient_len) {
1083
1106
  lastSequence.litlen = litlen;
1084
1107
  lastSequence.mlen = maxML;
1085
- lastSequence.off = maxOffset;
1108
+ lastSequence.off = maxOffcode;
1086
1109
  DEBUGLOG(6, "large match (%u>%u), immediate encoding",
1087
1110
  maxML, sufficient_len);
1088
1111
  cur = 0;
@@ -1099,15 +1122,15 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
1099
1122
  opt[pos].price = ZSTD_MAX_PRICE; /* mlen, litlen and price will be fixed during forward scanning */
1100
1123
  }
1101
1124
  for (matchNb = 0; matchNb < nbMatches; matchNb++) {
1102
- U32 const offset = matches[matchNb].off;
1125
+ U32 const offcode = matches[matchNb].off;
1103
1126
  U32 const end = matches[matchNb].len;
1104
1127
  for ( ; pos <= end ; pos++ ) {
1105
- U32 const matchPrice = ZSTD_getMatchPrice(offset, pos, optStatePtr, optLevel);
1128
+ U32 const matchPrice = ZSTD_getMatchPrice(offcode, pos, optStatePtr, optLevel);
1106
1129
  U32 const sequencePrice = literalsPrice + matchPrice;
1107
1130
  DEBUGLOG(7, "rPos:%u => set initial price : %.2f",
1108
1131
  pos, ZSTD_fCost(sequencePrice));
1109
1132
  opt[pos].mlen = pos;
1110
- opt[pos].off = offset;
1133
+ opt[pos].off = offcode;
1111
1134
  opt[pos].litlen = litlen;
1112
1135
  opt[pos].price = (int)sequencePrice;
1113
1136
  } }
@@ -1152,7 +1175,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
1152
1175
  assert(cur >= opt[cur].mlen);
1153
1176
  if (opt[cur].mlen != 0) {
1154
1177
  U32 const prev = cur - opt[cur].mlen;
1155
- repcodes_t newReps = ZSTD_updateRep(opt[prev].rep, opt[cur].off, opt[cur].litlen==0);
1178
+ repcodes_t const newReps = ZSTD_newRep(opt[prev].rep, opt[cur].off, opt[cur].litlen==0);
1156
1179
  ZSTD_memcpy(opt[cur].rep, &newReps, sizeof(repcodes_t));
1157
1180
  } else {
1158
1181
  ZSTD_memcpy(opt[cur].rep, opt[cur - 1].rep, sizeof(repcodes_t));
@@ -1242,7 +1265,7 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
1242
1265
  * update them while traversing the sequences.
1243
1266
  */
1244
1267
  if (lastSequence.mlen != 0) {
1245
- repcodes_t reps = ZSTD_updateRep(opt[cur].rep, lastSequence.off, lastSequence.litlen==0);
1268
+ repcodes_t const reps = ZSTD_newRep(opt[cur].rep, lastSequence.off, lastSequence.litlen==0);
1246
1269
  ZSTD_memcpy(rep, &reps, sizeof(reps));
1247
1270
  } else {
1248
1271
  ZSTD_memcpy(rep, opt[cur].rep, sizeof(repcodes_t));
@@ -1286,7 +1309,7 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
1286
1309
 
1287
1310
  assert(anchor + llen <= iend);
1288
1311
  ZSTD_updateStats(optStatePtr, llen, anchor, offCode, mlen);
1289
- ZSTD_storeSeq(seqStore, llen, anchor, iend, offCode, mlen-MINMATCH);
1312
+ ZSTD_storeSeq(seqStore, llen, anchor, iend, offCode, mlen);
1290
1313
  anchor += advance;
1291
1314
  ip = anchor;
1292
1315
  } }
@@ -102,9 +102,8 @@ typedef struct ZSTDMT_bufferPool_s {
102
102
  buffer_t bTable[1]; /* variable size */
103
103
  } ZSTDMT_bufferPool;
104
104
 
105
- static ZSTDMT_bufferPool* ZSTDMT_createBufferPool(unsigned nbWorkers, ZSTD_customMem cMem)
105
+ static ZSTDMT_bufferPool* ZSTDMT_createBufferPool(unsigned maxNbBuffers, ZSTD_customMem cMem)
106
106
  {
107
- unsigned const maxNbBuffers = 2*nbWorkers + 3;
108
107
  ZSTDMT_bufferPool* const bufPool = (ZSTDMT_bufferPool*)ZSTD_customCalloc(
109
108
  sizeof(ZSTDMT_bufferPool) + (maxNbBuffers-1) * sizeof(buffer_t), cMem);
110
109
  if (bufPool==NULL) return NULL;
@@ -160,9 +159,8 @@ static void ZSTDMT_setBufferSize(ZSTDMT_bufferPool* const bufPool, size_t const
160
159
  }
161
160
 
162
161
 
163
- static ZSTDMT_bufferPool* ZSTDMT_expandBufferPool(ZSTDMT_bufferPool* srcBufPool, U32 nbWorkers)
162
+ static ZSTDMT_bufferPool* ZSTDMT_expandBufferPool(ZSTDMT_bufferPool* srcBufPool, unsigned maxNbBuffers)
164
163
  {
165
- unsigned const maxNbBuffers = 2*nbWorkers + 3;
166
164
  if (srcBufPool==NULL) return NULL;
167
165
  if (srcBufPool->totalBuffers >= maxNbBuffers) /* good enough */
168
166
  return srcBufPool;
@@ -171,7 +169,7 @@ static ZSTDMT_bufferPool* ZSTDMT_expandBufferPool(ZSTDMT_bufferPool* srcBufPool,
171
169
  size_t const bSize = srcBufPool->bufferSize; /* forward parameters */
172
170
  ZSTDMT_bufferPool* newBufPool;
173
171
  ZSTDMT_freeBufferPool(srcBufPool);
174
- newBufPool = ZSTDMT_createBufferPool(nbWorkers, cMem);
172
+ newBufPool = ZSTDMT_createBufferPool(maxNbBuffers, cMem);
175
173
  if (newBufPool==NULL) return newBufPool;
176
174
  ZSTDMT_setBufferSize(newBufPool, bSize);
177
175
  return newBufPool;
@@ -263,6 +261,16 @@ static void ZSTDMT_releaseBuffer(ZSTDMT_bufferPool* bufPool, buffer_t buf)
263
261
  ZSTD_customFree(buf.start, bufPool->cMem);
264
262
  }
265
263
 
264
+ /* We need 2 output buffers per worker since each dstBuff must be flushed after it is released.
265
+ * The 3 additional buffers are as follows:
266
+ * 1 buffer for input loading
267
+ * 1 buffer for "next input" when submitting current one
268
+ * 1 buffer stuck in queue */
269
+ #define BUF_POOL_MAX_NB_BUFFERS(nbWorkers) 2*nbWorkers + 3
270
+
271
+ /* After a worker releases its rawSeqStore, it is immediately ready for reuse.
272
+ * So we only need one seq buffer per worker. */
273
+ #define SEQ_POOL_MAX_NB_BUFFERS(nbWorkers) nbWorkers
266
274
 
267
275
  /* ===== Seq Pool Wrapper ====== */
268
276
 
@@ -316,7 +324,7 @@ static void ZSTDMT_setNbSeq(ZSTDMT_seqPool* const seqPool, size_t const nbSeq)
316
324
 
317
325
  static ZSTDMT_seqPool* ZSTDMT_createSeqPool(unsigned nbWorkers, ZSTD_customMem cMem)
318
326
  {
319
- ZSTDMT_seqPool* const seqPool = ZSTDMT_createBufferPool(nbWorkers, cMem);
327
+ ZSTDMT_seqPool* const seqPool = ZSTDMT_createBufferPool(SEQ_POOL_MAX_NB_BUFFERS(nbWorkers), cMem);
320
328
  if (seqPool == NULL) return NULL;
321
329
  ZSTDMT_setNbSeq(seqPool, 0);
322
330
  return seqPool;
@@ -329,7 +337,7 @@ static void ZSTDMT_freeSeqPool(ZSTDMT_seqPool* seqPool)
329
337
 
330
338
  static ZSTDMT_seqPool* ZSTDMT_expandSeqPool(ZSTDMT_seqPool* pool, U32 nbWorkers)
331
339
  {
332
- return ZSTDMT_expandBufferPool(pool, nbWorkers);
340
+ return ZSTDMT_expandBufferPool(pool, SEQ_POOL_MAX_NB_BUFFERS(nbWorkers));
333
341
  }
334
342
 
335
343
 
@@ -936,7 +944,7 @@ MEM_STATIC ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced_internal(unsigned nbWorkers,
936
944
  mtctx->jobs = ZSTDMT_createJobsTable(&nbJobs, cMem);
937
945
  assert(nbJobs > 0); assert((nbJobs & (nbJobs - 1)) == 0); /* ensure nbJobs is a power of 2 */
938
946
  mtctx->jobIDMask = nbJobs - 1;
939
- mtctx->bufPool = ZSTDMT_createBufferPool(nbWorkers, cMem);
947
+ mtctx->bufPool = ZSTDMT_createBufferPool(BUF_POOL_MAX_NB_BUFFERS(nbWorkers), cMem);
940
948
  mtctx->cctxPool = ZSTDMT_createCCtxPool(nbWorkers, cMem);
941
949
  mtctx->seqPool = ZSTDMT_createSeqPool(nbWorkers, cMem);
942
950
  initError = ZSTDMT_serialState_init(&mtctx->serial);
@@ -1039,7 +1047,7 @@ static size_t ZSTDMT_resize(ZSTDMT_CCtx* mtctx, unsigned nbWorkers)
1039
1047
  {
1040
1048
  if (POOL_resize(mtctx->factory, nbWorkers)) return ERROR(memory_allocation);
1041
1049
  FORWARD_IF_ERROR( ZSTDMT_expandJobsTable(mtctx, nbWorkers) , "");
1042
- mtctx->bufPool = ZSTDMT_expandBufferPool(mtctx->bufPool, nbWorkers);
1050
+ mtctx->bufPool = ZSTDMT_expandBufferPool(mtctx->bufPool, BUF_POOL_MAX_NB_BUFFERS(nbWorkers));
1043
1051
  if (mtctx->bufPool == NULL) return ERROR(memory_allocation);
1044
1052
  mtctx->cctxPool = ZSTDMT_expandCCtxPool(mtctx->cctxPool, nbWorkers);
1045
1053
  if (mtctx->cctxPool == NULL) return ERROR(memory_allocation);
@@ -65,8 +65,11 @@ size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
65
65
  * Private use only. Init streaming operation.
66
66
  * expects params to be valid.
67
67
  * must receive dict, or cdict, or none, but not both.
68
+ * mtctx can be freshly constructed or reused from a prior compression.
69
+ * If mtctx is reused, memory allocations from the prior compression may not be freed,
70
+ * even if they are not needed for the current compression.
68
71
  * @return : 0, or an error code */
69
- size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs,
72
+ size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx,
70
73
  const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
71
74
  const ZSTD_CDict* cdict,
72
75
  ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
@@ -664,7 +664,7 @@ size_t HUF_decompress4X1_usingDTable_internal_default(void* dst, size_t dstSize,
664
664
 
665
665
  #if ZSTD_ENABLE_ASM_X86_64_BMI2
666
666
 
667
- HUF_ASM_DECL void HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop(HUF_DecompressAsmArgs* args);
667
+ HUF_ASM_DECL void HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop(HUF_DecompressAsmArgs* args) ZSTDLIB_HIDDEN;
668
668
 
669
669
  static HUF_ASM_X86_64_BMI2_ATTRS
670
670
  size_t
@@ -1380,7 +1380,7 @@ size_t HUF_decompress4X2_usingDTable_internal_default(void* dst, size_t dstSize,
1380
1380
 
1381
1381
  #if ZSTD_ENABLE_ASM_X86_64_BMI2
1382
1382
 
1383
- HUF_ASM_DECL void HUF_decompress4X2_usingDTable_internal_bmi2_asm_loop(HUF_DecompressAsmArgs* args);
1383
+ HUF_ASM_DECL void HUF_decompress4X2_usingDTable_internal_bmi2_asm_loop(HUF_DecompressAsmArgs* args) ZSTDLIB_HIDDEN;
1384
1384
 
1385
1385
  static HUF_ASM_X86_64_BMI2_ATTRS size_t
1386
1386
  HUF_decompress4X2_usingDTable_internal_bmi2_asm(
@@ -1,14 +1,24 @@
1
- #include "../common/portability_macros.h"
1
+ /*
2
+ * Copyright (c) Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
2
10
 
3
- #if ZSTD_ENABLE_ASM_X86_64_BMI2
11
+ #include "../common/portability_macros.h"
4
12
 
5
13
  /* Stack marking
6
14
  * ref: https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
7
15
  */
8
- #if defined(__linux__) && defined(__ELF__)
16
+ #if defined(__ELF__) && defined(__GNUC__)
9
17
  .section .note.GNU-stack,"",%progbits
10
18
  #endif
11
19
 
20
+ #if ZSTD_ENABLE_ASM_X86_64_BMI2
21
+
12
22
  /* Calling convention:
13
23
  *
14
24
  * %rdi contains the first argument: HUF_DecompressAsmArgs*.
@@ -20,6 +30,10 @@
20
30
  * TODO: Support Windows calling convention.
21
31
  */
22
32
 
33
+ ZSTD_HIDE_ASM_FUNCTION(HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop)
34
+ ZSTD_HIDE_ASM_FUNCTION(HUF_decompress4X2_usingDTable_internal_bmi2_asm_loop)
35
+ ZSTD_HIDE_ASM_FUNCTION(_HUF_decompress4X2_usingDTable_internal_bmi2_asm_loop)
36
+ ZSTD_HIDE_ASM_FUNCTION(_HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop)
23
37
  .global HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop
24
38
  .global HUF_decompress4X2_usingDTable_internal_bmi2_asm_loop
25
39
  .global _HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop
@@ -682,8 +682,8 @@ static void ZDICT_countEStats(EStats_ress_t esr, const ZSTD_parameters* params,
682
682
 
683
683
  if (nbSeq >= 2) { /* rep offsets */
684
684
  const seqDef* const seq = seqStorePtr->sequencesStart;
685
- U32 offset1 = seq[0].offset - 3;
686
- U32 offset2 = seq[1].offset - 3;
685
+ U32 offset1 = seq[0].offBase - ZSTD_REP_NUM;
686
+ U32 offset2 = seq[1].offBase - ZSTD_REP_NUM;
687
687
  if (offset1 >= MAXREPOFFSET) offset1 = 0;
688
688
  if (offset2 >= MAXREPOFFSET) offset2 = 0;
689
689
  repOffsets[offset1] += 3;
@@ -34,6 +34,8 @@ ZSTD_NO_ASM ?= 0
34
34
  # libzstd helpers
35
35
  ##################################################################
36
36
 
37
+ VOID ?= /dev/null
38
+
37
39
  # Make 4.3 doesn't support '\#' anymore (https://lwn.net/Articles/810071/)
38
40
  NUM_SYMBOL := \#
39
41
 
@@ -79,7 +81,7 @@ endif
79
81
  CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
80
82
  -DDYNAMIC_BMI2=0 -DNDEBUG
81
83
  else
82
- CFLAGS += -O3
84
+ CFLAGS ?= -O3
83
85
  endif
84
86
 
85
87
  DEBUGLEVEL ?= 0
@@ -93,8 +95,24 @@ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
93
95
  -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
94
96
  -Wredundant-decls -Wmissing-prototypes -Wc++-compat
95
97
  CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
98
+ ASFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) $(CFLAGS)
96
99
  LDFLAGS += $(MOREFLAGS)
97
- FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
100
+ FLAGS = $(CPPFLAGS) $(CFLAGS) $(ASFLAGS) $(LDFLAGS)
101
+
102
+ ifndef ALREADY_APPENDED_NOEXECSTACK
103
+ export ALREADY_APPENDED_NOEXECSTACK := 1
104
+ ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z noexecstack -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
105
+ LDFLAGS += -z noexecstack
106
+ endif
107
+ ifeq ($(shell echo | $(CC) $(FLAGS) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
108
+ CFLAGS += -Wa,--noexecstack
109
+ # CFLAGS are also added to ASFLAGS
110
+ else ifeq ($(shell echo | $(CC) $(FLAGS) -Qunused-arguments -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
111
+ # See e.g.: https://github.com/android/ndk/issues/171
112
+ CFLAGS += -Qunused-arguments -Wa,--noexecstack
113
+ # CFLAGS are also added to ASFLAGS
114
+ endif
115
+ endif
98
116
 
99
117
  HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
100
118
  GREP_OPTIONS ?=
@@ -0,0 +1,25 @@
1
+ module libzstd [extern_c] {
2
+ header "zstd.h"
3
+ export *
4
+ config_macros [exhaustive] /* zstd.h */ \
5
+ ZSTD_STATIC_LINKING_ONLY, \
6
+ ZSTDLIB_VISIBLE, \
7
+ ZSTD_DLL_EXPORT, \
8
+ ZSTDLIB_STATIC_API, \
9
+ ZSTD_DISABLE_DEPRECATE_WARNINGS, \
10
+ ZSTD_CLEVEL_DEFAULT, \
11
+ /* zdict.h */ ZDICT_STATIC_LINKING_ONLY, \
12
+ ZDICTLIB_VISIBILITY, \
13
+ ZDICT_DISABLE_DEPRECATE_WARNINGS, \
14
+ /* zstd_errors.h */ ZSTDERRORLIB_VISIBILITY
15
+
16
+ module dictbuilder [extern_c] {
17
+ header "zdict.h"
18
+ export *
19
+ }
20
+
21
+ module errors [extern_c] {
22
+ header "zstd_errors.h"
23
+ export *
24
+ }
25
+ }
@@ -74,7 +74,7 @@ extern "C" {
74
74
  /*------ Version ------*/
75
75
  #define ZSTD_VERSION_MAJOR 1
76
76
  #define ZSTD_VERSION_MINOR 5
77
- #define ZSTD_VERSION_RELEASE 1
77
+ #define ZSTD_VERSION_RELEASE 2
78
78
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
79
79
 
80
80
  /*! ZSTD_versionNumber() :
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "1.5.1.1"
2
+ VERSION = "1.5.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zstd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1.1
4
+ version: 1.5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SpringMT
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-28 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -182,7 +182,7 @@ files:
182
182
  - ext/zstdruby/libzstd/legacy/zstd_v07.h
183
183
  - ext/zstdruby/libzstd/libzstd.mk
184
184
  - ext/zstdruby/libzstd/libzstd.pc.in
185
- - ext/zstdruby/libzstd/modulemap/module.modulemap
185
+ - ext/zstdruby/libzstd/module.modulemap
186
186
  - ext/zstdruby/libzstd/zdict.h
187
187
  - ext/zstdruby/libzstd/zstd.h
188
188
  - ext/zstdruby/libzstd/zstd_errors.h
@@ -195,7 +195,7 @@ homepage: https://github.com/SpringMT/zstd-ruby
195
195
  licenses:
196
196
  - MIT
197
197
  metadata: {}
198
- post_install_message:
198
+ post_install_message:
199
199
  rdoc_options: []
200
200
  require_paths:
201
201
  - lib
@@ -210,8 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubygems_version: 3.3.3
214
- signing_key:
213
+ rubygems_version: 3.1.6
214
+ signing_key:
215
215
  specification_version: 4
216
216
  summary: Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
217
217
  test_files: []
@@ -1,4 +0,0 @@
1
- module libzstd [extern_c] {
2
- header "../zstd.h"
3
- export *
4
- }