zstdlib 0.7.0-x86-mingw32 → 0.10.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +20 -0
  3. data/README.md +7 -1
  4. data/Rakefile +38 -8
  5. data/ext/{zstdlib → zstdlib_c}/extconf.rb +11 -6
  6. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
  7. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
  8. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
  9. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
  10. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
  11. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
  12. data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
  13. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  14. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/adler32.c +0 -0
  15. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/compress.c +0 -0
  16. data/ext/zstdlib_c/zlib-1.2.12/crc32.c +1116 -0
  17. data/ext/zstdlib_c/zlib-1.2.12/crc32.h +9446 -0
  18. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.c +78 -30
  19. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.h +12 -15
  20. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzclose.c +0 -0
  21. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzguts.h +3 -2
  22. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzlib.c +5 -3
  23. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzread.c +5 -7
  24. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzwrite.c +25 -13
  25. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/infback.c +2 -1
  26. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.c +14 -14
  27. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.h +0 -0
  28. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffixed.h +0 -0
  29. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.c +39 -8
  30. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.h +3 -2
  31. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.c +3 -3
  32. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.h +0 -0
  33. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.c +27 -48
  34. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.h +0 -0
  35. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/uncompr.c +0 -0
  36. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zconf.h +0 -0
  37. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zlib.h +123 -100
  38. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.c +2 -2
  39. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.h +12 -9
  40. data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
  41. data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
  42. data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
  43. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +46 -22
  44. data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
  45. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
  46. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.c +1 -1
  47. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +12 -19
  48. data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
  49. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +2 -1
  50. data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
  51. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +41 -12
  52. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +139 -22
  53. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +47 -23
  54. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
  55. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
  56. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +4 -4
  57. data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
  58. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +6 -5
  59. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +0 -0
  60. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
  61. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
  62. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
  63. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
  64. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_internal.h +191 -145
  65. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
  66. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
  67. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +89 -46
  68. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +27 -29
  69. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +2 -2
  70. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
  71. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress.c +2917 -868
  72. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +458 -125
  73. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +12 -11
  74. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
  75. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +41 -18
  76. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +1 -1
  77. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.c +26 -298
  78. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.h +1 -1
  79. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +234 -83
  80. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +313 -138
  81. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +1 -1
  82. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +329 -150
  83. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +1 -1
  84. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
  85. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
  86. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +321 -216
  87. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +9 -2
  88. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
  89. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +412 -166
  90. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
  91. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +169 -453
  92. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
  93. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/huf_decompress.c +1044 -403
  94. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
  95. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +9 -9
  96. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +2 -2
  97. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +450 -105
  98. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.c +913 -273
  99. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +14 -5
  100. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +59 -12
  101. data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
  102. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +699 -214
  103. data/ext/{zstdlib/zstd-1.4.5/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +2 -1
  104. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
  105. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
  106. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
  107. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
  108. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
  109. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
  110. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
  111. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
  112. data/ext/zstdlib_c/zstd.mk +15 -0
  113. data/lib/2.4/zstdlib_c.so +0 -0
  114. data/lib/2.5/zstdlib_c.so +0 -0
  115. data/lib/2.6/zstdlib_c.so +0 -0
  116. data/lib/2.7/zstdlib_c.so +0 -0
  117. data/lib/3.0/zstdlib_c.so +0 -0
  118. data/lib/3.1/zstdlib_c.so +0 -0
  119. data/lib/zstdlib.rb +2 -2
  120. metadata +125 -116
  121. data/ext/zstdlib/zlib-1.2.11/crc32.c +0 -442
  122. data/ext/zstdlib/zlib-1.2.11/crc32.h +0 -441
  123. data/ext/zstdlib/zstd-1.4.5/lib/common/compiler.h +0 -175
  124. data/ext/zstdlib/zstd-1.4.5/lib/common/entropy_common.c +0 -216
  125. data/ext/zstdlib/zstd-1.4.5/lib/common/error_private.h +0 -80
  126. data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.c +0 -864
  127. data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.h +0 -285
  128. data/ext/zstdlib/zstd-1.4.5/lib/compress/huf_compress.c +0 -798
  129. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.c +0 -1138
  130. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.h +0 -67
  131. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstdmt_compress.h +0 -192
  132. data/ext/zstdlib/zstd.mk +0 -14
  133. data/lib/2.2/zstdlib.so +0 -0
  134. data/lib/2.3/zstdlib.so +0 -0
  135. data/lib/2.4/zstdlib.so +0 -0
  136. data/lib/2.5/zstdlib.so +0 -0
  137. data/lib/2.6/zstdlib.so +0 -0
  138. data/lib/2.7/zstdlib.so +0 -0
@@ -0,0 +1,163 @@
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
+ */
10
+
11
+ #ifndef ZSTD_TRACE_H
12
+ #define ZSTD_TRACE_H
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ #include <stddef.h>
19
+
20
+ /* weak symbol support
21
+ * For now, enable conservatively:
22
+ * - Only GNUC
23
+ * - Only ELF
24
+ * - Only x86-64 and i386
25
+ * Also, explicitly disable on platforms known not to work so they aren't
26
+ * forgotten in the future.
27
+ */
28
+ #if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \
29
+ defined(__GNUC__) && defined(__ELF__) && \
30
+ (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)) && \
31
+ !defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \
32
+ !defined(__CYGWIN__) && !defined(_AIX)
33
+ # define ZSTD_HAVE_WEAK_SYMBOLS 1
34
+ #else
35
+ # define ZSTD_HAVE_WEAK_SYMBOLS 0
36
+ #endif
37
+ #if ZSTD_HAVE_WEAK_SYMBOLS
38
+ # define ZSTD_WEAK_ATTR __attribute__((__weak__))
39
+ #else
40
+ # define ZSTD_WEAK_ATTR
41
+ #endif
42
+
43
+ /* Only enable tracing when weak symbols are available. */
44
+ #ifndef ZSTD_TRACE
45
+ # define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS
46
+ #endif
47
+
48
+ #if ZSTD_TRACE
49
+
50
+ struct ZSTD_CCtx_s;
51
+ struct ZSTD_DCtx_s;
52
+ struct ZSTD_CCtx_params_s;
53
+
54
+ typedef struct {
55
+ /**
56
+ * ZSTD_VERSION_NUMBER
57
+ *
58
+ * This is guaranteed to be the first member of ZSTD_trace.
59
+ * Otherwise, this struct is not stable between versions. If
60
+ * the version number does not match your expectation, you
61
+ * should not interpret the rest of the struct.
62
+ */
63
+ unsigned version;
64
+ /**
65
+ * Non-zero if streaming (de)compression is used.
66
+ */
67
+ unsigned streaming;
68
+ /**
69
+ * The dictionary ID.
70
+ */
71
+ unsigned dictionaryID;
72
+ /**
73
+ * Is the dictionary cold?
74
+ * Only set on decompression.
75
+ */
76
+ unsigned dictionaryIsCold;
77
+ /**
78
+ * The dictionary size or zero if no dictionary.
79
+ */
80
+ size_t dictionarySize;
81
+ /**
82
+ * The uncompressed size of the data.
83
+ */
84
+ size_t uncompressedSize;
85
+ /**
86
+ * The compressed size of the data.
87
+ */
88
+ size_t compressedSize;
89
+ /**
90
+ * The fully resolved CCtx parameters (NULL on decompression).
91
+ */
92
+ struct ZSTD_CCtx_params_s const* params;
93
+ /**
94
+ * The ZSTD_CCtx pointer (NULL on decompression).
95
+ */
96
+ struct ZSTD_CCtx_s const* cctx;
97
+ /**
98
+ * The ZSTD_DCtx pointer (NULL on compression).
99
+ */
100
+ struct ZSTD_DCtx_s const* dctx;
101
+ } ZSTD_Trace;
102
+
103
+ /**
104
+ * A tracing context. It must be 0 when tracing is disabled.
105
+ * Otherwise, any non-zero value returned by a tracing begin()
106
+ * function is presented to any subsequent calls to end().
107
+ *
108
+ * Any non-zero value is treated as tracing is enabled and not
109
+ * interpreted by the library.
110
+ *
111
+ * Two possible uses are:
112
+ * * A timestamp for when the begin() function was called.
113
+ * * A unique key identifying the (de)compression, like the
114
+ * address of the [dc]ctx pointer if you need to track
115
+ * more information than just a timestamp.
116
+ */
117
+ typedef unsigned long long ZSTD_TraceCtx;
118
+
119
+ /**
120
+ * Trace the beginning of a compression call.
121
+ * @param cctx The dctx pointer for the compression.
122
+ * It can be used as a key to map begin() to end().
123
+ * @returns Non-zero if tracing is enabled. The return value is
124
+ * passed to ZSTD_trace_compress_end().
125
+ */
126
+ ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(
127
+ struct ZSTD_CCtx_s const* cctx);
128
+
129
+ /**
130
+ * Trace the end of a compression call.
131
+ * @param ctx The return value of ZSTD_trace_compress_begin().
132
+ * @param trace The zstd tracing info.
133
+ */
134
+ ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(
135
+ ZSTD_TraceCtx ctx,
136
+ ZSTD_Trace const* trace);
137
+
138
+ /**
139
+ * Trace the beginning of a decompression call.
140
+ * @param dctx The dctx pointer for the decompression.
141
+ * It can be used as a key to map begin() to end().
142
+ * @returns Non-zero if tracing is enabled. The return value is
143
+ * passed to ZSTD_trace_compress_end().
144
+ */
145
+ ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(
146
+ struct ZSTD_DCtx_s const* dctx);
147
+
148
+ /**
149
+ * Trace the end of a decompression call.
150
+ * @param ctx The return value of ZSTD_trace_decompress_begin().
151
+ * @param trace The zstd tracing info.
152
+ */
153
+ ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(
154
+ ZSTD_TraceCtx ctx,
155
+ ZSTD_Trace const* trace);
156
+
157
+ #endif /* ZSTD_TRACE */
158
+
159
+ #if defined (__cplusplus)
160
+ }
161
+ #endif
162
+
163
+ #endif /* ZSTD_TRACE_H */
@@ -0,0 +1,134 @@
1
+ /*
2
+ * Copyright (c) Yann Collet, 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
+ */
10
+
11
+ #ifndef ZSTD_CLEVELS_H
12
+ #define ZSTD_CLEVELS_H
13
+
14
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
15
+ #include "../zstd.h"
16
+
17
+ /*-===== Pre-defined compression levels =====-*/
18
+
19
+ #define ZSTD_MAX_CLEVEL 22
20
+
21
+ #ifdef __GNUC__
22
+ __attribute__((__unused__))
23
+ #endif
24
+
25
+ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = {
26
+ { /* "default" - for any srcSize > 256 KB */
27
+ /* W, C, H, S, L, TL, strat */
28
+ { 19, 12, 13, 1, 6, 1, ZSTD_fast }, /* base for negative levels */
29
+ { 19, 13, 14, 1, 7, 0, ZSTD_fast }, /* level 1 */
30
+ { 20, 15, 16, 1, 6, 0, ZSTD_fast }, /* level 2 */
31
+ { 21, 16, 17, 1, 5, 0, ZSTD_dfast }, /* level 3 */
32
+ { 21, 18, 18, 1, 5, 0, ZSTD_dfast }, /* level 4 */
33
+ { 21, 18, 19, 3, 5, 2, ZSTD_greedy }, /* level 5 */
34
+ { 21, 18, 19, 3, 5, 4, ZSTD_lazy }, /* level 6 */
35
+ { 21, 19, 20, 4, 5, 8, ZSTD_lazy }, /* level 7 */
36
+ { 21, 19, 20, 4, 5, 16, ZSTD_lazy2 }, /* level 8 */
37
+ { 22, 20, 21, 4, 5, 16, ZSTD_lazy2 }, /* level 9 */
38
+ { 22, 21, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 10 */
39
+ { 22, 21, 22, 6, 5, 16, ZSTD_lazy2 }, /* level 11 */
40
+ { 22, 22, 23, 6, 5, 32, ZSTD_lazy2 }, /* level 12 */
41
+ { 22, 22, 22, 4, 5, 32, ZSTD_btlazy2 }, /* level 13 */
42
+ { 22, 22, 23, 5, 5, 32, ZSTD_btlazy2 }, /* level 14 */
43
+ { 22, 23, 23, 6, 5, 32, ZSTD_btlazy2 }, /* level 15 */
44
+ { 22, 22, 22, 5, 5, 48, ZSTD_btopt }, /* level 16 */
45
+ { 23, 23, 22, 5, 4, 64, ZSTD_btopt }, /* level 17 */
46
+ { 23, 23, 22, 6, 3, 64, ZSTD_btultra }, /* level 18 */
47
+ { 23, 24, 22, 7, 3,256, ZSTD_btultra2}, /* level 19 */
48
+ { 25, 25, 23, 7, 3,256, ZSTD_btultra2}, /* level 20 */
49
+ { 26, 26, 24, 7, 3,512, ZSTD_btultra2}, /* level 21 */
50
+ { 27, 27, 25, 9, 3,999, ZSTD_btultra2}, /* level 22 */
51
+ },
52
+ { /* for srcSize <= 256 KB */
53
+ /* W, C, H, S, L, T, strat */
54
+ { 18, 12, 13, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
55
+ { 18, 13, 14, 1, 6, 0, ZSTD_fast }, /* level 1 */
56
+ { 18, 14, 14, 1, 5, 0, ZSTD_dfast }, /* level 2 */
57
+ { 18, 16, 16, 1, 4, 0, ZSTD_dfast }, /* level 3 */
58
+ { 18, 16, 17, 3, 5, 2, ZSTD_greedy }, /* level 4.*/
59
+ { 18, 17, 18, 5, 5, 2, ZSTD_greedy }, /* level 5.*/
60
+ { 18, 18, 19, 3, 5, 4, ZSTD_lazy }, /* level 6.*/
61
+ { 18, 18, 19, 4, 4, 4, ZSTD_lazy }, /* level 7 */
62
+ { 18, 18, 19, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
63
+ { 18, 18, 19, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
64
+ { 18, 18, 19, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
65
+ { 18, 18, 19, 5, 4, 12, ZSTD_btlazy2 }, /* level 11.*/
66
+ { 18, 19, 19, 7, 4, 12, ZSTD_btlazy2 }, /* level 12.*/
67
+ { 18, 18, 19, 4, 4, 16, ZSTD_btopt }, /* level 13 */
68
+ { 18, 18, 19, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
69
+ { 18, 18, 19, 6, 3,128, ZSTD_btopt }, /* level 15.*/
70
+ { 18, 19, 19, 6, 3,128, ZSTD_btultra }, /* level 16.*/
71
+ { 18, 19, 19, 8, 3,256, ZSTD_btultra }, /* level 17.*/
72
+ { 18, 19, 19, 6, 3,128, ZSTD_btultra2}, /* level 18.*/
73
+ { 18, 19, 19, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
74
+ { 18, 19, 19, 10, 3,512, ZSTD_btultra2}, /* level 20.*/
75
+ { 18, 19, 19, 12, 3,512, ZSTD_btultra2}, /* level 21.*/
76
+ { 18, 19, 19, 13, 3,999, ZSTD_btultra2}, /* level 22.*/
77
+ },
78
+ { /* for srcSize <= 128 KB */
79
+ /* W, C, H, S, L, T, strat */
80
+ { 17, 12, 12, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
81
+ { 17, 12, 13, 1, 6, 0, ZSTD_fast }, /* level 1 */
82
+ { 17, 13, 15, 1, 5, 0, ZSTD_fast }, /* level 2 */
83
+ { 17, 15, 16, 2, 5, 0, ZSTD_dfast }, /* level 3 */
84
+ { 17, 17, 17, 2, 4, 0, ZSTD_dfast }, /* level 4 */
85
+ { 17, 16, 17, 3, 4, 2, ZSTD_greedy }, /* level 5 */
86
+ { 17, 16, 17, 3, 4, 4, ZSTD_lazy }, /* level 6 */
87
+ { 17, 16, 17, 3, 4, 8, ZSTD_lazy2 }, /* level 7 */
88
+ { 17, 16, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
89
+ { 17, 16, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
90
+ { 17, 16, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
91
+ { 17, 17, 17, 5, 4, 8, ZSTD_btlazy2 }, /* level 11 */
92
+ { 17, 18, 17, 7, 4, 12, ZSTD_btlazy2 }, /* level 12 */
93
+ { 17, 18, 17, 3, 4, 12, ZSTD_btopt }, /* level 13.*/
94
+ { 17, 18, 17, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
95
+ { 17, 18, 17, 6, 3,256, ZSTD_btopt }, /* level 15.*/
96
+ { 17, 18, 17, 6, 3,128, ZSTD_btultra }, /* level 16.*/
97
+ { 17, 18, 17, 8, 3,256, ZSTD_btultra }, /* level 17.*/
98
+ { 17, 18, 17, 10, 3,512, ZSTD_btultra }, /* level 18.*/
99
+ { 17, 18, 17, 5, 3,256, ZSTD_btultra2}, /* level 19.*/
100
+ { 17, 18, 17, 7, 3,512, ZSTD_btultra2}, /* level 20.*/
101
+ { 17, 18, 17, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
102
+ { 17, 18, 17, 11, 3,999, ZSTD_btultra2}, /* level 22.*/
103
+ },
104
+ { /* for srcSize <= 16 KB */
105
+ /* W, C, H, S, L, T, strat */
106
+ { 14, 12, 13, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
107
+ { 14, 14, 15, 1, 5, 0, ZSTD_fast }, /* level 1 */
108
+ { 14, 14, 15, 1, 4, 0, ZSTD_fast }, /* level 2 */
109
+ { 14, 14, 15, 2, 4, 0, ZSTD_dfast }, /* level 3 */
110
+ { 14, 14, 14, 4, 4, 2, ZSTD_greedy }, /* level 4 */
111
+ { 14, 14, 14, 3, 4, 4, ZSTD_lazy }, /* level 5.*/
112
+ { 14, 14, 14, 4, 4, 8, ZSTD_lazy2 }, /* level 6 */
113
+ { 14, 14, 14, 6, 4, 8, ZSTD_lazy2 }, /* level 7 */
114
+ { 14, 14, 14, 8, 4, 8, ZSTD_lazy2 }, /* level 8.*/
115
+ { 14, 15, 14, 5, 4, 8, ZSTD_btlazy2 }, /* level 9.*/
116
+ { 14, 15, 14, 9, 4, 8, ZSTD_btlazy2 }, /* level 10.*/
117
+ { 14, 15, 14, 3, 4, 12, ZSTD_btopt }, /* level 11.*/
118
+ { 14, 15, 14, 4, 3, 24, ZSTD_btopt }, /* level 12.*/
119
+ { 14, 15, 14, 5, 3, 32, ZSTD_btultra }, /* level 13.*/
120
+ { 14, 15, 15, 6, 3, 64, ZSTD_btultra }, /* level 14.*/
121
+ { 14, 15, 15, 7, 3,256, ZSTD_btultra }, /* level 15.*/
122
+ { 14, 15, 15, 5, 3, 48, ZSTD_btultra2}, /* level 16.*/
123
+ { 14, 15, 15, 6, 3,128, ZSTD_btultra2}, /* level 17.*/
124
+ { 14, 15, 15, 7, 3,256, ZSTD_btultra2}, /* level 18.*/
125
+ { 14, 15, 15, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
126
+ { 14, 15, 15, 8, 3,512, ZSTD_btultra2}, /* level 20.*/
127
+ { 14, 15, 15, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
128
+ { 14, 15, 15, 10, 3,999, ZSTD_btultra2}, /* level 22.*/
129
+ },
130
+ };
131
+
132
+
133
+
134
+ #endif /* ZSTD_CLEVELS_H */
@@ -1,6 +1,6 @@
1
1
  /* ******************************************************************
2
2
  * FSE : Finite State Entropy encoder
3
- * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
3
+ * Copyright (c) Yann Collet, Facebook, Inc.
4
4
  *
5
5
  * You can contact the author at :
6
6
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -15,8 +15,6 @@
15
15
  /* **************************************************************
16
16
  * Includes
17
17
  ****************************************************************/
18
- #include <stdlib.h> /* malloc, free, qsort */
19
- #include <string.h> /* memcpy, memset */
20
18
  #include "../common/compiler.h"
21
19
  #include "../common/mem.h" /* U32, U16, etc. */
22
20
  #include "../common/debug.h" /* assert, DEBUGLOG */
@@ -25,6 +23,9 @@
25
23
  #define FSE_STATIC_LINKING_ONLY
26
24
  #include "../common/fse.h"
27
25
  #include "../common/error_private.h"
26
+ #define ZSTD_DEPS_NEED_MALLOC
27
+ #define ZSTD_DEPS_NEED_MATH64
28
+ #include "../common/zstd_deps.h" /* ZSTD_malloc, ZSTD_free, ZSTD_memcpy, ZSTD_memset */
28
29
 
29
30
 
30
31
  /* **************************************************************
@@ -74,13 +75,16 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
74
75
  void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableLog ? tableSize>>1 : 1) ;
75
76
  FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
76
77
  U32 const step = FSE_TABLESTEP(tableSize);
77
- U32 cumul[FSE_MAX_SYMBOL_VALUE+2];
78
+ U32 const maxSV1 = maxSymbolValue+1;
79
+
80
+ U16* cumul = (U16*)workSpace; /* size = maxSV1 */
81
+ FSE_FUNCTION_TYPE* const tableSymbol = (FSE_FUNCTION_TYPE*)(cumul + (maxSV1+1)); /* size = tableSize */
78
82
 
79
- FSE_FUNCTION_TYPE* const tableSymbol = (FSE_FUNCTION_TYPE*)workSpace;
80
83
  U32 highThreshold = tableSize-1;
81
84
 
85
+ assert(((size_t)workSpace & 1) == 0); /* Must be 2 bytes-aligned */
86
+ if (FSE_BUILD_CTABLE_WORKSPACE_SIZE(maxSymbolValue, tableLog) > wkspSize) return ERROR(tableLog_tooLarge);
82
87
  /* CTable header */
83
- if (((size_t)1 << tableLog) * sizeof(FSE_FUNCTION_TYPE) > wkspSize) return ERROR(tableLog_tooLarge);
84
88
  tableU16[-2] = (U16) tableLog;
85
89
  tableU16[-1] = (U16) maxSymbolValue;
86
90
  assert(tableLog < 16); /* required for threshold strategy to work */
@@ -89,26 +93,67 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
89
93
  * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
90
94
 
91
95
  #ifdef __clang_analyzer__
92
- memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
96
+ ZSTD_memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
93
97
  #endif
94
98
 
95
99
  /* symbol start positions */
96
100
  { U32 u;
97
101
  cumul[0] = 0;
98
- for (u=1; u <= maxSymbolValue+1; u++) {
102
+ for (u=1; u <= maxSV1; u++) {
99
103
  if (normalizedCounter[u-1]==-1) { /* Low proba symbol */
100
104
  cumul[u] = cumul[u-1] + 1;
101
105
  tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1);
102
106
  } else {
103
- cumul[u] = cumul[u-1] + normalizedCounter[u-1];
107
+ assert(normalizedCounter[u-1] >= 0);
108
+ cumul[u] = cumul[u-1] + (U16)normalizedCounter[u-1];
109
+ assert(cumul[u] >= cumul[u-1]); /* no overflow */
104
110
  } }
105
- cumul[maxSymbolValue+1] = tableSize+1;
111
+ cumul[maxSV1] = (U16)(tableSize+1);
106
112
  }
107
113
 
108
114
  /* Spread symbols */
109
- { U32 position = 0;
115
+ if (highThreshold == tableSize - 1) {
116
+ /* Case for no low prob count symbols. Lay down 8 bytes at a time
117
+ * to reduce branch misses since we are operating on a small block
118
+ */
119
+ BYTE* const spread = tableSymbol + tableSize; /* size = tableSize + 8 (may write beyond tableSize) */
120
+ { U64 const add = 0x0101010101010101ull;
121
+ size_t pos = 0;
122
+ U64 sv = 0;
123
+ U32 s;
124
+ for (s=0; s<maxSV1; ++s, sv += add) {
125
+ int i;
126
+ int const n = normalizedCounter[s];
127
+ MEM_write64(spread + pos, sv);
128
+ for (i = 8; i < n; i += 8) {
129
+ MEM_write64(spread + pos + i, sv);
130
+ }
131
+ assert(n>=0);
132
+ pos += (size_t)n;
133
+ }
134
+ }
135
+ /* Spread symbols across the table. Lack of lowprob symbols means that
136
+ * we don't need variable sized inner loop, so we can unroll the loop and
137
+ * reduce branch misses.
138
+ */
139
+ { size_t position = 0;
140
+ size_t s;
141
+ size_t const unroll = 2; /* Experimentally determined optimal unroll */
142
+ assert(tableSize % unroll == 0); /* FSE_MIN_TABLELOG is 5 */
143
+ for (s = 0; s < (size_t)tableSize; s += unroll) {
144
+ size_t u;
145
+ for (u = 0; u < unroll; ++u) {
146
+ size_t const uPosition = (position + (u * step)) & tableMask;
147
+ tableSymbol[uPosition] = spread[s + u];
148
+ }
149
+ position = (position + (unroll * step)) & tableMask;
150
+ }
151
+ assert(position == 0); /* Must have initialized all positions */
152
+ }
153
+ } else {
154
+ U32 position = 0;
110
155
  U32 symbol;
111
- for (symbol=0; symbol<=maxSymbolValue; symbol++) {
156
+ for (symbol=0; symbol<maxSV1; symbol++) {
112
157
  int nbOccurrences;
113
158
  int const freq = normalizedCounter[symbol];
114
159
  for (nbOccurrences=0; nbOccurrences<freq; nbOccurrences++) {
@@ -117,7 +162,6 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
117
162
  while (position > highThreshold)
118
163
  position = (position + step) & tableMask; /* Low proba area */
119
164
  } }
120
-
121
165
  assert(position==0); /* Must have initialized all positions */
122
166
  }
123
167
 
@@ -141,16 +185,17 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
141
185
  case -1:
142
186
  case 1:
143
187
  symbolTT[s].deltaNbBits = (tableLog << 16) - (1<<tableLog);
144
- symbolTT[s].deltaFindState = total - 1;
188
+ assert(total <= INT_MAX);
189
+ symbolTT[s].deltaFindState = (int)(total - 1);
145
190
  total ++;
146
191
  break;
147
192
  default :
148
- {
149
- U32 const maxBitsOut = tableLog - BIT_highbit32 (normalizedCounter[s]-1);
150
- U32 const minStatePlus = normalizedCounter[s] << maxBitsOut;
193
+ assert(normalizedCounter[s] > 1);
194
+ { U32 const maxBitsOut = tableLog - BIT_highbit32 ((U32)normalizedCounter[s]-1);
195
+ U32 const minStatePlus = (U32)normalizedCounter[s] << maxBitsOut;
151
196
  symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
152
- symbolTT[s].deltaFindState = total - normalizedCounter[s];
153
- total += normalizedCounter[s];
197
+ symbolTT[s].deltaFindState = (int)(total - (unsigned)normalizedCounter[s]);
198
+ total += (unsigned)normalizedCounter[s];
154
199
  } } } }
155
200
 
156
201
  #if 0 /* debug : symbol costs */
@@ -161,31 +206,26 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
161
206
  symbol, normalizedCounter[symbol],
162
207
  FSE_getMaxNbBits(symbolTT, symbol),
163
208
  (double)FSE_bitCost(symbolTT, tableLog, symbol, 8) / 256);
164
- }
165
- }
209
+ } }
166
210
  #endif
167
211
 
168
212
  return 0;
169
213
  }
170
214
 
171
215
 
172
- size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
173
- {
174
- FSE_FUNCTION_TYPE tableSymbol[FSE_MAX_TABLESIZE]; /* memset() is not necessary, even if static analyzer complain about it */
175
- return FSE_buildCTable_wksp(ct, normalizedCounter, maxSymbolValue, tableLog, tableSymbol, sizeof(tableSymbol));
176
- }
177
-
178
-
179
216
 
180
217
  #ifndef FSE_COMMONDEFS_ONLY
181
218
 
182
-
183
219
  /*-**************************************************************
184
220
  * FSE NCount encoding
185
221
  ****************************************************************/
186
222
  size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
187
223
  {
188
- size_t const maxHeaderSize = (((maxSymbolValue+1) * tableLog) >> 3) + 3;
224
+ size_t const maxHeaderSize = (((maxSymbolValue+1) * tableLog
225
+ + 4 /* bitCount initialized at 4 */
226
+ + 2 /* first two symbols may use one additional bit each */) / 8)
227
+ + 1 /* round up to whole nb bytes */
228
+ + 2 /* additional two bytes for bitstream flush */;
189
229
  return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
190
230
  }
191
231
 
@@ -307,10 +347,10 @@ FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog)
307
347
  size_t size;
308
348
  if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
309
349
  size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
310
- return (FSE_CTable*)malloc(size);
350
+ return (FSE_CTable*)ZSTD_malloc(size);
311
351
  }
312
352
 
313
- void FSE_freeCTable (FSE_CTable* ct) { free(ct); }
353
+ void FSE_freeCTable (FSE_CTable* ct) { ZSTD_free(ct); }
314
354
 
315
355
  /* provides the minimum logSize to safely represent a distribution */
316
356
  static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
@@ -341,11 +381,10 @@ unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
341
381
  return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 2);
342
382
  }
343
383
 
344
-
345
384
  /* Secondary normalization method.
346
385
  To be used when primary method fails. */
347
386
 
348
- static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue)
387
+ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue, short lowProbCount)
349
388
  {
350
389
  short const NOT_YET_ASSIGNED = -2;
351
390
  U32 s;
@@ -362,7 +401,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
362
401
  continue;
363
402
  }
364
403
  if (count[s] <= lowThreshold) {
365
- norm[s] = -1;
404
+ norm[s] = lowProbCount;
366
405
  distributed++;
367
406
  total -= count[s];
368
407
  continue;
@@ -414,7 +453,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
414
453
 
415
454
  { U64 const vStepLog = 62 - tableLog;
416
455
  U64 const mid = (1ULL << (vStepLog-1)) - 1;
417
- U64 const rStep = ((((U64)1<<vStepLog) * ToDistribute) + mid) / total; /* scale on remaining */
456
+ U64 const rStep = ZSTD_div64((((U64)1<<vStepLog) * ToDistribute) + mid, (U32)total); /* scale on remaining */
418
457
  U64 tmpTotal = mid;
419
458
  for (s=0; s<=maxSymbolValue; s++) {
420
459
  if (norm[s]==NOT_YET_ASSIGNED) {
@@ -431,10 +470,9 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
431
470
  return 0;
432
471
  }
433
472
 
434
-
435
473
  size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
436
474
  const unsigned* count, size_t total,
437
- unsigned maxSymbolValue)
475
+ unsigned maxSymbolValue, unsigned useLowProbCount)
438
476
  {
439
477
  /* Sanity checks */
440
478
  if (tableLog==0) tableLog = FSE_DEFAULT_TABLELOG;
@@ -443,8 +481,9 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
443
481
  if (tableLog < FSE_minTableLog(total, maxSymbolValue)) return ERROR(GENERIC); /* Too small tableLog, compression potentially impossible */
444
482
 
445
483
  { static U32 const rtbTable[] = { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
484
+ short const lowProbCount = useLowProbCount ? -1 : 1;
446
485
  U64 const scale = 62 - tableLog;
447
- U64 const step = ((U64)1<<62) / total; /* <== here, one division ! */
486
+ U64 const step = ZSTD_div64((U64)1<<62, (U32)total); /* <== here, one division ! */
448
487
  U64 const vStep = 1ULL<<(scale-20);
449
488
  int stillToDistribute = 1<<tableLog;
450
489
  unsigned s;
@@ -456,7 +495,7 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
456
495
  if (count[s] == total) return 0; /* rle special case */
457
496
  if (count[s] == 0) { normalizedCounter[s]=0; continue; }
458
497
  if (count[s] <= lowThreshold) {
459
- normalizedCounter[s] = -1;
498
+ normalizedCounter[s] = lowProbCount;
460
499
  stillToDistribute--;
461
500
  } else {
462
501
  short proba = (short)((count[s]*step) >> scale);
@@ -470,7 +509,7 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
470
509
  } }
471
510
  if (-stillToDistribute >= (normalizedCounter[largest] >> 1)) {
472
511
  /* corner case, need another normalization method */
473
- size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue);
512
+ size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue, lowProbCount);
474
513
  if (FSE_isError(errorCode)) return errorCode;
475
514
  }
476
515
  else normalizedCounter[largest] += (short)stillToDistribute;
@@ -625,6 +664,7 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
625
664
 
626
665
  size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
627
666
 
667
+ #ifndef ZSTD_NO_UNUSED_FUNCTIONS
628
668
  /* FSE_compress_wksp() :
629
669
  * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
630
670
  * `wkspSize` size must be `(1<<tableLog)`.
@@ -643,7 +683,7 @@ size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t src
643
683
  size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable));
644
684
 
645
685
  /* init conditions */
646
- if (wkspSize < FSE_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
686
+ if (wkspSize < FSE_COMPRESS_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
647
687
  if (srcSize <= 1) return 0; /* Not compressible */
648
688
  if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
649
689
  if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
@@ -656,7 +696,7 @@ size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t src
656
696
  }
657
697
 
658
698
  tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
659
- CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue) );
699
+ CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue, /* useLowProbCount */ srcSize >= 2048) );
660
700
 
661
701
  /* Write table description header */
662
702
  { CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
@@ -678,13 +718,16 @@ size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t src
678
718
 
679
719
  typedef struct {
680
720
  FSE_CTable CTable_max[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
681
- BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
721
+ union {
722
+ U32 hist_wksp[HIST_WKSP_SIZE_U32];
723
+ BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
724
+ } workspace;
682
725
  } fseWkspMax_t;
683
726
 
684
727
  size_t FSE_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
685
728
  {
686
729
  fseWkspMax_t scratchBuffer;
687
- DEBUG_STATIC_ASSERT(sizeof(scratchBuffer) >= FSE_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)); /* compilation failures here means scratchBuffer is not large enough */
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 */
688
731
  if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
689
732
  return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer));
690
733
  }
@@ -693,6 +736,6 @@ size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcS
693
736
  {
694
737
  return FSE_compress2(dst, dstCapacity, src, srcSize, FSE_MAX_SYMBOL_VALUE, FSE_DEFAULT_TABLELOG);
695
738
  }
696
-
739
+ #endif
697
740
 
698
741
  #endif /* FSE_COMMONDEFS_ONLY */