zstdlib 0.13.0-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/CHANGES.md +107 -0
  4. data/Gemfile +3 -0
  5. data/README.md +107 -0
  6. data/Rakefile +59 -0
  7. data/ext/zstdlib_c/extconf.rb +59 -0
  8. data/ext/zstdlib_c/ruby/zlib-2.2/zstdlib.c +4675 -0
  9. data/ext/zstdlib_c/ruby/zlib-2.3/zstdlib.c +4702 -0
  10. data/ext/zstdlib_c/ruby/zlib-2.4/zstdlib.c +4859 -0
  11. data/ext/zstdlib_c/ruby/zlib-2.5/zstdlib.c +4864 -0
  12. data/ext/zstdlib_c/ruby/zlib-2.6/zstdlib.c +4906 -0
  13. data/ext/zstdlib_c/ruby/zlib-2.7/zstdlib.c +4895 -0
  14. data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
  15. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  16. data/ext/zstdlib_c/ruby/zlib-3.2/zstdlib.c +5090 -0
  17. data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
  18. data/ext/zstdlib_c/zlib-1.3.1/adler32.c +164 -0
  19. data/ext/zstdlib_c/zlib-1.3.1/compress.c +75 -0
  20. data/ext/zstdlib_c/zlib-1.3.1/crc32.c +1049 -0
  21. data/ext/zstdlib_c/zlib-1.3.1/crc32.h +9446 -0
  22. data/ext/zstdlib_c/zlib-1.3.1/deflate.c +2139 -0
  23. data/ext/zstdlib_c/zlib-1.3.1/deflate.h +377 -0
  24. data/ext/zstdlib_c/zlib-1.3.1/gzclose.c +23 -0
  25. data/ext/zstdlib_c/zlib-1.3.1/gzguts.h +214 -0
  26. data/ext/zstdlib_c/zlib-1.3.1/gzlib.c +582 -0
  27. data/ext/zstdlib_c/zlib-1.3.1/gzread.c +602 -0
  28. data/ext/zstdlib_c/zlib-1.3.1/gzwrite.c +631 -0
  29. data/ext/zstdlib_c/zlib-1.3.1/infback.c +628 -0
  30. data/ext/zstdlib_c/zlib-1.3.1/inffast.c +320 -0
  31. data/ext/zstdlib_c/zlib-1.3.1/inffast.h +11 -0
  32. data/ext/zstdlib_c/zlib-1.3.1/inffixed.h +94 -0
  33. data/ext/zstdlib_c/zlib-1.3.1/inflate.c +1526 -0
  34. data/ext/zstdlib_c/zlib-1.3.1/inflate.h +126 -0
  35. data/ext/zstdlib_c/zlib-1.3.1/inftrees.c +299 -0
  36. data/ext/zstdlib_c/zlib-1.3.1/inftrees.h +62 -0
  37. data/ext/zstdlib_c/zlib-1.3.1/trees.c +1117 -0
  38. data/ext/zstdlib_c/zlib-1.3.1/trees.h +128 -0
  39. data/ext/zstdlib_c/zlib-1.3.1/uncompr.c +85 -0
  40. data/ext/zstdlib_c/zlib-1.3.1/zconf.h +543 -0
  41. data/ext/zstdlib_c/zlib-1.3.1/zlib.h +1938 -0
  42. data/ext/zstdlib_c/zlib-1.3.1/zutil.c +299 -0
  43. data/ext/zstdlib_c/zlib-1.3.1/zutil.h +254 -0
  44. data/ext/zstdlib_c/zlib.mk +14 -0
  45. data/ext/zstdlib_c/zlibwrapper/zlibwrapper.c +10 -0
  46. data/ext/zstdlib_c/zlibwrapper.mk +14 -0
  47. data/ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h +55 -0
  48. data/ext/zstdlib_c/zstd-1.5.6/lib/common/bits.h +200 -0
  49. data/ext/zstdlib_c/zstd-1.5.6/lib/common/bitstream.h +457 -0
  50. data/ext/zstdlib_c/zstd-1.5.6/lib/common/compiler.h +450 -0
  51. data/ext/zstdlib_c/zstd-1.5.6/lib/common/cpu.h +249 -0
  52. data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.c +30 -0
  53. data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.h +116 -0
  54. data/ext/zstdlib_c/zstd-1.5.6/lib/common/entropy_common.c +340 -0
  55. data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.c +63 -0
  56. data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.h +168 -0
  57. data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse.h +640 -0
  58. data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse_decompress.c +313 -0
  59. data/ext/zstdlib_c/zstd-1.5.6/lib/common/huf.h +286 -0
  60. data/ext/zstdlib_c/zstd-1.5.6/lib/common/mem.h +426 -0
  61. data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.c +371 -0
  62. data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.h +90 -0
  63. data/ext/zstdlib_c/zstd-1.5.6/lib/common/portability_macros.h +158 -0
  64. data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.c +182 -0
  65. data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.h +150 -0
  66. data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.c +18 -0
  67. data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.h +7020 -0
  68. data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_common.c +48 -0
  69. data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_deps.h +111 -0
  70. data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_internal.h +392 -0
  71. data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_trace.h +163 -0
  72. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/clevels.h +134 -0
  73. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/fse_compress.c +625 -0
  74. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.c +181 -0
  75. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.h +75 -0
  76. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/huf_compress.c +1464 -0
  77. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress.c +7153 -0
  78. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_internal.h +1534 -0
  79. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.c +235 -0
  80. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.h +39 -0
  81. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.c +442 -0
  82. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.h +54 -0
  83. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.c +688 -0
  84. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.h +32 -0
  85. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_cwksp.h +748 -0
  86. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.c +770 -0
  87. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.h +50 -0
  88. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.c +968 -0
  89. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.h +38 -0
  90. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.c +2199 -0
  91. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.h +202 -0
  92. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.c +730 -0
  93. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.h +117 -0
  94. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm_geartab.h +106 -0
  95. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.c +1576 -0
  96. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.h +80 -0
  97. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.c +1882 -0
  98. data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.h +113 -0
  99. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress.c +1944 -0
  100. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress_amd64.S +595 -0
  101. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.c +244 -0
  102. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.h +44 -0
  103. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress.c +2407 -0
  104. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.c +2215 -0
  105. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.h +73 -0
  106. data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_internal.h +240 -0
  107. data/ext/zstdlib_c/zstd-1.5.6/lib/zdict.h +474 -0
  108. data/ext/zstdlib_c/zstd-1.5.6/lib/zstd.h +3089 -0
  109. data/ext/zstdlib_c/zstd-1.5.6/lib/zstd_errors.h +114 -0
  110. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzclose.c +26 -0
  111. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzcompatibility.h +68 -0
  112. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzguts.h +229 -0
  113. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzlib.c +587 -0
  114. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzread.c +637 -0
  115. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzwrite.c +631 -0
  116. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.c +1200 -0
  117. data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.h +91 -0
  118. data/ext/zstdlib_c/zstd.mk +15 -0
  119. data/lib/2.4/zstdlib_c.so +0 -0
  120. data/lib/2.5/zstdlib_c.so +0 -0
  121. data/lib/2.6/zstdlib_c.so +0 -0
  122. data/lib/2.7/zstdlib_c.so +0 -0
  123. data/lib/3.0/zstdlib_c.so +0 -0
  124. data/lib/3.1/zstdlib_c.so +0 -0
  125. data/lib/3.2/zstdlib_c.so +0 -0
  126. data/lib/3.3/zstdlib_c.so +0 -0
  127. data/lib/zstdlib.rb +6 -0
  128. data/test/zstdlib_test.rb +21 -0
  129. metadata +243 -0
