brotli 0.2.3 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +37 -0
- data/.github/workflows/publish.yml +24 -0
- data/.gitmodules +1 -1
- data/Gemfile +6 -3
- data/README.md +2 -2
- data/Rakefile +16 -9
- data/brotli.gemspec +7 -13
- data/ext/brotli/brotli.c +210 -31
- data/ext/brotli/buffer.c +1 -7
- data/ext/brotli/buffer.h +1 -1
- data/ext/brotli/extconf.rb +25 -17
- data/lib/brotli/version.rb +1 -1
- data/test/brotli_test.rb +107 -0
- data/test/brotli_writer_test.rb +36 -0
- data/test/test_helper.rb +8 -0
- data/vendor/brotli/c/common/constants.c +15 -0
- data/vendor/brotli/c/common/constants.h +137 -0
- data/vendor/brotli/c/common/context.c +156 -0
- data/vendor/brotli/c/common/context.h +4 -152
- data/vendor/brotli/c/common/dictionary.bin.br +0 -0
- data/vendor/brotli/c/common/dictionary.c +14 -3
- data/vendor/brotli/c/common/platform.c +23 -0
- data/vendor/brotli/c/common/platform.h +95 -122
- data/vendor/brotli/c/common/shared_dictionary.c +521 -0
- data/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
- data/vendor/brotli/c/common/transform.c +60 -4
- data/vendor/brotli/c/common/transform.h +5 -0
- data/vendor/brotli/c/common/version.h +31 -6
- data/vendor/brotli/c/dec/bit_reader.c +34 -4
- data/vendor/brotli/c/dec/bit_reader.h +221 -107
- data/vendor/brotli/c/dec/decode.c +772 -403
- data/vendor/brotli/c/dec/huffman.c +7 -4
- data/vendor/brotli/c/dec/huffman.h +8 -13
- data/vendor/brotli/c/dec/prefix.h +1 -18
- data/vendor/brotli/c/dec/state.c +40 -21
- data/vendor/brotli/c/dec/state.h +201 -59
- data/vendor/brotli/c/enc/backward_references.c +88 -25
- data/vendor/brotli/c/enc/backward_references.h +10 -8
- data/vendor/brotli/c/enc/backward_references_hq.c +194 -80
- data/vendor/brotli/c/enc/backward_references_hq.h +17 -13
- data/vendor/brotli/c/enc/backward_references_inc.h +52 -16
- data/vendor/brotli/c/enc/bit_cost.c +8 -7
- data/vendor/brotli/c/enc/bit_cost.h +5 -4
- data/vendor/brotli/c/enc/block_splitter.c +40 -17
- data/vendor/brotli/c/enc/block_splitter.h +5 -4
- data/vendor/brotli/c/enc/block_splitter_inc.h +99 -49
- data/vendor/brotli/c/enc/brotli_bit_stream.c +142 -137
- data/vendor/brotli/c/enc/brotli_bit_stream.h +11 -6
- data/vendor/brotli/c/enc/cluster.c +10 -9
- data/vendor/brotli/c/enc/cluster.h +7 -6
- data/vendor/brotli/c/enc/cluster_inc.h +30 -22
- data/vendor/brotli/c/enc/command.c +28 -0
- data/vendor/brotli/c/enc/command.h +17 -16
- data/vendor/brotli/c/enc/compound_dictionary.c +207 -0
- data/vendor/brotli/c/enc/compound_dictionary.h +74 -0
- data/vendor/brotli/c/enc/compress_fragment.c +93 -83
- data/vendor/brotli/c/enc/compress_fragment.h +32 -7
- data/vendor/brotli/c/enc/compress_fragment_two_pass.c +100 -88
- data/vendor/brotli/c/enc/compress_fragment_two_pass.h +21 -3
- data/vendor/brotli/c/enc/dictionary_hash.c +1829 -1101
- data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
- data/vendor/brotli/c/enc/encode.c +550 -416
- data/vendor/brotli/c/enc/encoder_dict.c +613 -5
- data/vendor/brotli/c/enc/encoder_dict.h +120 -4
- data/vendor/brotli/c/enc/entropy_encode.c +5 -2
- data/vendor/brotli/c/enc/entropy_encode.h +4 -3
- data/vendor/brotli/c/enc/entropy_encode_static.h +5 -2
- data/vendor/brotli/c/enc/fast_log.c +105 -0
- data/vendor/brotli/c/enc/fast_log.h +21 -101
- data/vendor/brotli/c/enc/find_match_length.h +17 -25
- data/vendor/brotli/c/enc/hash.h +350 -120
- data/vendor/brotli/c/enc/hash_composite_inc.h +71 -67
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +92 -51
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +79 -84
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +53 -54
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +93 -62
- data/vendor/brotli/c/enc/hash_rolling_inc.h +25 -29
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +42 -40
- data/vendor/brotli/c/enc/histogram.c +4 -4
- data/vendor/brotli/c/enc/histogram.h +7 -6
- data/vendor/brotli/c/enc/literal_cost.c +20 -15
- data/vendor/brotli/c/enc/literal_cost.h +4 -2
- data/vendor/brotli/c/enc/memory.c +29 -5
- data/vendor/brotli/c/enc/memory.h +43 -14
- data/vendor/brotli/c/enc/metablock.c +95 -85
- data/vendor/brotli/c/enc/metablock.h +9 -8
- data/vendor/brotli/c/enc/metablock_inc.h +9 -7
- data/vendor/brotli/c/enc/params.h +7 -4
- data/vendor/brotli/c/enc/prefix.h +3 -2
- data/vendor/brotli/c/enc/quality.h +40 -3
- data/vendor/brotli/c/enc/ringbuffer.h +8 -4
- data/vendor/brotli/c/enc/state.h +104 -0
- data/vendor/brotli/c/enc/static_dict.c +60 -4
- data/vendor/brotli/c/enc/static_dict.h +3 -2
- data/vendor/brotli/c/enc/static_dict_lut.h +2 -0
- data/vendor/brotli/c/enc/utf8_util.c +2 -2
- data/vendor/brotli/c/enc/utf8_util.h +2 -1
- data/vendor/brotli/c/enc/write_bits.h +29 -26
- data/vendor/brotli/c/include/brotli/decode.h +67 -2
- data/vendor/brotli/c/include/brotli/encode.h +77 -3
- data/vendor/brotli/c/include/brotli/port.h +34 -3
- data/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
- metadata +23 -97
- data/.travis.yml +0 -31
- data/docs/Brotli/Error.html +0 -124
- data/docs/Brotli.html +0 -485
- data/docs/_index.html +0 -122
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -127
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -127
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -67
- data/docs/top-level-namespace.html +0 -110
- data/spec/brotli_spec.rb +0 -88
- data/spec/inflate_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -4
@@ -4,14 +4,16 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
#include "
|
7
|
+
#include "dictionary.h"
|
8
|
+
#include "platform.h"
|
8
9
|
|
9
10
|
#if defined(__cplusplus) || defined(c_plusplus)
|
10
11
|
extern "C" {
|
11
12
|
#endif
|
12
13
|
|
13
|
-
#
|
14
|
+
#if !defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
|
14
15
|
static const uint8_t kBrotliDictionaryData[] =
|
16
|
+
/* GENERATED CODE START */
|
15
17
|
{
|
16
18
|
116,105,109,101,100,111,119,110,108,105,102,101,108,101,102,116,98,97,99,107,99,
|
17
19
|
111,100,101,100,97,116,97,115,104,111,119,111,110,108,121,115,105,116,101,99,105
|
@@ -5859,10 +5861,15 @@ static const uint8_t kBrotliDictionaryData[] =
|
|
5859
5861
|
,164,181,224,164,190,224,164,136,224,164,184,224,164,149,224,165,141,224,164,176
|
5860
5862
|
,224,164,191,224,164,175,224,164,164,224,164,190
|
5861
5863
|
}
|
5864
|
+
/* GENERATED CODE END */
|
5862
5865
|
;
|
5863
5866
|
#endif /* !BROTLI_EXTERNAL_DICTIONARY_DATA */
|
5864
5867
|
|
5868
|
+
#if !defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
|
5869
|
+
static const BrotliDictionary kBrotliDictionary = {
|
5870
|
+
#else
|
5865
5871
|
static BrotliDictionary kBrotliDictionary = {
|
5872
|
+
#endif
|
5866
5873
|
/* size_bits_by_length */
|
5867
5874
|
{
|
5868
5875
|
0, 0, 0, 0, 10, 10, 11, 11,
|
@@ -5890,14 +5897,18 @@ static BrotliDictionary kBrotliDictionary = {
|
|
5890
5897
|
#endif
|
5891
5898
|
};
|
5892
5899
|
|
5893
|
-
const BrotliDictionary* BrotliGetDictionary() {
|
5900
|
+
const BrotliDictionary* BrotliGetDictionary(void) {
|
5894
5901
|
return &kBrotliDictionary;
|
5895
5902
|
}
|
5896
5903
|
|
5897
5904
|
void BrotliSetDictionaryData(const uint8_t* data) {
|
5905
|
+
#if defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
|
5898
5906
|
if (!!data && !kBrotliDictionary.data) {
|
5899
5907
|
kBrotliDictionary.data = data;
|
5900
5908
|
}
|
5909
|
+
#else
|
5910
|
+
BROTLI_UNUSED(data); // Appease -Werror=unused-parameter
|
5911
|
+
#endif
|
5901
5912
|
}
|
5902
5913
|
|
5903
5914
|
#if defined(__cplusplus) || defined(c_plusplus)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/* Copyright 2016 Google Inc. All Rights Reserved.
|
2
|
+
|
3
|
+
Distributed under MIT license.
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdlib.h>
|
8
|
+
|
9
|
+
#include <brotli/types.h>
|
10
|
+
|
11
|
+
#include "platform.h"
|
12
|
+
|
13
|
+
/* Default brotli_alloc_func */
|
14
|
+
void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
|
15
|
+
BROTLI_UNUSED(opaque);
|
16
|
+
return malloc(size);
|
17
|
+
}
|
18
|
+
|
19
|
+
/* Default brotli_free_func */
|
20
|
+
void BrotliDefaultFreeFunc(void* opaque, void* address) {
|
21
|
+
BROTLI_UNUSED(opaque);
|
22
|
+
free(address);
|
23
|
+
}
|
@@ -12,24 +12,24 @@
|
|
12
12
|
* BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
|
13
13
|
* BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
|
14
14
|
* BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
|
15
|
-
* BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
|
16
|
-
read and overlapping memcpy; this reduces decompression speed by 5%
|
17
15
|
* BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
|
16
|
+
* BROTLI_BUILD_NO_UNALIGNED_READ_FAST forces off the fast-unaligned-read
|
17
|
+
optimizations (mainly for testing purposes)
|
18
18
|
* BROTLI_DEBUG dumps file name and line number when decoder detects stream
|
19
19
|
or memory error
|
20
20
|
* BROTLI_ENABLE_LOG enables asserts and dumps various state information
|
21
|
+
* BROTLI_ENABLE_DUMP overrides default "dump" behaviour
|
21
22
|
*/
|
22
23
|
|
23
24
|
#ifndef BROTLI_COMMON_PLATFORM_H_
|
24
25
|
#define BROTLI_COMMON_PLATFORM_H_
|
25
26
|
|
26
27
|
#include <string.h> /* memcpy */
|
27
|
-
#include <stdlib.h> /* malloc, free */
|
28
28
|
|
29
29
|
#include <brotli/port.h>
|
30
30
|
#include <brotli/types.h>
|
31
31
|
|
32
|
-
#if defined(OS_LINUX) || defined(OS_CYGWIN)
|
32
|
+
#if defined(OS_LINUX) || defined(OS_CYGWIN) || defined(__EMSCRIPTEN__)
|
33
33
|
#include <endian.h>
|
34
34
|
#elif defined(OS_FREEBSD)
|
35
35
|
#include <machine/endian.h>
|
@@ -41,6 +41,10 @@
|
|
41
41
|
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
|
42
42
|
#endif
|
43
43
|
|
44
|
+
#if BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
45
|
+
#include <intrin.h>
|
46
|
+
#endif
|
47
|
+
|
44
48
|
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
|
45
49
|
#include <assert.h>
|
46
50
|
#include <stdio.h>
|
@@ -153,24 +157,6 @@ OR:
|
|
153
157
|
#define BROTLI_NOINLINE
|
154
158
|
#endif
|
155
159
|
|
156
|
-
/* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
|
157
|
-
#if !defined(BROTLI_INTERNAL)
|
158
|
-
#if defined(_WIN32) || defined(__CYGWIN__)
|
159
|
-
#define BROTLI_INTERNAL
|
160
|
-
#elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
|
161
|
-
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
162
|
-
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
163
|
-
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
164
|
-
BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
|
165
|
-
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
166
|
-
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
|
167
|
-
defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
|
168
|
-
#define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
|
169
|
-
#else
|
170
|
-
#define BROTLI_INTERNAL
|
171
|
-
#endif
|
172
|
-
#endif
|
173
|
-
|
174
160
|
/* <<< <<< <<< end of hedley macros. */
|
175
161
|
|
176
162
|
#if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \
|
@@ -223,15 +209,24 @@ OR:
|
|
223
209
|
#define BROTLI_TARGET_RISCV64
|
224
210
|
#endif
|
225
211
|
|
212
|
+
#if defined(__loongarch_lp64)
|
213
|
+
#define BROTLI_TARGET_LOONGARCH64
|
214
|
+
#endif
|
215
|
+
|
216
|
+
#if defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \
|
217
|
+
defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64) || \
|
218
|
+
defined(BROTLI_TARGET_LOONGARCH64)
|
219
|
+
#define BROTLI_TARGET_64_BITS 1
|
220
|
+
#else
|
221
|
+
#define BROTLI_TARGET_64_BITS 0
|
222
|
+
#endif
|
223
|
+
|
226
224
|
#if defined(BROTLI_BUILD_64_BIT)
|
227
225
|
#define BROTLI_64_BITS 1
|
228
226
|
#elif defined(BROTLI_BUILD_32_BIT)
|
229
227
|
#define BROTLI_64_BITS 0
|
230
|
-
#elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \
|
231
|
-
defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64)
|
232
|
-
#define BROTLI_64_BITS 1
|
233
228
|
#else
|
234
|
-
#define BROTLI_64_BITS
|
229
|
+
#define BROTLI_64_BITS BROTLI_TARGET_64_BITS
|
235
230
|
#endif
|
236
231
|
|
237
232
|
#if (BROTLI_64_BITS)
|
@@ -275,18 +270,19 @@ OR:
|
|
275
270
|
#undef BROTLI_X_BIG_ENDIAN
|
276
271
|
#endif
|
277
272
|
|
278
|
-
#if defined(
|
279
|
-
#define
|
280
|
-
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) ||
|
273
|
+
#if defined(BROTLI_BUILD_NO_UNALIGNED_READ_FAST)
|
274
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!0)
|
275
|
+
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
|
281
276
|
defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) || \
|
282
|
-
defined(BROTLI_TARGET_RISCV64)
|
283
|
-
/*
|
284
|
-
|
277
|
+
defined(BROTLI_TARGET_RISCV64) || defined(BROTLI_TARGET_LOONGARCH64)
|
278
|
+
/* These targets are known to generate efficient code for unaligned reads
|
279
|
+
* (e.g. a single instruction, not multiple 1-byte loads, shifted and or'd
|
280
|
+
* together). */
|
281
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!1)
|
285
282
|
#else
|
286
|
-
#define
|
283
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!0)
|
287
284
|
#endif
|
288
285
|
|
289
|
-
#if BROTLI_ALIGNED_READ
|
290
286
|
/* Portable unaligned memory access: read / write values via memcpy. */
|
291
287
|
static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
|
292
288
|
uint16_t t;
|
@@ -306,76 +302,6 @@ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
|
306
302
|
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
307
303
|
memcpy(p, &v, sizeof v);
|
308
304
|
}
|
309
|
-
#else /* BROTLI_ALIGNED_READ */
|
310
|
-
/* Unaligned memory access is allowed: just cast pointer to requested type. */
|
311
|
-
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
|
312
|
-
defined(MEMORY_SANITIZER)
|
313
|
-
/* Consider we have an unaligned load/store of 4 bytes from address 0x...05.
|
314
|
-
AddressSanitizer will treat it as a 3-byte access to the range 05:07 and
|
315
|
-
will miss a bug if 08 is the first unaddressable byte.
|
316
|
-
ThreadSanitizer will also treat this as a 3-byte access to 05:07 and will
|
317
|
-
miss a race between this access and some other accesses to 08.
|
318
|
-
MemorySanitizer will correctly propagate the shadow on unaligned stores
|
319
|
-
and correctly report bugs on unaligned loads, but it may not properly
|
320
|
-
update and report the origin of the uninitialized memory.
|
321
|
-
For all three tools, replacing an unaligned access with a tool-specific
|
322
|
-
callback solves the problem. */
|
323
|
-
#if defined(__cplusplus)
|
324
|
-
extern "C" {
|
325
|
-
#endif /* __cplusplus */
|
326
|
-
uint16_t __sanitizer_unaligned_load16(const void* p);
|
327
|
-
uint32_t __sanitizer_unaligned_load32(const void* p);
|
328
|
-
uint64_t __sanitizer_unaligned_load64(const void* p);
|
329
|
-
void __sanitizer_unaligned_store64(void* p, uint64_t v);
|
330
|
-
#if defined(__cplusplus)
|
331
|
-
} /* extern "C" */
|
332
|
-
#endif /* __cplusplus */
|
333
|
-
#define BrotliUnalignedRead16 __sanitizer_unaligned_load16
|
334
|
-
#define BrotliUnalignedRead32 __sanitizer_unaligned_load32
|
335
|
-
#define BrotliUnalignedRead64 __sanitizer_unaligned_load64
|
336
|
-
#define BrotliUnalignedWrite64 __sanitizer_unaligned_store64
|
337
|
-
#else
|
338
|
-
static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
|
339
|
-
return *(const uint16_t*)p;
|
340
|
-
}
|
341
|
-
static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
|
342
|
-
return *(const uint32_t*)p;
|
343
|
-
}
|
344
|
-
#if (BROTLI_64_BITS)
|
345
|
-
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
346
|
-
return *(const uint64_t*)p;
|
347
|
-
}
|
348
|
-
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
349
|
-
*(uint64_t*)p = v;
|
350
|
-
}
|
351
|
-
#else /* BROTLI_64_BITS */
|
352
|
-
/* Avoid emitting LDRD / STRD, which require properly aligned address. */
|
353
|
-
/* If __attribute__(aligned) is available, use that. Otherwise, memcpy. */
|
354
|
-
|
355
|
-
#if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0)
|
356
|
-
typedef BROTLI_ALIGNED(1) uint64_t brotli_unaligned_uint64_t;
|
357
|
-
|
358
|
-
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
359
|
-
return (uint64_t) ((brotli_unaligned_uint64_t*) p)[0];
|
360
|
-
}
|
361
|
-
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
362
|
-
brotli_unaligned_uint64_t* dwords = (brotli_unaligned_uint64_t*) p;
|
363
|
-
dwords[0] = (brotli_unaligned_uint64_t) v;
|
364
|
-
}
|
365
|
-
#else /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
|
366
|
-
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
367
|
-
uint64_t v;
|
368
|
-
memcpy(&v, p, sizeof(uint64_t));
|
369
|
-
return v;
|
370
|
-
}
|
371
|
-
|
372
|
-
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
373
|
-
memcpy(p, &v, sizeof(uint64_t));
|
374
|
-
}
|
375
|
-
#endif /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
|
376
|
-
#endif /* BROTLI_64_BITS */
|
377
|
-
#endif /* ASAN / TSAN / MSAN */
|
378
|
-
#endif /* BROTLI_ALIGNED_READ */
|
379
305
|
|
380
306
|
#if BROTLI_LITTLE_ENDIAN
|
381
307
|
/* Straight endianness. Just read / write values. */
|
@@ -451,6 +377,16 @@ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
451
377
|
}
|
452
378
|
#endif /* BROTLI_LITTLE_ENDIAN */
|
453
379
|
|
380
|
+
static BROTLI_INLINE void* BROTLI_UNALIGNED_LOAD_PTR(const void* p) {
|
381
|
+
void* v;
|
382
|
+
memcpy(&v, p, sizeof(void*));
|
383
|
+
return v;
|
384
|
+
}
|
385
|
+
|
386
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE_PTR(void* p, const void* v) {
|
387
|
+
memcpy(p, &v, sizeof(void*));
|
388
|
+
}
|
389
|
+
|
454
390
|
/* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */
|
455
391
|
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \
|
456
392
|
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
@@ -466,14 +402,24 @@ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
466
402
|
#endif
|
467
403
|
|
468
404
|
#if defined(BROTLI_ENABLE_LOG)
|
469
|
-
#define BROTLI_DCHECK(x) assert(x)
|
470
405
|
#define BROTLI_LOG(x) printf x
|
471
406
|
#else
|
472
|
-
#define BROTLI_DCHECK(x)
|
473
407
|
#define BROTLI_LOG(x)
|
474
408
|
#endif
|
475
409
|
|
476
410
|
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
|
411
|
+
#define BROTLI_ENABLE_DUMP_DEFAULT 1
|
412
|
+
#define BROTLI_DCHECK(x) assert(x)
|
413
|
+
#else
|
414
|
+
#define BROTLI_ENABLE_DUMP_DEFAULT 0
|
415
|
+
#define BROTLI_DCHECK(x)
|
416
|
+
#endif
|
417
|
+
|
418
|
+
#if !defined(BROTLI_ENABLE_DUMP)
|
419
|
+
#define BROTLI_ENABLE_DUMP BROTLI_ENABLE_DUMP_DEFAULT
|
420
|
+
#endif
|
421
|
+
|
422
|
+
#if BROTLI_ENABLE_DUMP
|
477
423
|
static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
|
478
424
|
fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
|
479
425
|
fflush(stderr);
|
@@ -483,11 +429,13 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
|
|
483
429
|
#define BROTLI_DUMP() (void)(0)
|
484
430
|
#endif
|
485
431
|
|
486
|
-
/*
|
432
|
+
/* BrotliRBit assumes brotli_reg_t fits native CPU register type. */
|
433
|
+
#if (BROTLI_64_BITS == BROTLI_TARGET_64_BITS)
|
434
|
+
/* TODO(eustas): add appropriate icc/sunpro/arm/ibm/ti checks. */
|
487
435
|
#if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
|
488
436
|
!defined(BROTLI_BUILD_NO_RBIT)
|
489
437
|
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
|
490
|
-
/* TODO: detect ARMv6T2 and enable this code for it. */
|
438
|
+
/* TODO(eustas): detect ARMv6T2 and enable this code for it. */
|
491
439
|
static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
|
492
440
|
brotli_reg_t output;
|
493
441
|
__asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
|
@@ -496,15 +444,14 @@ static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
|
|
496
444
|
#define BROTLI_RBIT(x) BrotliRBit(x)
|
497
445
|
#endif /* armv7 / armv8 */
|
498
446
|
#endif /* gcc || clang */
|
447
|
+
#endif /* brotli_reg_t is native */
|
499
448
|
#if !defined(BROTLI_RBIT)
|
500
449
|
static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }
|
501
450
|
#endif /* BROTLI_RBIT */
|
502
451
|
|
503
|
-
#define
|
504
|
-
|
505
|
-
|
506
|
-
if ((N & 4) != 0) {X; X; X; X;} \
|
507
|
-
}
|
452
|
+
#define BROTLI_REPEAT_4(X) {X; X; X; X;}
|
453
|
+
#define BROTLI_REPEAT_5(X) {X; X; X; X; X;}
|
454
|
+
#define BROTLI_REPEAT_6(X) {X; X; X; X; X; X;}
|
508
455
|
|
509
456
|
#define BROTLI_UNUSED(X) (void)(X)
|
510
457
|
|
@@ -523,17 +470,41 @@ BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
|
|
523
470
|
(A)[(J)] = __brotli_swap_tmp; \
|
524
471
|
}
|
525
472
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
473
|
+
#if BROTLI_64_BITS
|
474
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \
|
475
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
476
|
+
#define BROTLI_TZCNT64 __builtin_ctzll
|
477
|
+
#elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
478
|
+
#if defined(BROTLI_TARGET_X64)
|
479
|
+
#define BROTLI_TZCNT64 _tzcnt_u64
|
480
|
+
#else /* BROTLI_TARGET_X64 */
|
481
|
+
static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) {
|
482
|
+
uint32_t lsb;
|
483
|
+
_BitScanForward64(&lsb, x);
|
484
|
+
return lsb;
|
530
485
|
}
|
486
|
+
#define BROTLI_TZCNT64 BrotliBsf64Msvc
|
487
|
+
#endif /* BROTLI_TARGET_X64 */
|
488
|
+
#endif /* __builtin_ctzll */
|
489
|
+
#endif /* BROTLI_64_BITS */
|
531
490
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
491
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
|
492
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
493
|
+
#define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x))
|
494
|
+
#elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
495
|
+
static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) {
|
496
|
+
unsigned long msb;
|
497
|
+
_BitScanReverse(&msb, x);
|
498
|
+
return (uint32_t)msb;
|
536
499
|
}
|
500
|
+
#define BROTLI_BSR32 BrotliBsr32Msvc
|
501
|
+
#endif /* __builtin_clz */
|
502
|
+
|
503
|
+
/* Default brotli_alloc_func */
|
504
|
+
BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size);
|
505
|
+
|
506
|
+
/* Default brotli_free_func */
|
507
|
+
BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address);
|
537
508
|
|
538
509
|
BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
|
539
510
|
BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
|
@@ -545,6 +516,8 @@ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
|
|
545
516
|
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
|
546
517
|
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
|
547
518
|
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
|
519
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD_PTR);
|
520
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE_PTR);
|
548
521
|
BROTLI_UNUSED(&BrotliRBit);
|
549
522
|
BROTLI_UNUSED(&brotli_min_double);
|
550
523
|
BROTLI_UNUSED(&brotli_max_double);
|
@@ -560,7 +533,7 @@ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
|
|
560
533
|
BROTLI_UNUSED(&brotli_max_uint8_t);
|
561
534
|
BROTLI_UNUSED(&BrotliDefaultAllocFunc);
|
562
535
|
BROTLI_UNUSED(&BrotliDefaultFreeFunc);
|
563
|
-
#if
|
536
|
+
#if BROTLI_ENABLE_DUMP
|
564
537
|
BROTLI_UNUSED(&BrotliDump);
|
565
538
|
#endif
|
566
539
|
}
|