zstd-ruby 1.5.2.3 → 1.5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/ext/zstdruby/libzstd/common/bits.h +175 -0
  4. data/ext/zstdruby/libzstd/common/bitstream.h +18 -59
  5. data/ext/zstdruby/libzstd/common/compiler.h +22 -3
  6. data/ext/zstdruby/libzstd/common/cpu.h +1 -1
  7. data/ext/zstdruby/libzstd/common/debug.c +1 -1
  8. data/ext/zstdruby/libzstd/common/debug.h +1 -1
  9. data/ext/zstdruby/libzstd/common/entropy_common.c +12 -40
  10. data/ext/zstdruby/libzstd/common/error_private.c +9 -2
  11. data/ext/zstdruby/libzstd/common/error_private.h +1 -1
  12. data/ext/zstdruby/libzstd/common/fse.h +5 -83
  13. data/ext/zstdruby/libzstd/common/fse_decompress.c +7 -99
  14. data/ext/zstdruby/libzstd/common/huf.h +65 -156
  15. data/ext/zstdruby/libzstd/common/mem.h +39 -46
  16. data/ext/zstdruby/libzstd/common/pool.c +26 -10
  17. data/ext/zstdruby/libzstd/common/pool.h +7 -1
  18. data/ext/zstdruby/libzstd/common/portability_macros.h +22 -3
  19. data/ext/zstdruby/libzstd/common/threading.c +68 -14
  20. data/ext/zstdruby/libzstd/common/threading.h +5 -10
  21. data/ext/zstdruby/libzstd/common/xxhash.c +2 -2
  22. data/ext/zstdruby/libzstd/common/xxhash.h +8 -8
  23. data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
  24. data/ext/zstdruby/libzstd/common/zstd_deps.h +1 -1
  25. data/ext/zstdruby/libzstd/common/zstd_internal.h +17 -113
  26. data/ext/zstdruby/libzstd/common/zstd_trace.h +3 -3
  27. data/ext/zstdruby/libzstd/compress/clevels.h +1 -1
  28. data/ext/zstdruby/libzstd/compress/fse_compress.c +7 -124
  29. data/ext/zstdruby/libzstd/compress/hist.c +1 -1
  30. data/ext/zstdruby/libzstd/compress/hist.h +1 -1
  31. data/ext/zstdruby/libzstd/compress/huf_compress.c +234 -169
  32. data/ext/zstdruby/libzstd/compress/zstd_compress.c +1055 -455
  33. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +165 -145
  34. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +115 -39
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +16 -8
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +3 -3
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -21
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
  40. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +5 -3
  41. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +95 -33
  42. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +3 -2
  43. data/ext/zstdruby/libzstd/compress/zstd_fast.c +433 -148
  44. data/ext/zstdruby/libzstd/compress/zstd_fast.h +3 -2
  45. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +306 -283
  46. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +4 -2
  47. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +5 -5
  48. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +1 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +1 -1
  50. data/ext/zstdruby/libzstd/compress/zstd_opt.c +104 -80
  51. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  52. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +12 -5
  53. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +1 -1
  54. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +434 -441
  55. data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +30 -39
  56. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +3 -4
  57. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +1 -1
  58. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +164 -42
  59. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +186 -65
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +1 -1
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +4 -2
  62. data/ext/zstdruby/libzstd/dictBuilder/cover.c +19 -15
  63. data/ext/zstdruby/libzstd/dictBuilder/cover.h +1 -1
  64. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +2 -2
  65. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +9 -87
  66. data/ext/zstdruby/libzstd/zdict.h +53 -31
  67. data/ext/zstdruby/libzstd/zstd.h +489 -90
  68. data/ext/zstdruby/libzstd/zstd_errors.h +27 -8
  69. data/ext/zstdruby/main.c +4 -0
  70. data/lib/zstd-ruby/version.rb +1 -1
  71. metadata +7 -6
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -28,7 +28,6 @@
28
28
  #include "../zstd.h"
29
29
  #define FSE_STATIC_LINKING_ONLY
30
30
  #include "fse.h"
31
- #define HUF_STATIC_LINKING_ONLY
32
31
  #include "huf.h"
