deflate-ruby 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CLAUDE.md +95 -92
  3. data/LICENSE.txt +6 -6
  4. data/README.md +87 -65
  5. data/Rakefile +23 -0
  6. data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_impl.h → adler32_impl.h} +8 -7
  7. data/ext/deflate_ruby/common_defs.h +748 -0
  8. data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.c → cpu_features.c} +46 -16
  9. data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.h → cpu_features.h} +2 -1
  10. data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_impl.h → crc32_impl.h} +22 -23
  11. data/ext/deflate_ruby/{libdeflate/lib/crc32_multipliers.h → crc32_multipliers.h} +2 -4
  12. data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_pclmul_template.h → crc32_pclmul_template.h} +23 -94
  13. data/ext/deflate_ruby/{libdeflate/lib/crc32_tables.h → crc32_tables.h} +1 -1
  14. data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.c → deflate_compress.c} +59 -60
  15. data/ext/deflate_ruby/deflate_ruby.c +392 -218
  16. data/ext/deflate_ruby/deflate_ruby.h +6 -0
  17. data/ext/deflate_ruby/extconf.rb +35 -25
  18. data/ext/deflate_ruby/libdeflate/adler32.c +162 -0
  19. data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/adler32_impl.h +14 -7
  20. data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/crc32_impl.h +25 -31
  21. data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_helpers.h +156 -0
  22. data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_wide.h +226 -0
  23. data/ext/deflate_ruby/libdeflate/bt_matchfinder.h +342 -0
  24. data/ext/deflate_ruby/libdeflate/common_defs.h +2 -1
  25. data/ext/deflate_ruby/libdeflate/cpu_features_common.h +93 -0
  26. data/ext/deflate_ruby/libdeflate/crc32.c +262 -0
  27. data/ext/deflate_ruby/libdeflate/crc32_multipliers.h +375 -0
  28. data/ext/deflate_ruby/libdeflate/crc32_tables.h +587 -0
  29. data/ext/deflate_ruby/libdeflate/decompress_template.h +777 -0
  30. data/ext/deflate_ruby/libdeflate/deflate_compress.c +4128 -0
  31. data/ext/deflate_ruby/libdeflate/deflate_compress.h +15 -0
  32. data/ext/deflate_ruby/libdeflate/deflate_constants.h +56 -0
  33. data/ext/deflate_ruby/libdeflate/deflate_decompress.c +1208 -0
  34. data/ext/deflate_ruby/libdeflate/gzip_compress.c +90 -0
  35. data/ext/deflate_ruby/libdeflate/gzip_constants.h +45 -0
  36. data/ext/deflate_ruby/libdeflate/gzip_decompress.c +144 -0
  37. data/ext/deflate_ruby/libdeflate/hc_matchfinder.h +401 -0
  38. data/ext/deflate_ruby/libdeflate/ht_matchfinder.h +234 -0
  39. data/ext/deflate_ruby/libdeflate/lib_common.h +106 -0
  40. data/ext/deflate_ruby/libdeflate/libdeflate.h +2 -2
  41. data/ext/deflate_ruby/libdeflate/{lib/matchfinder_common.h → matchfinder_common.h} +3 -3
  42. data/ext/deflate_ruby/libdeflate/x86/adler32_impl.h +135 -0
  43. data/ext/deflate_ruby/libdeflate/x86/adler32_template.h +518 -0
  44. data/ext/deflate_ruby/libdeflate/x86/cpu_features.c +213 -0
  45. data/ext/deflate_ruby/libdeflate/x86/cpu_features.h +170 -0
  46. data/ext/deflate_ruby/libdeflate/x86/crc32_impl.h +159 -0
  47. data/ext/deflate_ruby/libdeflate/x86/crc32_pclmul_template.h +424 -0
  48. data/ext/deflate_ruby/libdeflate/x86/decompress_impl.h +57 -0
  49. data/ext/deflate_ruby/libdeflate.h +411 -0
  50. data/ext/deflate_ruby/matchfinder_common.h +224 -0
  51. data/ext/deflate_ruby/matchfinder_impl.h +122 -0
  52. data/ext/deflate_ruby/utils.c +141 -0
  53. data/ext/deflate_ruby/zlib_compress.c +82 -0
  54. data/ext/deflate_ruby/zlib_constants.h +21 -0
  55. data/ext/deflate_ruby/zlib_decompress.c +104 -0
  56. data/lib/deflate_ruby/version.rb +1 -1
  57. data/lib/deflate_ruby.rb +1 -63
  58. data/sig/deflate_ruby.rbs +4 -0
  59. data/test/test_deflate_ruby.rb +220 -0
  60. data/test/test_helper.rb +6 -0
  61. metadata +89 -144
  62. data/ext/deflate_ruby/libdeflate/CMakeLists.txt +0 -270
  63. data/ext/deflate_ruby/libdeflate/NEWS.md +0 -494
  64. data/ext/deflate_ruby/libdeflate/README.md +0 -228
  65. data/ext/deflate_ruby/libdeflate/libdeflate-config.cmake.in +0 -3
  66. data/ext/deflate_ruby/libdeflate/libdeflate.pc.in +0 -18
  67. data/ext/deflate_ruby/libdeflate/programs/CMakeLists.txt +0 -105
  68. data/ext/deflate_ruby/libdeflate/programs/benchmark.c +0 -696
  69. data/ext/deflate_ruby/libdeflate/programs/checksum.c +0 -218
  70. data/ext/deflate_ruby/libdeflate/programs/config.h.in +0 -19
  71. data/ext/deflate_ruby/libdeflate/programs/gzip.c +0 -688
  72. data/ext/deflate_ruby/libdeflate/programs/prog_util.c +0 -521
  73. data/ext/deflate_ruby/libdeflate/programs/prog_util.h +0 -225
  74. data/ext/deflate_ruby/libdeflate/programs/test_checksums.c +0 -200
  75. data/ext/deflate_ruby/libdeflate/programs/test_custom_malloc.c +0 -155
  76. data/ext/deflate_ruby/libdeflate/programs/test_incomplete_codes.c +0 -385
  77. data/ext/deflate_ruby/libdeflate/programs/test_invalid_streams.c +0 -130
  78. data/ext/deflate_ruby/libdeflate/programs/test_litrunlen_overflow.c +0 -72
  79. data/ext/deflate_ruby/libdeflate/programs/test_overread.c +0 -95
  80. data/ext/deflate_ruby/libdeflate/programs/test_slow_decompression.c +0 -472
  81. data/ext/deflate_ruby/libdeflate/programs/test_trailing_bytes.c +0 -151
  82. data/ext/deflate_ruby/libdeflate/programs/test_util.c +0 -237
  83. data/ext/deflate_ruby/libdeflate/programs/test_util.h +0 -61
  84. data/ext/deflate_ruby/libdeflate/programs/tgetopt.c +0 -118
  85. data/ext/deflate_ruby/libdeflate/scripts/android_build.sh +0 -118
  86. data/ext/deflate_ruby/libdeflate/scripts/android_tests.sh +0 -69
  87. data/ext/deflate_ruby/libdeflate/scripts/benchmark.sh +0 -10
  88. data/ext/deflate_ruby/libdeflate/scripts/checksum.sh +0 -10
  89. data/ext/deflate_ruby/libdeflate/scripts/checksum_benchmarks.sh +0 -253
  90. data/ext/deflate_ruby/libdeflate/scripts/cmake-helper.sh +0 -17
  91. data/ext/deflate_ruby/libdeflate/scripts/deflate_benchmarks.sh +0 -119
  92. data/ext/deflate_ruby/libdeflate/scripts/exec_tests.sh +0 -38
  93. data/ext/deflate_ruby/libdeflate/scripts/gen-release-archives.sh +0 -37
  94. data/ext/deflate_ruby/libdeflate/scripts/gen_bitreverse_tab.py +0 -19
  95. data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_multipliers.c +0 -199
  96. data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_tables.c +0 -105
  97. data/ext/deflate_ruby/libdeflate/scripts/gen_default_litlen_costs.py +0 -44
  98. data/ext/deflate_ruby/libdeflate/scripts/gen_offset_slot_map.py +0 -29
  99. data/ext/deflate_ruby/libdeflate/scripts/gzip_tests.sh +0 -523
  100. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/corpus/0 +0 -0
  101. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/fuzz.c +0 -95
  102. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/corpus/0 +0 -3
  103. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/fuzz.c +0 -62
  104. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/fuzz.sh +0 -108
  105. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/corpus/0 +0 -0
  106. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/fuzz.c +0 -19
  107. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/corpus/0 +0 -3
  108. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/fuzz.c +0 -19
  109. data/ext/deflate_ruby/libdeflate/scripts/run_tests.sh +0 -416
  110. data/ext/deflate_ruby/libdeflate/scripts/toolchain-i686-w64-mingw32.cmake +0 -8
  111. data/ext/deflate_ruby/libdeflate/scripts/toolchain-x86_64-w64-mingw32.cmake +0 -8
  112. /data/ext/deflate_ruby/{libdeflate/lib/adler32.c → adler32.c} +0 -0
  113. /data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_template.h → adler32_template.h} +0 -0
  114. /data/ext/deflate_ruby/{libdeflate/lib/bt_matchfinder.h → bt_matchfinder.h} +0 -0
  115. /data/ext/deflate_ruby/{libdeflate/lib/cpu_features_common.h → cpu_features_common.h} +0 -0
  116. /data/ext/deflate_ruby/{libdeflate/lib/crc32.c → crc32.c} +0 -0
  117. /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_helpers.h → crc32_pmull_helpers.h} +0 -0
  118. /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_wide.h → crc32_pmull_wide.h} +0 -0
  119. /data/ext/deflate_ruby/{libdeflate/lib/x86/decompress_impl.h → decompress_impl.h} +0 -0
  120. /data/ext/deflate_ruby/{libdeflate/lib/decompress_template.h → decompress_template.h} +0 -0
  121. /data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.h → deflate_compress.h} +0 -0
  122. /data/ext/deflate_ruby/{libdeflate/lib/deflate_constants.h → deflate_constants.h} +0 -0
  123. /data/ext/deflate_ruby/{libdeflate/lib/deflate_decompress.c → deflate_decompress.c} +0 -0
  124. /data/ext/deflate_ruby/{libdeflate/lib/gzip_compress.c → gzip_compress.c} +0 -0
  125. /data/ext/deflate_ruby/{libdeflate/lib/gzip_constants.h → gzip_constants.h} +0 -0
  126. /data/ext/deflate_ruby/{libdeflate/lib/gzip_decompress.c → gzip_decompress.c} +0 -0
  127. /data/ext/deflate_ruby/{libdeflate/lib/hc_matchfinder.h → hc_matchfinder.h} +0 -0
  128. /data/ext/deflate_ruby/{libdeflate/lib/ht_matchfinder.h → ht_matchfinder.h} +0 -0
  129. /data/ext/deflate_ruby/{libdeflate/lib/lib_common.h → lib_common.h} +0 -0
  130. /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.c +0 -0
  131. /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.h +0 -0
  132. /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/matchfinder_impl.h +0 -0
  133. /data/ext/deflate_ruby/libdeflate/{lib/riscv → riscv}/matchfinder_impl.h +0 -0
  134. /data/ext/deflate_ruby/libdeflate/{lib/utils.c → utils.c} +0 -0
  135. /data/ext/deflate_ruby/libdeflate/{lib/x86 → x86}/matchfinder_impl.h +0 -0
  136. /data/ext/deflate_ruby/libdeflate/{lib/zlib_compress.c → zlib_compress.c} +0 -0
  137. /data/ext/deflate_ruby/libdeflate/{lib/zlib_constants.h → zlib_constants.h} +0 -0
  138. /data/ext/deflate_ruby/libdeflate/{lib/zlib_decompress.c → zlib_decompress.c} +0 -0