@@ -0,0 +1,30 @@
1
+ /* ******************************************************************
2
+ * debug
3
+ * Part of FSE library
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
13
+ ****************************************************************** */
14
+
15
+
16
+ /*
17
+ * This module only hosts one global variable
18
+ * which can be used to dynamically influence the verbosity of traces,
19
+ * such as DEBUGLOG and RAWLOG
20
+ */
21
+
22
+ #include "debug.h"
23
+
24
+ #if !defined(ZSTD_LINUX_KERNEL) || (DEBUGLEVEL>=2)
25
+ /* We only use this when DEBUGLEVEL>=2, but we get -Werror=pedantic errors if a
26
+ * translation unit is empty. So remove this from Linux kernel builds, but
27
+ * otherwise just leave it in.
28
+ */
29
+ int g_debuglevel = DEBUGLEVEL;
30
+ #endif
@@ -0,0 +1,116 @@
1
+ /* ******************************************************************
2
+ * debug
3
+ * Part of FSE library
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
13
+ ****************************************************************** */
14
+
15
+
16
+ /*
17
+ * The purpose of this header is to enable debug functions.
18
+ * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
19
+ * and DEBUG_STATIC_ASSERT() for compile-time.
20
+ *
21
+ * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
22
+ *
23
+ * Level 1 enables assert() only.
24
+ * Starting level 2, traces can be generated and pushed to stderr.
25
+ * The higher the level, the more verbose the traces.
26
+ *
27
+ * It's possible to dynamically adjust level using variable g_debug_level,
28
+ * which is only declared if DEBUGLEVEL>=2,
29
+ * and is a global variable, not multi-thread protected (use with care)
30
+ */
31
+
32
+ #ifndef DEBUG_H_12987983217
33
+ #define DEBUG_H_12987983217
34
+
35
+ #if defined (__cplusplus)
36
+ extern "C" {
37
+ #endif
38
+
39
+
40
+ /* static assert is triggered at compile time, leaving no runtime artefact.
41
+ * static assert only works with compile-time constants.
42
+ * Also, this variant can only be used inside a function. */
43
+ #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
44
+
45
+
46
+ /* DEBUGLEVEL is expected to be defined externally,
47
+ * typically through compiler command line.
48
+ * Value must be a number. */
49
+ #ifndef DEBUGLEVEL
50
+ # define DEBUGLEVEL 0
51
+ #endif
52
+
53
+
54
+ /* recommended values for DEBUGLEVEL :
55
+ * 0 : release mode, no debug, all run-time checks disabled
56
+ * 1 : enables assert() only, no display
57
+ * 2 : reserved, for currently active debug path
58
+ * 3 : events once per object lifetime (CCtx, CDict, etc.)
59
+ * 4 : events once per frame
60
+ * 5 : events once per block
61
+ * 6 : events once per sequence (verbose)
62
+ * 7+: events at every position (*very* verbose)
63
+ *
64
+ * It's generally inconvenient to output traces > 5.
65
+ * In which case, it's possible to selectively trigger high verbosity levels
66
+ * by modifying g_debug_level.
67
+ */
68
+
69
+ #if (DEBUGLEVEL>=1)
70
+ # define ZSTD_DEPS_NEED_ASSERT
71
+ # include "zstd_deps.h"
72
+ #else
73
+ # ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
74
+ # define assert(condition) ((void)0) /* disable assert (default) */
75
+ # endif
76
+ #endif
77
+
78
+ #if (DEBUGLEVEL>=2)
79
+ # define ZSTD_DEPS_NEED_IO
80
+ # include "zstd_deps.h"
81
+ extern int g_debuglevel; /* the variable is only declared,
82
+ it actually lives in debug.c,
83
+ and is shared by the whole process.
84
+ It's not thread-safe.
85
+ It's useful when enabling very verbose levels
86
+ on selective conditions (such as position in src) */
87
+
88
+ # define RAWLOG(l, ...) \
89
+ do { \
90
+ if (l<=g_debuglevel) { \
91
+ ZSTD_DEBUG_PRINT(__VA_ARGS__); \
92
+ } \
93
+ } while (0)
94
+
95
+ #define STRINGIFY(x) #x
96
+ #define TOSTRING(x) STRINGIFY(x)
97
+ #define LINE_AS_STRING TOSTRING(__LINE__)
98
+
99
+ # define DEBUGLOG(l, ...) \
100
+ do { \
101
+ if (l<=g_debuglevel) { \
102
+ ZSTD_DEBUG_PRINT(__FILE__ ":" LINE_AS_STRING ": " __VA_ARGS__); \
103
+ ZSTD_DEBUG_PRINT(" \n"); \
104
+ } \
105
+ } while (0)
106
+ #else
107
+ # define RAWLOG(l, ...) do { } while (0) /* disabled */
108
+ # define DEBUGLOG(l, ...) do { } while (0) /* disabled */
109
+ #endif
110
+
111
+
112
+ #if defined (__cplusplus)
113
+ }
114
+ #endif
115
+
116
+ #endif /* DEBUG_H_12987983217 */
@@ -0,0 +1,340 @@
1
+ /* ******************************************************************
2
+ * Common functions of New Generation Entropy library
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * You can contact the author at :
6
+ * - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
7
+ * - Public forum : https://groups.google.com/forum/#!forum/lz4c
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
13
+ ****************************************************************** */
14
+
15
+ /* *************************************
16
+ * Dependencies
17
+ ***************************************/
18
+ #include "mem.h"
19
+ #include "error_private.h" /* ERR_*, ERROR */
20
+ #define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
21
+ #include "fse.h"
22
+ #include "huf.h"
23
+ #include "bits.h" /* ZSDT_highbit32, ZSTD_countTrailingZeros32 */
24
+
25
+
26
+ /*=== Version ===*/
27
+ unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; }
28
+
29
+
30
+ /*=== Error Management ===*/
31
+ unsigned FSE_isError(size_t code) { return ERR_isError(code); }
32
+ const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
33
+
34
+ unsigned HUF_isError(size_t code) { return ERR_isError(code); }
35
+ const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
36
+
37
+
38
+ /*-**************************************************************
39
+ * FSE NCount encoding-decoding
40
+ ****************************************************************/
41
+ FORCE_INLINE_TEMPLATE
42
+ size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
43
+ const void* headerBuffer, size_t hbSize)
44
+ {
45
+ const BYTE* const istart = (const BYTE*) headerBuffer;
46
+ const BYTE* const iend = istart + hbSize;
47
+ const BYTE* ip = istart;
48
+ int nbBits;
49
+ int remaining;
50
+ int threshold;
51
+ U32 bitStream;
52
+ int bitCount;
53
+ unsigned charnum = 0;
54
+ unsigned const maxSV1 = *maxSVPtr + 1;
55
+ int previous0 = 0;
56
+
57
+ if (hbSize < 8) {
58
+ /* This function only works when hbSize >= 8 */
59
+ char buffer[8] = {0};
60
+ ZSTD_memcpy(buffer, headerBuffer, hbSize);
61
+ { size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
62
+ buffer, sizeof(buffer));
63
+ if (FSE_isError(countSize)) return countSize;
64
+ if (countSize > hbSize) return ERROR(corruption_detected);
65
+ return countSize;
66
+ } }
67
+ assert(hbSize >= 8);
68
+
69
+ /* init */
70
+ ZSTD_memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
71
+ bitStream = MEM_readLE32(ip);
72
+ nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
73
+ if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
74
+ bitStream >>= 4;
75
+ bitCount = 4;
76
+ *tableLogPtr = nbBits;
77
+ remaining = (1<<nbBits)+1;
78
+ threshold = 1<<nbBits;
79
+ nbBits++;
80
+
81
+ for (;;) {
82
+ if (previous0) {
83
+ /* Count the number of repeats. Each time the
84
+ * 2-bit repeat code is 0b11 there is another
85
+ * repeat.
86
+ * Avoid UB by setting the high bit to 1.
87
+ */
88
+ int repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
89
+ while (repeats >= 12) {
90
+ charnum += 3 * 12;
91
+ if (LIKELY(ip <= iend-7)) {
92
+ ip += 3;
93
+ } else {
94
+ bitCount -= (int)(8 * (iend - 7 - ip));
95
+ bitCount &= 31;
96
+ ip = iend - 4;
97
+ }
98
+ bitStream = MEM_readLE32(ip) >> bitCount;
99
+ repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
100
+ }
101
+ charnum += 3 * repeats;
102
+ bitStream >>= 2 * repeats;
103
+ bitCount += 2 * repeats;
104
+
105
+ /* Add the final repeat which isn't 0b11. */
106
+ assert((bitStream & 3) < 3);
107
+ charnum += bitStream & 3;
108
+ bitCount += 2;
109
+
110
+ /* This is an error, but break and return an error
111
+ * at the end, because returning out of a loop makes
112
+ * it harder for the compiler to optimize.
113
+ */
114
+ if (charnum >= maxSV1) break;
115
+
116
+ /* We don't need to set the normalized count to 0
117
+ * because we already memset the whole buffer to 0.
118
+ */
119
+
120
+ if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
121
+ assert((bitCount >> 3) <= 3); /* For first condition to work */
122
+ ip += bitCount>>3;
123
+ bitCount &= 7;
124
+ } else {
125
+ bitCount -= (int)(8 * (iend - 4 - ip));
126
+ bitCount &= 31;
127
+ ip = iend - 4;
128
+ }
129
+ bitStream = MEM_readLE32(ip) >> bitCount;
130
+ }
131
+ {
132
+ int const max = (2*threshold-1) - remaining;
133
+ int count;
134
+
135
+ if ((bitStream & (threshold-1)) < (U32)max) {
136
+ count = bitStream & (threshold-1);
137
+ bitCount += nbBits-1;
138
+ } else {
139
+ count = bitStream & (2*threshold-1);
140
+ if (count >= threshold) count -= max;
141
+ bitCount += nbBits;
142
+ }
143
+
144
+ count--; /* extra accuracy */
145
+ /* When it matters (small blocks), this is a
146
+ * predictable branch, because we don't use -1.
147
+ */
148
+ if (count >= 0) {
149
+ remaining -= count;
150
+ } else {
151
+ assert(count == -1);
152
+ remaining += count;
153
+ }
154
+ normalizedCounter[charnum++] = (short)count;
155
+ previous0 = !count;
156
+
157
+ assert(threshold > 1);
158
+ if (remaining < threshold) {
159
+ /* This branch can be folded into the
160
+ * threshold update condition because we
161
+ * know that threshold > 1.
162
+ */
163
+ if (remaining <= 1) break;
164
+ nbBits = ZSTD_highbit32(remaining) + 1;
165
+ threshold = 1 << (nbBits - 1);
166
+ }
167
+ if (charnum >= maxSV1) break;
168
+
169
+ if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
170
+ ip += bitCount>>3;
171
+ bitCount &= 7;
172
+ } else {
173
+ bitCount -= (int)(8 * (iend - 4 - ip));
174
+ bitCount &= 31;
175
+ ip = iend - 4;
176
+ }
177
+ bitStream = MEM_readLE32(ip) >> bitCount;
178
+ } }
179
+ if (remaining != 1) return ERROR(corruption_detected);
180
+ /* Only possible when there are too many zeros. */
181
+ if (charnum > maxSV1) return ERROR(maxSymbolValue_tooSmall);
182
+ if (bitCount > 32) return ERROR(corruption_detected);
183
+ *maxSVPtr = charnum-1;
184
+
185
+ ip += (bitCount+7)>>3;
186
+ return ip-istart;
187
+ }
188
+
189
+ /* Avoids the FORCE_INLINE of the _body() function. */
190
+ static size_t FSE_readNCount_body_default(
191
+ short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
192
+ const void* headerBuffer, size_t hbSize)
193
+ {
194
+ return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
195
+ }
196
+
197
+ #if DYNAMIC_BMI2
198
+ BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
199
+ short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
200
+ const void* headerBuffer, size_t hbSize)
201
+ {
202
+ return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
203
+ }
204
+ #endif
205
+
206
+ size_t FSE_readNCount_bmi2(
207
+ short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
208
+ const void* headerBuffer, size_t hbSize, int bmi2)
209
+ {
210
+ #if DYNAMIC_BMI2
211
+ if (bmi2) {
212
+ return FSE_readNCount_body_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
213
+ }
214
+ #endif
215
+ (void)bmi2;
216
+ return FSE_readNCount_body_default(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
217
+ }
218
+
219
+ size_t FSE_readNCount(
220
+ short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
221
+ const void* headerBuffer, size_t hbSize)
222
+ {
223
+ return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, /* bmi2 */ 0);
224
+ }
225
+
226
+
227
+ /*! HUF_readStats() :
228
+ Read compact Huffman tree, saved by HUF_writeCTable().
229
+ `huffWeight` is destination buffer.
230
+ `rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
231
+ @return : size read from `src` , or an error Code .
232
+ Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
233
+ */
234
+ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
235
+ U32* nbSymbolsPtr, U32* tableLogPtr,
236
+ const void* src, size_t srcSize)
237
+ {
238
+ U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
239
+ return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* flags */ 0);
240
+ }
241
+
242
+ FORCE_INLINE_TEMPLATE size_t
243
+ HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
244
+ U32* nbSymbolsPtr, U32* tableLogPtr,
245
+ const void* src, size_t srcSize,
246
+ void* workSpace, size_t wkspSize,
247
+ int bmi2)
248
+ {
249
+ U32 weightTotal;
250
+ const BYTE* ip = (const BYTE*) src;
251
+ size_t iSize;
252
+ size_t oSize;
253
+
254
+ if (!srcSize) return ERROR(srcSize_wrong);
255
+ iSize = ip[0];
256
+ /* ZSTD_memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
257
+
258
+ if (iSize >= 128) { /* special header */
259
+ oSize = iSize - 127;
260
+ iSize = ((oSize+1)/2);
261
+ if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
262
+ if (oSize >= hwSize) return ERROR(corruption_detected);
263
+ ip += 1;
264
+ { U32 n;
265
+ for (n=0; n<oSize; n+=2) {
266
+ huffWeight[n] = ip[n/2] >> 4;
267
+ huffWeight[n+1] = ip[n/2] & 15;
268
+ } } }
269
+ else { /* header compressed with FSE (normal case) */
270
+ if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
271
+ /* max (hwSize-1) values decoded, as last one is implied */
272
+ oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize-1, ip+1, iSize, 6, workSpace, wkspSize, bmi2);
273
+ if (FSE_isError(oSize)) return oSize;
274
+ }
275
+
276
+ /* collect weight stats */
277
+ ZSTD_memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
278
+ weightTotal = 0;
279
+ { U32 n; for (n=0; n<oSize; n++) {
280
+ if (huffWeight[n] > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
281
+ rankStats[huffWeight[n]]++;
282
+ weightTotal += (1 << huffWeight[n]) >> 1;
283
+ } }
284
+ if (weightTotal == 0) return ERROR(corruption_detected);
285
+
286
+ /* get last non-null symbol weight (implied, total must be 2^n) */
287
+ { U32 const tableLog = ZSTD_highbit32(weightTotal) + 1;
288
+ if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
289
+ *tableLogPtr = tableLog;
290
+ /* determine last weight */
291
+ { U32 const total = 1 << tableLog;
292
+ U32 const rest = total - weightTotal;
293
+ U32 const verif = 1 << ZSTD_highbit32(rest);
294
+ U32 const lastWeight = ZSTD_highbit32(rest) + 1;
295
+ if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
296
+ huffWeight[oSize] = (BYTE)lastWeight;
297
+ rankStats[lastWeight]++;
298
+ } }
299
+
300
+ /* check tree construction validity */
301
+ if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */
302
+
303
+ /* results */
304
+ *nbSymbolsPtr = (U32)(oSize+1);
305
+ return iSize+1;
306
+ }
307
+
308
+ /* Avoids the FORCE_INLINE of the _body() function. */
309
+ static size_t HUF_readStats_body_default(BYTE* huffWeight, size_t hwSize, U32* rankStats,
310
+ U32* nbSymbolsPtr, U32* tableLogPtr,
311
+ const void* src, size_t srcSize,
312
+ void* workSpace, size_t wkspSize)
313
+ {
314
+ return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 0);
315
+ }
316
+
317
+ #if DYNAMIC_BMI2
318
+ static BMI2_TARGET_ATTRIBUTE size_t HUF_readStats_body_bmi2(BYTE* huffWeight, size_t hwSize, U32* rankStats,
319
+ U32* nbSymbolsPtr, U32* tableLogPtr,
320
+ const void* src, size_t srcSize,
321
+ void* workSpace, size_t wkspSize)
322
+ {
323
+ return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 1);
324
+ }
325
+ #endif
326
+
327
+ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
328
+ U32* nbSymbolsPtr, U32* tableLogPtr,
329
+ const void* src, size_t srcSize,
330
+ void* workSpace, size_t wkspSize,
331
+ int flags)
332
+ {
333
+ #if DYNAMIC_BMI2
334
+ if (flags & HUF_flags_bmi2) {
335
+ return HUF_readStats_body_bmi2(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
336
+ }
337
+ #endif
338
+ (void)flags;
339
+ return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
340
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
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
+ */
10
+
11
+ /* The purpose of this file is to have a single list of error strings embedded in binary */
12
+
13
+ #include "error_private.h"
14
+
15
+ const char* ERR_getErrorString(ERR_enum code)
16
+ {
17
+ #ifdef ZSTD_STRIP_ERROR_STRINGS
18
+ (void)code;
19
+ return "Error strings stripped";
20
+ #else
21
+ static const char* const notErrorCode = "Unspecified error code";
22
+ switch( code )
23
+ {
24
+ case PREFIX(no_error): return "No error detected";
25
+ case PREFIX(GENERIC): return "Error (generic)";
26
+ case PREFIX(prefix_unknown): return "Unknown frame descriptor";
27
+ case PREFIX(version_unsupported): return "Version not supported";
28
+ case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
29
+ case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
30
+ case PREFIX(corruption_detected): return "Data corruption detected";
31
+ case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
32
+ case PREFIX(literals_headerWrong): return "Header of Literals' block doesn't respect format specification";
33
+ case PREFIX(parameter_unsupported): return "Unsupported parameter";
34
+ case PREFIX(parameter_combination_unsupported): return "Unsupported combination of parameters";
35
+ case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
36
+ case PREFIX(init_missing): return "Context should be init first";
37
+ case PREFIX(memory_allocation): return "Allocation error : not enough memory";
38
+ case PREFIX(workSpace_tooSmall): return "workSpace buffer is not large enough";
39
+ case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
40
+ case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
41
+ case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
42
+ case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
43
+ case PREFIX(stabilityCondition_notRespected): return "pledged buffer stability condition is not respected";
44
+ case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
45
+ case PREFIX(dictionary_wrong): return "Dictionary mismatch";
46
+ case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
47
+ case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
48
+ case PREFIX(srcSize_wrong): return "Src size is incorrect";
49
+ case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
50
+ case PREFIX(noForwardProgress_destFull): return "Operation made no progress over multiple calls, due to output buffer being full";
51
+ case PREFIX(noForwardProgress_inputEmpty): return "Operation made no progress over multiple calls, due to input being empty";
52
+ /* following error codes are not stable and may be removed or changed in a future version */
53
+ case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
54
+ case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
55
+ case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
56
+ case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
57
+ case PREFIX(sequenceProducer_failed): return "Block-level external sequence producer returned an error code";
58
+ case PREFIX(externalSequences_invalid): return "External sequences are not valid";
59
+ case PREFIX(maxCode):
60
+ default: return notErrorCode;
61
+ }
62
+ #endif
63
+ }