33
32
  #ifndef XXH_STATIC_LINKING_ONLY
34
33
  # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
@@ -93,9 +92,9 @@ typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
93
92
  #define ZSTD_FRAMECHECKSUMSIZE 4
94
93
 
95
94
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
96
- #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
95
+ #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */) /* for a non-null block */
96
+ #define MIN_LITERALS_FOR_4_STREAMS 6
97
97
 
98
- #define HufLog 12
99
98
  typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
100
99
 
101
100
  #define LONGNBSEQ 0x7F00
@@ -103,6 +102,7 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
103
102
  #define MINMATCH 3
104
103
 
105
104
  #define Litbits 8
105
+ #define LitHufLog 11
106
106
  #define MaxLit ((1<<Litbits) - 1)
107
107
  #define MaxML 52
108
108
  #define MaxLL 35
@@ -113,6 +113,8 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
113
113
  #define LLFSELog 9
114
114
  #define OffFSELog 8
115
115
  #define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
116
+ #define MaxMLBits 16
117
+ #define MaxLLBits 16
116
118
 
117
119
  #define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
118
120
  /* Each table cannot take more than #symbols * FSELog bits */
@@ -235,12 +237,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
235
237
  * one COPY16() in the first call. Then, do two calls per loop since
236
238
  * at that point it is more likely to have a high trip count.
237
239
  */
238
- #ifdef __aarch64__
239
- do {
240
- COPY16(op, ip);
241
- }
242
- while (op < oend);
243
- #else
244
240
  ZSTD_copy16(op, ip);
245
241
  if (16 >= length) return;
246
242
  op += 16;
@@ -250,7 +246,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
250
246
  COPY16(op, ip);
251
247
  }
252
248
  while (op < oend);
253
- #endif
254
249
  }
255
250
  }
256
251
 