@@ -0,0 +1,262 @@
1
+ /*
2
+ * crc32.c - CRC-32 checksum algorithm for the gzip format
3
+ *
4
+ * Copyright 2016 Eric Biggers
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use,
10
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following
13
+ * conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ * OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+ /*
29
+ * High-level description of CRC
30
+ * =============================
31
+ *
32
+ * Consider a bit sequence 'bits[1...len]'. Interpret 'bits' as the "message"
33
+ * polynomial M(x) with coefficients in GF(2) (the field of integers modulo 2),
34
+ * where the coefficient of 'x^i' is 'bits[len - i]'. Then, compute:
35
+ *
36
+ * R(x) = M(x)*x^n mod G(x)
37
+ *
38
+ * where G(x) is a selected "generator" polynomial of degree 'n'. The remainder
39
+ * R(x) is a polynomial of max degree 'n - 1'. The CRC of 'bits' is R(x)
40
+ * interpreted as a bitstring of length 'n'.
41
+ *
42
+ * CRC used in gzip
43
+ * ================
44
+ *
45
+ * In the gzip format (RFC 1952):
46
+ *
47
+ * - The bitstring to checksum is formed from the bytes of the uncompressed
48
+ * data by concatenating the bits from the bytes in order, proceeding
49
+ * from the low-order bit to the high-order bit within each byte.
50
+ *
51
+ * - The generator polynomial G(x) is: x^32 + x^26 + x^23 + x^22 + x^16 +
52
+ * x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1.
53
+ * Consequently, the CRC length is 32 bits ("CRC-32").
54
+ *
55
+ * - The highest order 32 coefficients of M(x)*x^n are inverted.
56
+ *
57
+ * - All 32 coefficients of R(x) are inverted.
58
+ *
59
+ * The two inversions cause added leading and trailing zero bits to affect the
60
+ * resulting CRC, whereas with a regular CRC such bits would have no effect on
61
+ * the CRC.
62
+ *
63
+ * Computation and optimizations
64
+ * =============================
65
+ *
66
+ * We can compute R(x) through "long division", maintaining only 32 bits of
67
+ * state at any given time. Multiplication by 'x' can be implemented as
68
+ * right-shifting by 1 (assuming the polynomial<=>bitstring mapping where the
69
+ * highest order bit represents the coefficient of x^0), and both addition and
70
+ * subtraction can be implemented as bitwise exclusive OR (since we are working
71
+ * in GF(2)). Here is an unoptimized implementation:
72
+ *
73
+ * static u32 crc32_gzip(const u8 *p, size_t len)
74
+ * {
75
+ * u32 crc = 0;
76
+ * const u32 divisor = 0xEDB88320;
77
+ *
78
+ * for (size_t i = 0; i < len * 8 + 32; i++) {
79
+ * int bit;
80
+ * u32 multiple;
81
+ *
82
+ * if (i < len * 8)
83
+ * bit = (p[i / 8] >> (i % 8)) & 1;
84
+ * else
85
+ * bit = 0; // one of the 32 appended 0 bits
86
+ *
87
+ * if (i < 32) // the first 32 bits are inverted
88
+ * bit ^= 1;
89
+ *
90
+ * if (crc & 1)
91
+ * multiple = divisor;
92
+ * else
93
+ * multiple = 0;
94
+ *
95
+ * crc >>= 1;
96
+ * crc |= (u32)bit << 31;
97
+ * crc ^= multiple;
98
+ * }
99
+ *
100
+ * return ~crc;
101
+ * }
102
+ *
103
+ * In this implementation, the 32-bit integer 'crc' maintains the remainder of
104
+ * the currently processed portion of the message (with 32 zero bits appended)
105
+ * when divided by the generator polynomial. 'crc' is the representation of
106
+ * R(x), and 'divisor' is the representation of G(x) excluding the x^32
107
+ * coefficient. For each bit to process, we multiply R(x) by 'x^1', then add
108
+ * 'x^0' if the new bit is a 1. If this causes R(x) to gain a nonzero x^32
109
+ * term, then we subtract G(x) from R(x).
110
+ *
111
+ * We can speed this up by taking advantage of the fact that XOR is commutative
112
+ * and associative, so the order in which we combine the inputs into 'crc' is
113
+ * unimportant. And since each message bit we add doesn't affect the choice of
114
+ * 'multiple' until 32 bits later, we need not actually add each message bit
115
+ * until that point:
116
+ *
117
+ * static u32 crc32_gzip(const u8 *p, size_t len)
118
+ * {
119
+ * u32 crc = ~0;
120
+ * const u32 divisor = 0xEDB88320;
121
+ *
122
+ * for (size_t i = 0; i < len * 8; i++) {
123
+ * int bit;
124
+ * u32 multiple;
125
+ *
126
+ * bit = (p[i / 8] >> (i % 8)) & 1;
127
+ * crc ^= bit;
128
+ * if (crc & 1)
129
+ * multiple = divisor;
130
+ * else
131
+ * multiple = 0;
132
+ * crc >>= 1;
133
+ * crc ^= multiple;
134
+ * }
135
+ *
136
+ * return ~crc;
137
+ * }
138
+ *
139
+ * With the above implementation we get the effect of 32 appended 0 bits for
140
+ * free; they never affect the choice of a divisor, nor would they change the
141
+ * value of 'crc' if they were to be actually XOR'ed in. And by starting with a
142
+ * remainder of all 1 bits, we get the effect of complementing the first 32
143
+ * message bits.
144
+ *
145
+ * The next optimization is to process the input in multi-bit units. Suppose
146
+ * that we insert the next 'n' message bits into the remainder. Then we get an
147
+ * intermediate remainder of length '32 + n' bits, and the CRC of the extra 'n'
148
+ * bits is the amount by which the low 32 bits of the remainder will change as a
149
+ * result of cancelling out those 'n' bits. Taking n=8 (one byte) and
150
+ * precomputing a table containing the CRC of each possible byte, we get
151
+ * crc32_slice1() defined below.
152
+ *
153
+ * As a further optimization, we could increase the multi-bit unit size to 16.
154
+ * However, that is inefficient because the table size explodes from 256 entries
155
+ * (1024 bytes) to 65536 entries (262144 bytes), which wastes memory and won't
156
+ * fit in L1 cache on typical processors.
157
+ *
158
+ * However, we can actually process 4 bytes at a time using 4 different tables
159
+ * with 256 entries each. Logically, we form a 64-bit intermediate remainder
160
+ * and cancel out the high 32 bits in 8-bit chunks. Bits 32-39 are cancelled
161
+ * out by the CRC of those bits, whereas bits 40-47 are be cancelled out by the
162
+ * CRC of those bits with 8 zero bits appended, and so on.
163
+ *
164
+ * In crc32_slice8(), this method is extended to 8 bytes at a time. The
165
+ * intermediate remainder (which we never actually store explicitly) is 96 bits.
166
+ *
167
+ * On CPUs that support fast carryless multiplication, CRCs can be computed even
168
+ * more quickly via "folding". See e.g. the x86 PCLMUL implementations.
169
+ */
170
+
171
+ #include "lib_common.h"
172
+ #include "crc32_multipliers.h"
173
+ #include "crc32_tables.h"
174
+
175
+ /* This is the default implementation. It uses the slice-by-8 method. */
176
+ static u32 MAYBE_UNUSED
177
+ crc32_slice8(u32 crc, const u8 *p, size_t len)
178
+ {
179
+ const u8 * const end = p + len;
180
+ const u8 *end64;
181
+
182
+ for (; ((uintptr_t)p & 7) && p != end; p++)
183
+ crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p];
184
+
185
+ end64 = p + ((end - p) & ~7);
186
+ for (; p != end64; p += 8) {
187
+ u32 v1 = le32_bswap(*(const u32 *)(p + 0));
188
+ u32 v2 = le32_bswap(*(const u32 *)(p + 4));
189
+
190
+ crc = crc32_slice8_table[0x700 + (u8)((crc ^ v1) >> 0)] ^
191
+ crc32_slice8_table[0x600 + (u8)((crc ^ v1) >> 8)] ^
192
+ crc32_slice8_table[0x500 + (u8)((crc ^ v1) >> 16)] ^
193
+ crc32_slice8_table[0x400 + (u8)((crc ^ v1) >> 24)] ^
194
+ crc32_slice8_table[0x300 + (u8)(v2 >> 0)] ^
195
+ crc32_slice8_table[0x200 + (u8)(v2 >> 8)] ^
196
+ crc32_slice8_table[0x100 + (u8)(v2 >> 16)] ^
197
+ crc32_slice8_table[0x000 + (u8)(v2 >> 24)];
198
+ }
199
+
200
+ for (; p != end; p++)
201
+ crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p];
202
+
203
+ return crc;
204
+ }
205
+
206
+ /*
207
+ * This is a more lightweight generic implementation, which can be used as a
208
+ * subroutine by architecture-specific implementations to process small amounts
209
+ * of unaligned data at the beginning and/or end of the buffer.
210
+ */
211
+ static forceinline u32 MAYBE_UNUSED
212
+ crc32_slice1(u32 crc, const u8 *p, size_t len)
213
+ {
214
+ size_t i;
215
+
216
+ for (i = 0; i < len; i++)
217
+ crc = (crc >> 8) ^ crc32_slice1_table[(u8)crc ^ p[i]];
218
+ return crc;
219
+ }
220
+
221
+ /* Include architecture-specific implementation(s) if available. */
222
+ #undef DEFAULT_IMPL
223
+ #undef arch_select_crc32_func
224
+ typedef u32 (*crc32_func_t)(u32 crc, const u8 *p, size_t len);
225
+ #if defined(ARCH_ARM32) || defined(ARCH_ARM64)
226
+ # include "arm/crc32_impl.h"
227
+ #elif defined(ARCH_X86_32) || defined(ARCH_X86_64)
228
+ # include "x86/crc32_impl.h"
229
+ #endif
230
+
231
+ #ifndef DEFAULT_IMPL
232
+ # define DEFAULT_IMPL crc32_slice8
233
+ #endif
234
+
235
+ #ifdef arch_select_crc32_func
236
+ static u32 dispatch_crc32(u32 crc, const u8 *p, size_t len);
237
+
238
+ static volatile crc32_func_t crc32_impl = dispatch_crc32;
239
+
240
+ /* Choose the best implementation at runtime. */
241
+ static u32 dispatch_crc32(u32 crc, const u8 *p, size_t len)
242
+ {
243
+ crc32_func_t f = arch_select_crc32_func();
244
+
245
+ if (f == NULL)
246
+ f = DEFAULT_IMPL;
247
+
248
+ crc32_impl = f;
249
+ return f(crc, p, len);
250
+ }
251
+ #else
252
+ /* The best implementation is statically known, so call it directly. */
253
+ #define crc32_impl DEFAULT_IMPL
254
+ #endif
255
+
256
+ LIBDEFLATEAPI u32
257
+ libdeflate_crc32(u32 crc, const void *p, size_t len)
258
+ {
259
+ if (p == NULL) /* Return initial value. */
260
+ return 0;
261
+ return ~crc32_impl(~crc, p, len);
262
+ }
@@ -0,0 +1,375 @@
1
+ /*
2
+ * crc32_multipliers.h - constants for CRC-32 folding
3
+ *
4
+ * THIS FILE WAS GENERATED BY gen-crc32-consts.py. DO NOT EDIT.
5
+ */
6
+
7
+ #define CRC32_X159_MODG 0xae689191 /* x^159 mod G(x) */
8
+ #define CRC32_X95_MODG 0xccaa009e /* x^95 mod G(x) */
9
+
10
+ #define CRC32_X287_MODG 0xf1da05aa /* x^287 mod G(x) */
11
+ #define CRC32_X223_MODG 0x81256527 /* x^223 mod G(x) */
12
+
13
+ #define CRC32_X415_MODG 0x3db1ecdc /* x^415 mod G(x) */
14
+ #define CRC32_X351_MODG 0xaf449247 /* x^351 mod G(x) */
15
+
16
+ #define CRC32_X543_MODG 0x8f352d95 /* x^543 mod G(x) */
17
+ #define CRC32_X479_MODG 0x1d9513d7 /* x^479 mod G(x) */
18
+
19
+ #define CRC32_X671_MODG 0x1c279815 /* x^671 mod G(x) */
20
+ #define CRC32_X607_MODG 0xae0b5394 /* x^607 mod G(x) */
21
+
22
+ #define CRC32_X799_MODG 0xdf068dc2 /* x^799 mod G(x) */
23
+ #define CRC32_X735_MODG 0x57c54819 /* x^735 mod G(x) */
24
+
25
+ #define CRC32_X927_MODG 0x31f8303f /* x^927 mod G(x) */
26
+ #define CRC32_X863_MODG 0x0cbec0ed /* x^863 mod G(x) */
27
+
28
+ #define CRC32_X1055_MODG 0x33fff533 /* x^1055 mod G(x) */
29
+ #define CRC32_X991_MODG 0x910eeec1 /* x^991 mod G(x) */
30
+
31
+ #define CRC32_X1183_MODG 0x26b70c3d /* x^1183 mod G(x) */
32
+ #define CRC32_X1119_MODG 0x3f41287a /* x^1119 mod G(x) */
33
+
34
+ #define CRC32_X1311_MODG 0xe3543be0 /* x^1311 mod G(x) */
35
+ #define CRC32_X1247_MODG 0x9026d5b1 /* x^1247 mod G(x) */
36
+
37
+ #define CRC32_X1439_MODG 0x5a1bb05d /* x^1439 mod G(x) */
38
+ #define CRC32_X1375_MODG 0xd1df2327 /* x^1375 mod G(x) */
39
+
40
+ #define CRC32_X1567_MODG 0x596c8d81 /* x^1567 mod G(x) */
41
+ #define CRC32_X1503_MODG 0xf5e48c85 /* x^1503 mod G(x) */
42
+
43
+ #define CRC32_X1695_MODG 0x682bdd4f /* x^1695 mod G(x) */
44
+ #define CRC32_X1631_MODG 0x3c656ced /* x^1631 mod G(x) */
45
+
46
+ #define CRC32_X1823_MODG 0x4a28bd43 /* x^1823 mod G(x) */
47
+ #define CRC32_X1759_MODG 0xfe807bbd /* x^1759 mod G(x) */
48
+
49
+ #define CRC32_X1951_MODG 0x0077f00d /* x^1951 mod G(x) */
50
+ #define CRC32_X1887_MODG 0x1f0c2cdd /* x^1887 mod G(x) */
51
+
52
+ #define CRC32_X2079_MODG 0xce3371cb /* x^2079 mod G(x) */
53
+ #define CRC32_X2015_MODG 0xe95c1271 /* x^2015 mod G(x) */
54
+
55
+ #define CRC32_X2207_MODG 0xa749e894 /* x^2207 mod G(x) */
56
+ #define CRC32_X2143_MODG 0xb918a347 /* x^2143 mod G(x) */
57
+
58
+ #define CRC32_X2335_MODG 0x2c538639 /* x^2335 mod G(x) */
59
+ #define CRC32_X2271_MODG 0x71d54a59 /* x^2271 mod G(x) */
60
+
61
+ #define CRC32_X2463_MODG 0x32b0733c /* x^2463 mod G(x) */
62
+ #define CRC32_X2399_MODG 0xff6f2fc2 /* x^2399 mod G(x) */
63
+
64
+ #define CRC32_X2591_MODG 0x0e9bd5cc /* x^2591 mod G(x) */
65
+ #define CRC32_X2527_MODG 0xcec97417 /* x^2527 mod G(x) */
66
+
67
+ #define CRC32_X2719_MODG 0x76278617 /* x^2719 mod G(x) */
68
+ #define CRC32_X2655_MODG 0x1c63267b /* x^2655 mod G(x) */
69
+
70
+ #define CRC32_X2847_MODG 0xc51b93e3 /* x^2847 mod G(x) */
71
+ #define CRC32_X2783_MODG 0xf183c71b /* x^2783 mod G(x) */
72
+
73
+ #define CRC32_X2975_MODG 0x7eaed122 /* x^2975 mod G(x) */
74
+ #define CRC32_X2911_MODG 0x9b9bdbd0 /* x^2911 mod G(x) */
75
+
76
+ #define CRC32_X3103_MODG 0x2ce423f1 /* x^3103 mod G(x) */
77
+ #define CRC32_X3039_MODG 0xd31343ea /* x^3039 mod G(x) */
78
+
79
+ #define CRC32_X3231_MODG 0x8b8d8645 /* x^3231 mod G(x) */
80
+ #define CRC32_X3167_MODG 0x4470ac44 /* x^3167 mod G(x) */
81
+
82
+ #define CRC32_X3359_MODG 0x4b700aa8 /* x^3359 mod G(x) */
83
+ #define CRC32_X3295_MODG 0xeea395c4 /* x^3295 mod G(x) */
84
+
85
+ #define CRC32_X3487_MODG 0xeff5e99d /* x^3487 mod G(x) */
86
+ #define CRC32_X3423_MODG 0xf9d9c7ee /* x^3423 mod G(x) */
87
+
88
+ #define CRC32_X3615_MODG 0xad0d2bb2 /* x^3615 mod G(x) */
89
+ #define CRC32_X3551_MODG 0xcd669a40 /* x^3551 mod G(x) */
90
+
91
+ #define CRC32_X3743_MODG 0x9fb66bd3 /* x^3743 mod G(x) */
92
+ #define CRC32_X3679_MODG 0x6d40f445 /* x^3679 mod G(x) */
93
+
94
+ #define CRC32_X3871_MODG 0xc2dcc467 /* x^3871 mod G(x) */
95
+ #define CRC32_X3807_MODG 0x9ee62949 /* x^3807 mod G(x) */
96
+
97
+ #define CRC32_X3999_MODG 0x398e2ff2 /* x^3999 mod G(x) */
98
+ #define CRC32_X3935_MODG 0x145575d5 /* x^3935 mod G(x) */
99
+
100
+ #define CRC32_X4127_MODG 0x1072db28 /* x^4127 mod G(x) */
101
+ #define CRC32_X4063_MODG 0x0c30f51d /* x^4063 mod G(x) */
102
+
103
+ #define CRC32_BARRETT_CONSTANT_1 0xb4e5b025f7011641ULL /* floor(x^95 / G(x)) */
104
+ #define CRC32_BARRETT_CONSTANT_2 0x00000001db710641ULL /* G(x) */
105
+
106
+ #define CRC32_NUM_CHUNKS 4
107
+ #define CRC32_MIN_VARIABLE_CHUNK_LEN 128UL
108
+ #define CRC32_MAX_VARIABLE_CHUNK_LEN 16384UL
109
+
110
+ /* Multipliers for implementations that use a variable chunk length */
111
+ static const u32 crc32_mults_for_chunklen[][CRC32_NUM_CHUNKS - 1] MAYBE_UNUSED = {
112
+ { 0 /* unused row */ },
113
+ /* chunk_len=128 */
114
+ { 0xd31343ea /* x^3039 mod G(x) */, 0xe95c1271 /* x^2015 mod G(x) */, 0x910eeec1 /* x^991 mod G(x) */, },
115
+ /* chunk_len=256 */
116
+ { 0x1d6708a0 /* x^6111 mod G(x) */, 0x0c30f51d /* x^4063 mod G(x) */, 0xe95c1271 /* x^2015 mod G(x) */, },
117
+ /* chunk_len=384 */
118
+ { 0xdb3839f3 /* x^9183 mod G(x) */, 0x1d6708a0 /* x^6111 mod G(x) */, 0xd31343ea /* x^3039 mod G(x) */, },
119
+ /* chunk_len=512 */
120
+ { 0x1753ab84 /* x^12255 mod G(x) */, 0xbbf2f6d6 /* x^8159 mod G(x) */, 0x0c30f51d /* x^4063 mod G(x) */, },
121
+ /* chunk_len=640 */
122
+ { 0x3796455c /* x^15327 mod G(x) */, 0xb8e0e4a8 /* x^10207 mod G(x) */, 0xc352f6de /* x^5087 mod G(x) */, },
123
+ /* chunk_len=768 */
124
+ { 0x3954de39 /* x^18399 mod G(x) */, 0x1753ab84 /* x^12255 mod G(x) */, 0x1d6708a0 /* x^6111 mod G(x) */, },
125
+ /* chunk_len=896 */
126
+ { 0x632d78c5 /* x^21471 mod G(x) */, 0x3fc33de4 /* x^14303 mod G(x) */, 0x9a1b53c8 /* x^7135 mod G(x) */, },
127
+ /* chunk_len=1024 */
128
+ { 0xa0decef3 /* x^24543 mod G(x) */, 0x7b4aa8b7 /* x^16351 mod G(x) */, 0xbbf2f6d6 /* x^8159 mod G(x) */, },
129
+ /* chunk_len=1152 */
130
+ { 0xe9c09bb0 /* x^27615 mod G(x) */, 0x3954de39 /* x^18399 mod G(x) */, 0xdb3839f3 /* x^9183 mod G(x) */, },
131
+ /* chunk_len=1280 */
132
+ { 0xd51917a4 /* x^30687 mod G(x) */, 0xcae68461 /* x^20447 mod G(x) */, 0xb8e0e4a8 /* x^10207 mod G(x) */, },
133
+ /* chunk_len=1408 */
134
+ { 0x154a8a62 /* x^33759 mod G(x) */, 0x41e7589c /* x^22495 mod G(x) */, 0x3e9a43cd /* x^11231 mod G(x) */, },
135
+ /* chunk_len=1536 */
136
+ { 0xf196555d /* x^36831 mod G(x) */, 0xa0decef3 /* x^24543 mod G(x) */, 0x1753ab84 /* x^12255 mod G(x) */, },
137
+ /* chunk_len=1664 */
138
+ { 0x8eec2999 /* x^39903 mod G(x) */, 0xefb0a128 /* x^26591 mod G(x) */, 0x6044fbb0 /* x^13279 mod G(x) */, },
139
+ /* chunk_len=1792 */
140
+ { 0x27892abf /* x^42975 mod G(x) */, 0x48d72bb1 /* x^28639 mod G(x) */, 0x3fc33de4 /* x^14303 mod G(x) */, },
141
+ /* chunk_len=1920 */
142
+ { 0x77bc2419 /* x^46047 mod G(x) */, 0xd51917a4 /* x^30687 mod G(x) */, 0x3796455c /* x^15327 mod G(x) */, },
143
+ /* chunk_len=2048 */
144
+ { 0xcea114a5 /* x^49119 mod G(x) */, 0x68c0a2c5 /* x^32735 mod G(x) */, 0x7b4aa8b7 /* x^16351 mod G(x) */, },
145
+ /* chunk_len=2176 */
146
+ { 0xa1077e85 /* x^52191 mod G(x) */, 0x188cc628 /* x^34783 mod G(x) */, 0x0c21f835 /* x^17375 mod G(x) */, },
147
+ /* chunk_len=2304 */
148
+ { 0xc5ed75e1 /* x^55263 mod G(x) */, 0xf196555d /* x^36831 mod G(x) */, 0x3954de39 /* x^18399 mod G(x) */, },
149
+ /* chunk_len=2432 */
150
+ { 0xca4fba3f /* x^58335 mod G(x) */, 0x0acfa26f /* x^38879 mod G(x) */, 0x6cb21510 /* x^19423 mod G(x) */, },
151
+ /* chunk_len=2560 */
152
+ { 0xcf5bcdc4 /* x^61407 mod G(x) */, 0x4fae7fc0 /* x^40927 mod G(x) */, 0xcae68461 /* x^20447 mod G(x) */, },
153
+ /* chunk_len=2688 */
154
+ { 0xf36b9d16 /* x^64479 mod G(x) */, 0x27892abf /* x^42975 mod G(x) */, 0x632d78c5 /* x^21471 mod G(x) */, },
155
+ /* chunk_len=2816 */
156
+ { 0xf76fd988 /* x^67551 mod G(x) */, 0xed5c39b1 /* x^45023 mod G(x) */, 0x41e7589c /* x^22495 mod G(x) */, },
157
+ /* chunk_len=2944 */
158
+ { 0x6c45d92e /* x^70623 mod G(x) */, 0xff809fcd /* x^47071 mod G(x) */, 0x0c46baec /* x^23519 mod G(x) */, },
159
+ /* chunk_len=3072 */
160
+ { 0x6116b82b /* x^73695 mod G(x) */, 0xcea114a5 /* x^49119 mod G(x) */, 0xa0decef3 /* x^24543 mod G(x) */, },
161
+ /* chunk_len=3200 */
162
+ { 0x4d9899bb /* x^76767 mod G(x) */, 0x9f9d8d9c /* x^51167 mod G(x) */, 0x53deb236 /* x^25567 mod G(x) */, },
163
+ /* chunk_len=3328 */
164
+ { 0x3e7c93b9 /* x^79839 mod G(x) */, 0x6666b805 /* x^53215 mod G(x) */, 0xefb0a128 /* x^26591 mod G(x) */, },
165
+ /* chunk_len=3456 */
166
+ { 0x388b20ac /* x^82911 mod G(x) */, 0xc5ed75e1 /* x^55263 mod G(x) */, 0xe9c09bb0 /* x^27615 mod G(x) */, },
167
+ /* chunk_len=3584 */
168
+ { 0x0956d953 /* x^85983 mod G(x) */, 0x97fbdb14 /* x^57311 mod G(x) */, 0x48d72bb1 /* x^28639 mod G(x) */, },
169
+ /* chunk_len=3712 */
170
+ { 0x55cb4dfe /* x^89055 mod G(x) */, 0x1b37c832 /* x^59359 mod G(x) */, 0xc07331b3 /* x^29663 mod G(x) */, },
171
+ /* chunk_len=3840 */
172
+ { 0x52222fea /* x^92127 mod G(x) */, 0xcf5bcdc4 /* x^61407 mod G(x) */, 0xd51917a4 /* x^30687 mod G(x) */, },
173
+ /* chunk_len=3968 */
174
+ { 0x0603989b /* x^95199 mod G(x) */, 0xb03c8112 /* x^63455 mod G(x) */, 0x5e04b9a5 /* x^31711 mod G(x) */, },
175
+ /* chunk_len=4096 */
176
+ { 0x4470c029 /* x^98271 mod G(x) */, 0x2339d155 /* x^65503 mod G(x) */, 0x68c0a2c5 /* x^32735 mod G(x) */, },
177
+ /* chunk_len=4224 */
178
+ { 0xb6f35093 /* x^101343 mod G(x) */, 0xf76fd988 /* x^67551 mod G(x) */, 0x154a8a62 /* x^33759 mod G(x) */, },
179
+ /* chunk_len=4352 */
180
+ { 0xc46805ba /* x^104415 mod G(x) */, 0x416f9449 /* x^69599 mod G(x) */, 0x188cc628 /* x^34783 mod G(x) */, },
181
+ /* chunk_len=4480 */
182
+ { 0xc3876592 /* x^107487 mod G(x) */, 0x4b809189 /* x^71647 mod G(x) */, 0xc35cf6e7 /* x^35807 mod G(x) */, },
183
+ /* chunk_len=4608 */
184
+ { 0x5b0c98b9 /* x^110559 mod G(x) */, 0x6116b82b /* x^73695 mod G(x) */, 0xf196555d /* x^36831 mod G(x) */, },
185
+ /* chunk_len=4736 */
186
+ { 0x30d13e5f /* x^113631 mod G(x) */, 0x4c5a315a /* x^75743 mod G(x) */, 0x8c224466 /* x^37855 mod G(x) */, },
187
+ /* chunk_len=4864 */
188
+ { 0x54afca53 /* x^116703 mod G(x) */, 0xbccfa2c1 /* x^77791 mod G(x) */, 0x0acfa26f /* x^38879 mod G(x) */, },
189
+ /* chunk_len=4992 */
190
+ { 0x93102436 /* x^119775 mod G(x) */, 0x3e7c93b9 /* x^79839 mod G(x) */, 0x8eec2999 /* x^39903 mod G(x) */, },
191
+ /* chunk_len=5120 */
192
+ { 0xbd2655a8 /* x^122847 mod G(x) */, 0x3e116c9d /* x^81887 mod G(x) */, 0x4fae7fc0 /* x^40927 mod G(x) */, },
193
+ /* chunk_len=5248 */
194
+ { 0x70cd7f26 /* x^125919 mod G(x) */, 0x408e57f2 /* x^83935 mod G(x) */, 0x1691be45 /* x^41951 mod G(x) */, },
195
+ /* chunk_len=5376 */
196
+ { 0x2d546c53 /* x^128991 mod G(x) */, 0x0956d953 /* x^85983 mod G(x) */, 0x27892abf /* x^42975 mod G(x) */, },
197
+ /* chunk_len=5504 */
198
+ { 0xb53410a8 /* x^132063 mod G(x) */, 0x42ebf0ad /* x^88031 mod G(x) */, 0x161f3c12 /* x^43999 mod G(x) */, },
199
+ /* chunk_len=5632 */
200
+ { 0x67a93f75 /* x^135135 mod G(x) */, 0xcf3233e4 /* x^90079 mod G(x) */, 0xed5c39b1 /* x^45023 mod G(x) */, },
201
+ /* chunk_len=5760 */
202
+ { 0x9830ac33 /* x^138207 mod G(x) */, 0x52222fea /* x^92127 mod G(x) */, 0x77bc2419 /* x^46047 mod G(x) */, },
203
+ /* chunk_len=5888 */
204
+ { 0xb0b6fc3e /* x^141279 mod G(x) */, 0x2fde73f8 /* x^94175 mod G(x) */, 0xff809fcd /* x^47071 mod G(x) */, },
205
+ /* chunk_len=6016 */
206
+ { 0x84170f16 /* x^144351 mod G(x) */, 0xced90d99 /* x^96223 mod G(x) */, 0x30de0f98 /* x^48095 mod G(x) */, },
207
+ /* chunk_len=6144 */
208
+ { 0xd7017a0c /* x^147423 mod G(x) */, 0x4470c029 /* x^98271 mod G(x) */, 0xcea114a5 /* x^49119 mod G(x) */, },
209
+ /* chunk_len=6272 */
210
+ { 0xadb25de6 /* x^150495 mod G(x) */, 0x84f40beb /* x^100319 mod G(x) */, 0x2b7e0e1b /* x^50143 mod G(x) */, },
211
+ /* chunk_len=6400 */
212
+ { 0x8282fddc /* x^153567 mod G(x) */, 0xec855937 /* x^102367 mod G(x) */, 0x9f9d8d9c /* x^51167 mod G(x) */, },
213
+ /* chunk_len=6528 */
214
+ { 0x46362bee /* x^156639 mod G(x) */, 0xc46805ba /* x^104415 mod G(x) */, 0xa1077e85 /* x^52191 mod G(x) */, },
215
+ /* chunk_len=6656 */
216
+ { 0xb9077a01 /* x^159711 mod G(x) */, 0xdf7a24ac /* x^106463 mod G(x) */, 0x6666b805 /* x^53215 mod G(x) */, },
217
+ /* chunk_len=6784 */
218
+ { 0xf51d9bc6 /* x^162783 mod G(x) */, 0x2b52dc39 /* x^108511 mod G(x) */, 0x7e774cf6 /* x^54239 mod G(x) */, },
219
+ /* chunk_len=6912 */
220
+ { 0x4ca19a29 /* x^165855 mod G(x) */, 0x5b0c98b9 /* x^110559 mod G(x) */, 0xc5ed75e1 /* x^55263 mod G(x) */, },
221
+ /* chunk_len=7040 */
222
+ { 0xdc0fc3fc /* x^168927 mod G(x) */, 0xb939fcdf /* x^112607 mod G(x) */, 0x3678fed2 /* x^56287 mod G(x) */, },
223
+ /* chunk_len=7168 */
224
+ { 0x63c3d167 /* x^171999 mod G(x) */, 0x70f9947d /* x^114655 mod G(x) */, 0x97fbdb14 /* x^57311 mod G(x) */, },
225
+ /* chunk_len=7296 */
226
+ { 0x5851d254 /* x^175071 mod G(x) */, 0x54afca53 /* x^116703 mod G(x) */, 0xca4fba3f /* x^58335 mod G(x) */, },
227
+ /* chunk_len=7424 */
228
+ { 0xfeacf2a1 /* x^178143 mod G(x) */, 0x7a3c0a6a /* x^118751 mod G(x) */, 0x1b37c832 /* x^59359 mod G(x) */, },
229
+ /* chunk_len=7552 */
230
+ { 0x93b7edc8 /* x^181215 mod G(x) */, 0x1fea4d2a /* x^120799 mod G(x) */, 0x58fa96ee /* x^60383 mod G(x) */, },
231
+ /* chunk_len=7680 */
232
+ { 0x5539e44a /* x^184287 mod G(x) */, 0xbd2655a8 /* x^122847 mod G(x) */, 0xcf5bcdc4 /* x^61407 mod G(x) */, },
233
+ /* chunk_len=7808 */
234
+ { 0xde32a3d2 /* x^187359 mod G(x) */, 0x4ff61aa1 /* x^124895 mod G(x) */, 0x6a6a3694 /* x^62431 mod G(x) */, },
235
+ /* chunk_len=7936 */
236
+ { 0xf0baeeb6 /* x^190431 mod G(x) */, 0x7ae2f6f4 /* x^126943 mod G(x) */, 0xb03c8112 /* x^63455 mod G(x) */, },
237
+ /* chunk_len=8064 */
238
+ { 0xbe15887f /* x^193503 mod G(x) */, 0x2d546c53 /* x^128991 mod G(x) */, 0xf36b9d16 /* x^64479 mod G(x) */, },
239
+ /* chunk_len=8192 */
240
+ { 0x64f34a05 /* x^196575 mod G(x) */, 0xe0ee5efe /* x^131039 mod G(x) */, 0x2339d155 /* x^65503 mod G(x) */, },
241
+ /* chunk_len=8320 */
242
+ { 0x1b6d1aea /* x^199647 mod G(x) */, 0xfeafb67c /* x^133087 mod G(x) */, 0x4fb001a8 /* x^66527 mod G(x) */, },
243
+ /* chunk_len=8448 */
244
+ { 0x82adb0b8 /* x^202719 mod G(x) */, 0x67a93f75 /* x^135135 mod G(x) */, 0xf76fd988 /* x^67551 mod G(x) */, },
245
+ /* chunk_len=8576 */
246
+ { 0x694587c7 /* x^205791 mod G(x) */, 0x3b34408b /* x^137183 mod G(x) */, 0xeccb2978 /* x^68575 mod G(x) */, },
247
+ /* chunk_len=8704 */
248
+ { 0xd2fc57c3 /* x^208863 mod G(x) */, 0x07fcf8c6 /* x^139231 mod G(x) */, 0x416f9449 /* x^69599 mod G(x) */, },
249
+ /* chunk_len=8832 */
250
+ { 0x9dd6837c /* x^211935 mod G(x) */, 0xb0b6fc3e /* x^141279 mod G(x) */, 0x6c45d92e /* x^70623 mod G(x) */, },
251
+ /* chunk_len=8960 */
252
+ { 0x3a9d1f97 /* x^215007 mod G(x) */, 0xefd033b2 /* x^143327 mod G(x) */, 0x4b809189 /* x^71647 mod G(x) */, },
253
+ /* chunk_len=9088 */
254
+ { 0x1eee1d2a /* x^218079 mod G(x) */, 0xf2a6e46e /* x^145375 mod G(x) */, 0x55b4c814 /* x^72671 mod G(x) */, },
255
+ /* chunk_len=9216 */
256
+ { 0xb57c7728 /* x^221151 mod G(x) */, 0xd7017a0c /* x^147423 mod G(x) */, 0x6116b82b /* x^73695 mod G(x) */, },
257
+ /* chunk_len=9344 */
258
+ { 0xf2fc5d61 /* x^224223 mod G(x) */, 0x242aac86 /* x^149471 mod G(x) */, 0x05245cf0 /* x^74719 mod G(x) */, },
259
+ /* chunk_len=9472 */
260
+ { 0x26387824 /* x^227295 mod G(x) */, 0xc15c4ca5 /* x^151519 mod G(x) */, 0x4c5a315a /* x^75743 mod G(x) */, },
261
+ /* chunk_len=9600 */
262
+ { 0x8c151e77 /* x^230367 mod G(x) */, 0x8282fddc /* x^153567 mod G(x) */, 0x4d9899bb /* x^76767 mod G(x) */, },
263
+ /* chunk_len=9728 */
264
+ { 0x8ea1f680 /* x^233439 mod G(x) */, 0xf5ff6cdd /* x^155615 mod G(x) */, 0xbccfa2c1 /* x^77791 mod G(x) */, },
265
+ /* chunk_len=9856 */
266
+ { 0xe8cf3d2a /* x^236511 mod G(x) */, 0x338b1fb1 /* x^157663 mod G(x) */, 0xeda61f70 /* x^78815 mod G(x) */, },
267
+ /* chunk_len=9984 */
268
+ { 0x21f15b59 /* x^239583 mod G(x) */, 0xb9077a01 /* x^159711 mod G(x) */, 0x3e7c93b9 /* x^79839 mod G(x) */, },
269
+ /* chunk_len=10112 */
270
+ { 0x6f68d64a /* x^242655 mod G(x) */, 0x901b0161 /* x^161759 mod G(x) */, 0xb9fd3537 /* x^80863 mod G(x) */, },
271
+ /* chunk_len=10240 */
272
+ { 0x71b74d95 /* x^245727 mod G(x) */, 0xf5ddd5ad /* x^163807 mod G(x) */, 0x3e116c9d /* x^81887 mod G(x) */, },
273
+ /* chunk_len=10368 */
274
+ { 0x4c2e7261 /* x^248799 mod G(x) */, 0x4ca19a29 /* x^165855 mod G(x) */, 0x388b20ac /* x^82911 mod G(x) */, },
275
+ /* chunk_len=10496 */
276
+ { 0x8a2d38e8 /* x^251871 mod G(x) */, 0xd27ee0a1 /* x^167903 mod G(x) */, 0x408e57f2 /* x^83935 mod G(x) */, },
277
+ /* chunk_len=10624 */
278
+ { 0x7e58ca17 /* x^254943 mod G(x) */, 0x69dfedd2 /* x^169951 mod G(x) */, 0x3a76805e /* x^84959 mod G(x) */, },
279
+ /* chunk_len=10752 */
280
+ { 0xf997967f /* x^258015 mod G(x) */, 0x63c3d167 /* x^171999 mod G(x) */, 0x0956d953 /* x^85983 mod G(x) */, },
281
+ /* chunk_len=10880 */
282
+ { 0x48215963 /* x^261087 mod G(x) */, 0x71e1dfe0 /* x^174047 mod G(x) */, 0x42a6d410 /* x^87007 mod G(x) */, },
283
+ /* chunk_len=11008 */
284
+ { 0xa704b94c /* x^264159 mod G(x) */, 0x679f198a /* x^176095 mod G(x) */, 0x42ebf0ad /* x^88031 mod G(x) */, },
285
+ /* chunk_len=11136 */
286
+ { 0x1d699056 /* x^267231 mod G(x) */, 0xfeacf2a1 /* x^178143 mod G(x) */, 0x55cb4dfe /* x^89055 mod G(x) */, },
287
+ /* chunk_len=11264 */
288
+ { 0x6800bcc5 /* x^270303 mod G(x) */, 0x16024f15 /* x^180191 mod G(x) */, 0xcf3233e4 /* x^90079 mod G(x) */, },
289
+ /* chunk_len=11392 */
290
+ { 0x2d48e4ca /* x^273375 mod G(x) */, 0xbe61582f /* x^182239 mod G(x) */, 0x46026283 /* x^91103 mod G(x) */, },
291
+ /* chunk_len=11520 */
292
+ { 0x4c4c2b55 /* x^276447 mod G(x) */, 0x5539e44a /* x^184287 mod G(x) */, 0x52222fea /* x^92127 mod G(x) */, },
293
+ /* chunk_len=11648 */
294
+ { 0xd8ce94cb /* x^279519 mod G(x) */, 0xbc613c26 /* x^186335 mod G(x) */, 0x33776b4b /* x^93151 mod G(x) */, },
295
+ /* chunk_len=11776 */
296
+ { 0xd0b5a02b /* x^282591 mod G(x) */, 0x490d3cc6 /* x^188383 mod G(x) */, 0x2fde73f8 /* x^94175 mod G(x) */, },
297
+ /* chunk_len=11904 */
298
+ { 0xa223f7ec /* x^285663 mod G(x) */, 0xf0baeeb6 /* x^190431 mod G(x) */, 0x0603989b /* x^95199 mod G(x) */, },
299
+ /* chunk_len=12032 */
300
+ { 0x58de337a /* x^288735 mod G(x) */, 0x3bf3d597 /* x^192479 mod G(x) */, 0xced90d99 /* x^96223 mod G(x) */, },
301
+ /* chunk_len=12160 */
302
+ { 0x37f5d8f4 /* x^291807 mod G(x) */, 0x4d5b699b /* x^194527 mod G(x) */, 0xd7262e5f /* x^97247 mod G(x) */, },
303
+ /* chunk_len=12288 */
304
+ { 0xfa8a435d /* x^294879 mod G(x) */, 0x64f34a05 /* x^196575 mod G(x) */, 0x4470c029 /* x^98271 mod G(x) */, },
305
+ /* chunk_len=12416 */
306
+ { 0x238709fe /* x^297951 mod G(x) */, 0x52e7458f /* x^198623 mod G(x) */, 0x9a174cd3 /* x^99295 mod G(x) */, },
307
+ /* chunk_len=12544 */
308
+ { 0x9e1ba6f5 /* x^301023 mod G(x) */, 0xef0272f7 /* x^200671 mod G(x) */, 0x84f40beb /* x^100319 mod G(x) */, },
309
+ /* chunk_len=12672 */
310
+ { 0xcd8b57fa /* x^304095 mod G(x) */, 0x82adb0b8 /* x^202719 mod G(x) */, 0xb6f35093 /* x^101343 mod G(x) */, },
311
+ /* chunk_len=12800 */
312
+ { 0x0aed142f /* x^307167 mod G(x) */, 0xb1650290 /* x^204767 mod G(x) */, 0xec855937 /* x^102367 mod G(x) */, },
313
+ /* chunk_len=12928 */
314
+ { 0xd1f064db /* x^310239 mod G(x) */, 0x6e7340d3 /* x^206815 mod G(x) */, 0x5c28cb52 /* x^103391 mod G(x) */, },
315
+ /* chunk_len=13056 */
316
+ { 0x464ac895 /* x^313311 mod G(x) */, 0xd2fc57c3 /* x^208863 mod G(x) */, 0xc46805ba /* x^104415 mod G(x) */, },
317
+ /* chunk_len=13184 */
318
+ { 0xa0e6beea /* x^316383 mod G(x) */, 0xcfeec3d0 /* x^210911 mod G(x) */, 0x0225d214 /* x^105439 mod G(x) */, },
319
+ /* chunk_len=13312 */
320
+ { 0x78703ce0 /* x^319455 mod G(x) */, 0xc60f6075 /* x^212959 mod G(x) */, 0xdf7a24ac /* x^106463 mod G(x) */, },
321
+ /* chunk_len=13440 */
322
+ { 0xfea48165 /* x^322527 mod G(x) */, 0x3a9d1f97 /* x^215007 mod G(x) */, 0xc3876592 /* x^107487 mod G(x) */, },
323
+ /* chunk_len=13568 */
324
+ { 0xdb89b8db /* x^325599 mod G(x) */, 0xa6172211 /* x^217055 mod G(x) */, 0x2b52dc39 /* x^108511 mod G(x) */, },
325
+ /* chunk_len=13696 */
326
+ { 0x7ca03731 /* x^328671 mod G(x) */, 0x1db42849 /* x^219103 mod G(x) */, 0xc5df246e /* x^109535 mod G(x) */, },
327
+ /* chunk_len=13824 */
328
+ { 0x8801d0aa /* x^331743 mod G(x) */, 0xb57c7728 /* x^221151 mod G(x) */, 0x5b0c98b9 /* x^110559 mod G(x) */, },
329
+ /* chunk_len=13952 */
330
+ { 0xf89cd7f0 /* x^334815 mod G(x) */, 0xcc396a0b /* x^223199 mod G(x) */, 0xdb799c51 /* x^111583 mod G(x) */, },
331
+ /* chunk_len=14080 */
332
+ { 0x1611a808 /* x^337887 mod G(x) */, 0xaeae6105 /* x^225247 mod G(x) */, 0xb939fcdf /* x^112607 mod G(x) */, },
333
+ /* chunk_len=14208 */
334
+ { 0xe3cdb888 /* x^340959 mod G(x) */, 0x26387824 /* x^227295 mod G(x) */, 0x30d13e5f /* x^113631 mod G(x) */, },
335
+ /* chunk_len=14336 */
336
+ { 0x552a4cf6 /* x^344031 mod G(x) */, 0xee2d04bb /* x^229343 mod G(x) */, 0x70f9947d /* x^114655 mod G(x) */, },
337
+ /* chunk_len=14464 */
338
+ { 0x85e248e9 /* x^347103 mod G(x) */, 0x0a79663f /* x^231391 mod G(x) */, 0x53339cf7 /* x^115679 mod G(x) */, },
339
+ /* chunk_len=14592 */
340
+ { 0x1c61c3e9 /* x^350175 mod G(x) */, 0x8ea1f680 /* x^233439 mod G(x) */, 0x54afca53 /* x^116703 mod G(x) */, },
341
+ /* chunk_len=14720 */
342
+ { 0xb14cfc2b /* x^353247 mod G(x) */, 0x2e073302 /* x^235487 mod G(x) */, 0x10897992 /* x^117727 mod G(x) */, },
343
+ /* chunk_len=14848 */
344
+ { 0x6ec444cc /* x^356319 mod G(x) */, 0x9e819f13 /* x^237535 mod G(x) */, 0x7a3c0a6a /* x^118751 mod G(x) */, },
345
+ /* chunk_len=14976 */
346
+ { 0xe2fa5f80 /* x^359391 mod G(x) */, 0x21f15b59 /* x^239583 mod G(x) */, 0x93102436 /* x^119775 mod G(x) */, },
347
+ /* chunk_len=15104 */
348
+ { 0x6d33f4c6 /* x^362463 mod G(x) */, 0x31a27455 /* x^241631 mod G(x) */, 0x1fea4d2a /* x^120799 mod G(x) */, },
349
+ /* chunk_len=15232 */
350
+ { 0xb6dec609 /* x^365535 mod G(x) */, 0x4d437056 /* x^243679 mod G(x) */, 0x42eb1e2a /* x^121823 mod G(x) */, },
351
+ /* chunk_len=15360 */
352
+ { 0x1846c518 /* x^368607 mod G(x) */, 0x71b74d95 /* x^245727 mod G(x) */, 0xbd2655a8 /* x^122847 mod G(x) */, },
353
+ /* chunk_len=15488 */
354
+ { 0x9f947f8a /* x^371679 mod G(x) */, 0x2b501619 /* x^247775 mod G(x) */, 0xa4924b0e /* x^123871 mod G(x) */, },
355
+ /* chunk_len=15616 */
356
+ { 0xb7442f4d /* x^374751 mod G(x) */, 0xba30a5d8 /* x^249823 mod G(x) */, 0x4ff61aa1 /* x^124895 mod G(x) */, },
357
+ /* chunk_len=15744 */
358
+ { 0xe2c93242 /* x^377823 mod G(x) */, 0x8a2d38e8 /* x^251871 mod G(x) */, 0x70cd7f26 /* x^125919 mod G(x) */, },
359
+ /* chunk_len=15872 */
360
+ { 0xcd6863df /* x^380895 mod G(x) */, 0x78fd88dc /* x^253919 mod G(x) */, 0x7ae2f6f4 /* x^126943 mod G(x) */, },
361
+ /* chunk_len=16000 */
362
+ { 0xd512001d /* x^383967 mod G(x) */, 0xe6612dff /* x^255967 mod G(x) */, 0x5c4d0ca9 /* x^127967 mod G(x) */, },
363
+ /* chunk_len=16128 */
364
+ { 0x4e8d6b6c /* x^387039 mod G(x) */, 0xf997967f /* x^258015 mod G(x) */, 0x2d546c53 /* x^128991 mod G(x) */, },
365
+ /* chunk_len=16256 */
366
+ { 0xfa653ba1 /* x^390111 mod G(x) */, 0xc99014d4 /* x^260063 mod G(x) */, 0xa0c9fd27 /* x^130015 mod G(x) */, },
367
+ /* chunk_len=16384 */
368
+ { 0x49893408 /* x^393183 mod G(x) */, 0x29c2448b /* x^262111 mod G(x) */, 0xe0ee5efe /* x^131039 mod G(x) */, },
369
+ };
370
+
371
+ /* Multipliers for implementations that use a large fixed chunk length */
372
+ #define CRC32_FIXED_CHUNK_LEN 32768UL
373
+ #define CRC32_FIXED_CHUNK_MULT_1 0x29c2448b /* x^262111 mod G(x) */
374
+ #define CRC32_FIXED_CHUNK_MULT_2 0x4b912f53 /* x^524255 mod G(x) */
375
+ #define CRC32_FIXED_CHUNK_MULT_3 0x454c93be /* x^786399 mod G(x) */