@@ -299,11 +294,11 @@ typedef enum {
299
294
  typedef struct {
300
295
  seqDef* sequencesStart;
301
296
  seqDef* sequences; /* ptr to end of sequences */
302
- BYTE* litStart;
303
- BYTE* lit; /* ptr to end of literals */
304
- BYTE* llCode;
305
- BYTE* mlCode;
306
- BYTE* ofCode;
297
+ BYTE* litStart;
298
+ BYTE* lit; /* ptr to end of literals */
299
+ BYTE* llCode;
300
+ BYTE* mlCode;
301
+ BYTE* ofCode;
307
302
  size_t maxNbSeq;
308
303
  size_t maxNbLit;
309
304
 
@@ -311,8 +306,8 @@ typedef struct {
311
306
  * in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
312
307
  * the existing value of the litLength or matchLength by 0x10000.
313
308
  */
314
- ZSTD_longLengthType_e longLengthType;
315
- U32 longLengthPos; /* Index of the sequence to apply long length modification to */
309
+ ZSTD_longLengthType_e longLengthType;
310
+ U32 longLengthPos; /* Index of the sequence to apply long length modification to */
316
311
  } seqStore_t;
317
312
 
318
313
  typedef struct {
@@ -331,10 +326,10 @@ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore
331
326
  seqLen.matchLength = seq->mlBase + MINMATCH;
332
327
  if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
333
328
  if (seqStore->longLengthType == ZSTD_llt_literalLength) {
334
- seqLen.litLength += 0xFFFF;
329
+ seqLen.litLength += 0x10000;
335
330
  }
336
331
  if (seqStore->longLengthType == ZSTD_llt_matchLength) {
337
- seqLen.matchLength += 0xFFFF;
332
+ seqLen.matchLength += 0x10000;
338
333
  }
339
334
  }
340
335
  return seqLen;
@@ -347,12 +342,13 @@ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore
347
342
  * `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
348
343
  */
349
344
  typedef struct {
345
+ size_t nbBlocks;
350
346
  size_t compressedSize;
351
347
  unsigned long long decompressedBound;
352
348
  } ZSTD_frameSizeInfo; /* decompress & legacy */
353
349
 
354
350
  const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
355
- void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
351
+ int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
356
352
 
357
353
  /* custom memory allocation functions */
358
354
  void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
@@ -360,98 +356,6 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
360
356
  void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
361
357
 
362
358
 
363
- MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
364
- {
365
- assert(val != 0);
366
- {
367
- # if defined(_MSC_VER) /* Visual */
368
- # if STATIC_BMI2 == 1
369
- return _lzcnt_u32(val)^31;
370
- # else
371
- if (val != 0) {
372
- unsigned long r;
373
- _BitScanReverse(&r, val);
374
- return (unsigned)r;
375
- } else {
376
- /* Should not reach this code path */
377
- __assume(0);
378
- }
379
- # endif
380
- # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
381
- return __builtin_clz (val) ^ 31;
382
- # elif defined(__ICCARM__) /* IAR Intrinsic */
383
- return 31 - __CLZ(val);
384
- # else /* Software version */
385
- static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
386
- U32 v = val;
387
- v |= v >> 1;
388
- v |= v >> 2;
389
- v |= v >> 4;
390
- v |= v >> 8;
391
- v |= v >> 16;
392
- return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
393
- # endif
394
- }
395
- }
396
-
397
- /**
398
- * Counts the number of trailing zeros of a `size_t`.
399
- * Most compilers should support CTZ as a builtin. A backup
400
- * implementation is provided if the builtin isn't supported, but
401
- * it may not be terribly efficient.
402
- */
403
- MEM_STATIC unsigned ZSTD_countTrailingZeros(size_t val)
404
- {
405
- if (MEM_64bits()) {
406
- # if defined(_MSC_VER) && defined(_WIN64)
407
- # if STATIC_BMI2
408
- return _tzcnt_u64(val);
409
- # else
410
- if (val != 0) {
411
- unsigned long r;
412
- _BitScanForward64(&r, (U64)val);
413
- return (unsigned)r;
414
- } else {
415
- /* Should not reach this code path */
416
- __assume(0);
417
- }
418
- # endif
419
- # elif defined(__GNUC__) && (__GNUC__ >= 4)
420
- return __builtin_ctzll((U64)val);
421
- # else
422
- static const int DeBruijnBytePos[64] = { 0, 1, 2, 7, 3, 13, 8, 19,
423
- 4, 25, 14, 28, 9, 34, 20, 56,
424
- 5, 17, 26, 54, 15, 41, 29, 43,
425
- 10, 31, 38, 35, 21, 45, 49, 57,
426
- 63, 6, 12, 18, 24, 27, 33, 55,
427
- 16, 53, 40, 42, 30, 37, 44, 48,
428
- 62, 11, 23, 32, 52, 39, 36, 47,
429
- 61, 22, 51, 46, 60, 50, 59, 58 };
430
- return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
431
- # endif
432
- } else { /* 32 bits */
433
- # if defined(_MSC_VER)
434
- if (val != 0) {
435
- unsigned long r;
436
- _BitScanForward(&r, (U32)val);
437
- return (unsigned)r;
438
- } else {
439
- /* Should not reach this code path */
440
- __assume(0);
441
- }
442
- # elif defined(__GNUC__) && (__GNUC__ >= 3)
443
- return __builtin_ctz((U32)val);
444
- # else
445
- static const int DeBruijnBytePos[32] = { 0, 1, 28, 2, 29, 14, 24, 3,
446
- 30, 22, 20, 15, 25, 17, 4, 8,
447
- 31, 27, 13, 23, 21, 19, 16, 7,
448
- 26, 12, 18, 6, 11, 5, 10, 9 };
449
- return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
450
- # endif
451
- }
452
- }
453
-
454
-
455
359
  /* ZSTD_invalidateRepCodes() :
456
360
  * ensures next compression will not use repcodes from previous block.
457
361
  * Note : only works with regular variant;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -21,13 +21,13 @@ extern "C" {
21
21
  * For now, enable conservatively:
22
22
  * - Only GNUC
23
23
  * - Only ELF
24
- * - Only x86-64 and i386
24
+ * - Only x86-64, i386 and aarch64
25
25
  * Also, explicitly disable on platforms known not to work so they aren't
26
26
  * forgotten in the future.
27
27
  */
28
28
  #if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \
29
29
  defined(__GNUC__) && defined(__ELF__) && \
30
- (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)) && \
30
+ (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__aarch64__)) && \
31
31
  !defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \
32
32
  !defined(__CYGWIN__) && !defined(_AIX)
33
33
  # define ZSTD_HAVE_WEAK_SYMBOLS 1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -1,6 +1,6 @@
1
1
  /* ******************************************************************
2
2
  * FSE : Finite State Entropy encoder
3
- * Copyright (c) Yann Collet, Facebook, Inc.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * You can contact the author at :
6
6
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -26,6 +26,7 @@
26
26
  #define ZSTD_DEPS_NEED_MALLOC
27
27
  #define ZSTD_DEPS_NEED_MATH64
28
28
  #include "../common/zstd_deps.h" /* ZSTD_malloc, ZSTD_free, ZSTD_memcpy, ZSTD_memset */
29
+ #include "../common/bits.h" /* ZSTD_highbit32 */
29
30
 
30
31
 
31
32
  /* **************************************************************
@@ -90,7 +91,7 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
90
91
  assert(tableLog < 16); /* required for threshold strategy to work */
91
92
 
92
93
  /* For explanations on how to distribute symbol values over the table :
93
- * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
94
+ * https://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
94
95
 
95
96
  #ifdef __clang_analyzer__
96
97
  ZSTD_memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
@@ -191,7 +192,7 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
191
192
  break;
192
193
  default :
193
194
  assert(normalizedCounter[s] > 1);
194
- { U32 const maxBitsOut = tableLog - BIT_highbit32 ((U32)normalizedCounter[s]-1);
195
+ { U32 const maxBitsOut = tableLog - ZSTD_highbit32 ((U32)normalizedCounter[s]-1);
195
196
  U32 const minStatePlus = (U32)normalizedCounter[s] << maxBitsOut;
196
197
  symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
197
198
  symbolTT[s].deltaFindState = (int)(total - (unsigned)normalizedCounter[s]);
@@ -342,21 +343,11 @@ size_t FSE_writeNCount (void* buffer, size_t bufferSize,
342
343
  * FSE Compression Code
343
344
  ****************************************************************/
344
345
 
345
- FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog)
346
- {
347
- size_t size;
348
- if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
349
- size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
350
- return (FSE_CTable*)ZSTD_malloc(size);
351
- }
352
-
353
- void FSE_freeCTable (FSE_CTable* ct) { ZSTD_free(ct); }
354
-
355
346
  /* provides the minimum logSize to safely represent a distribution */
356
347
  static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
357
348
  {
358
- U32 minBitsSrc = BIT_highbit32((U32)(srcSize)) + 1;
359
- U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2;
349
+ U32 minBitsSrc = ZSTD_highbit32((U32)(srcSize)) + 1;
350
+ U32 minBitsSymbols = ZSTD_highbit32(maxSymbolValue) + 2;
360
351
  U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
361
352
  assert(srcSize > 1); /* Not supported, RLE should be used instead */
362
353
  return minBits;
@@ -364,7 +355,7 @@ static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
364
355
 
365
356
  unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
366
357
  {
367
- U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
358
+ U32 maxBitsSrc = ZSTD_highbit32((U32)(srcSize - 1)) - minus;
368
359
  U32 tableLog = maxTableLog;
369
360
  U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
370
361
  assert(srcSize > 1); /* Not supported, RLE should be used instead */
@@ -532,40 +523,6 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
532
523
  return tableLog;
533
524
  }
534
525
 
535
-
536
- /* fake FSE_CTable, for raw (uncompressed) input */
537
- size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits)
538
- {
539
- const unsigned tableSize = 1 << nbBits;
540
- const unsigned tableMask = tableSize - 1;
541
- const unsigned maxSymbolValue = tableMask;
542
- void* const ptr = ct;
543
- U16* const tableU16 = ( (U16*) ptr) + 2;
544
- void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableSize>>1); /* assumption : tableLog >= 1 */
545
- FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
546
- unsigned s;
547
-
548
- /* Sanity checks */
549
- if (nbBits < 1) return ERROR(GENERIC); /* min size */
550
-
551
- /* header */
552
- tableU16[-2] = (U16) nbBits;
553
- tableU16[-1] = (U16) maxSymbolValue;
554
-
555
- /* Build table */
556
- for (s=0; s<tableSize; s++)
557
- tableU16[s] = (U16)(tableSize + s);
558
-
559
- /* Build Symbol Transformation Table */
560
- { const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits);
561
- for (s=0; s<=maxSymbolValue; s++) {
562
- symbolTT[s].deltaNbBits = deltaNbBits;
563
- symbolTT[s].deltaFindState = s-1;
564
- } }
565
-
566
- return 0;
567
- }
568
-
569
526
  /* fake FSE_CTable, for rle input (always same symbol) */
570
527
  size_t FSE_buildCTable_rle (FSE_CTable* ct, BYTE symbolValue)
571
528
  {
@@ -664,78 +621,4 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
664
621
 
665
622
  size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
666
623
 
667
- #ifndef ZSTD_NO_UNUSED_FUNCTIONS
668
- /* FSE_compress_wksp() :
669
- * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
670
- * `wkspSize` size must be `(1<<tableLog)`.
671
- */
672
- size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
673
- {
674
- BYTE* const ostart = (BYTE*) dst;
675
- BYTE* op = ostart;
676
- BYTE* const oend = ostart + dstSize;
677
-
678
- unsigned count[FSE_MAX_SYMBOL_VALUE+1];
679
- S16 norm[FSE_MAX_SYMBOL_VALUE+1];
680
- FSE_CTable* CTable = (FSE_CTable*)workSpace;
681
- size_t const CTableSize = FSE_CTABLE_SIZE_U32(tableLog, maxSymbolValue);
682
- void* scratchBuffer = (void*)(CTable + CTableSize);
683
- size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable));
684
-
685
- /* init conditions */
686
- if (wkspSize < FSE_COMPRESS_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
687
- if (srcSize <= 1) return 0; /* Not compressible */
688
- if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
689
- if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
690
-
691
- /* Scan input and build symbol stats */
692
- { CHECK_V_F(maxCount, HIST_count_wksp(count, &maxSymbolValue, src, srcSize, scratchBuffer, scratchBufferSize) );
693
- if (maxCount == srcSize) return 1; /* only a single symbol in src : rle */
694
- if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */
695
- if (maxCount < (srcSize >> 7)) return 0; /* Heuristic : not compressible enough */
696
- }
697
-
698
- tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
699
- CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue, /* useLowProbCount */ srcSize >= 2048) );
700
-
701
- /* Write table description header */
702
- { CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
703
- op += nc_err;
704
- }
705
-
706
- /* Compress */
707
- CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
708
- { CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) );
709
- if (cSize == 0) return 0; /* not enough space for compressed data */
710
- op += cSize;
711
- }
712
-
713
- /* check compressibility */
714
- if ( (size_t)(op-ostart) >= srcSize-1 ) return 0;
715
-
716
- return op-ostart;
717
- }
718
-
719
- typedef struct {
720
- FSE_CTable CTable_max[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
721
- union {
722
- U32 hist_wksp[HIST_WKSP_SIZE_U32];
723
- BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
724
- } workspace;
725
- } fseWkspMax_t;
726
-
727
- size_t FSE_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
728
- {
729
- fseWkspMax_t scratchBuffer;
730
- DEBUG_STATIC_ASSERT(sizeof(scratchBuffer) >= FSE_COMPRESS_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)); /* compilation failures here means scratchBuffer is not large enough */
731
- if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
732
- return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer));
733
- }
734
-
735
- size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
736
- {
737
- return FSE_compress2(dst, dstCapacity, src, srcSize, FSE_MAX_SYMBOL_VALUE, FSE_DEFAULT_TABLELOG);
738
- }
739
- #endif
740
-
741
624
  #endif /* FSE_COMMONDEFS_ONLY */
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * hist : Histogram functions
3
3
  * part of Finite State Entropy project
4
- * Copyright (c) Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * hist : Histogram functions
3
3
  * part of Finite State Entropy project
4
- * Copyright (c) Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy