diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-05-04 04:54:00 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-05-04 04:54:00 +0000 |
commit | 1bab9f565782a0f389314cb1a5dfc6f597d96e22 (patch) | |
tree | cda8c972ba15244ffa89e88d743a2cdce0fa99e6 /Build/source/texk/dvisvgm/dvisvgm-src/libs | |
parent | 90faf12dc7ac78559d3bb81953320d776a835e4b (diff) |
dvisvgm-2.4
git-svn-id: svn://tug.org/texlive/trunk@47608 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/libs')
21 files changed, 600 insertions, 628 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.am b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.am index bb1abc712a1..0d003184008 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.am +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.am @@ -29,7 +29,6 @@ libbrotli_a_SOURCES = \ enc/compress_fragment.h \ enc/compress_fragment_two_pass.c \ enc/compress_fragment_two_pass.h \ - enc/context.h \ enc/dictionary_hash.c \ enc/dictionary_hash.h \ enc/encode.c \ @@ -57,7 +56,6 @@ libbrotli_a_SOURCES = \ enc/metablock.h \ enc/metablock_inc.h \ enc/params.h \ - enc/port.h \ enc/prefix.h \ enc/quality.h \ enc/ringbuffer.h \ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.in b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.in index 01005633007..0d53a841126 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.in +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/Makefile.in @@ -375,7 +375,6 @@ libbrotli_a_SOURCES = \ enc/compress_fragment.h \ enc/compress_fragment_two_pass.c \ enc/compress_fragment_two_pass.h \ - enc/context.h \ enc/dictionary_hash.c \ enc/dictionary_hash.h \ enc/encode.c \ @@ -403,7 +402,6 @@ libbrotli_a_SOURCES = \ enc/metablock.h \ enc/metablock_inc.h \ enc/params.h \ - enc/port.h \ enc/prefix.h \ enc/quality.h \ enc/ringbuffer.h \ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/constants.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/constants.h index 26edcd59218..d1b88d12af3 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/constants.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/constants.h @@ -38,7 +38,7 @@ #define BROTLI_MAX_NPOSTFIX 3 #define BROTLI_MAX_NDIRECT 120 #define BROTLI_MAX_DISTANCE_BITS 24U -#define BROTLI_DISTANCE_ALPHABET_SIZE(NDIRECT, NPOSTFIX, MAXNBITS) ( \ +#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \ BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) + \ ((MAXNBITS) << ((NPOSTFIX) + 1))) /* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/platform.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/platform.h index d6fd3ee90e9..8d1429094c8 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/platform.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/platform.h @@ -99,17 +99,15 @@ #define BROTLI_NOINLINE #endif -#if defined(__arm__) || defined(__thumb__) || \ - defined(_M_ARM) || defined(_M_ARMT) || defined(__ARM64_ARCH_8__) -#define BROTLI_TARGET_ARM #if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \ (defined(M_ARM) && (M_ARM == 7)) #define BROTLI_TARGET_ARMV7 #endif /* ARMv7 */ -#if defined(__aarch64__) || defined(__ARM64_ARCH_8__) + +#if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \ + defined(__aarch64__) || defined(__ARM64_ARCH_8__) #define BROTLI_TARGET_ARMV8 #endif /* ARMv8 */ -#endif /* ARM */ #if defined(__i386) || defined(_M_IX86) #define BROTLI_TARGET_X86 @@ -213,12 +211,25 @@ static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) { static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) { return *(const uint32_t*)p; } +#if (BROTLI_64_BITS) static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) { return *(const uint64_t*)p; } static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { *(uint64_t*)p = v; } +#else /* BROTLI_64_BITS */ +/* Avoid emitting LDRD / STRD, which require properly aligned address. */ +static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) { + const uint32_t* dwords = (const uint32_t*)p; + return dwords[0] | ((uint64_t)dwords[1] << 32); +} +static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { + uint32_t* dwords = (uint32_t *)p; + dwords[0] = (uint32_t)v; + dwords[1] = (uint32_t)(v >> 32); +} +#endif /* BROTLI_64_BITS */ #endif /* BROTLI_ALIGNED_READ */ #if BROTLI_LITTLE_ENDIAN @@ -328,7 +339,7 @@ OR: #define BROTLI_IS_CONSTANT(x) (!!0) #endif -#if defined(BROTLI_TARGET_ARM) +#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8) #define BROTLI_HAS_UBFX (!!1) #else #define BROTLI_HAS_UBFX (!!0) @@ -362,7 +373,7 @@ static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) { return output; } #define BROTLI_RBIT(x) BrotliRBit(x) -#endif /* armv7 */ +#endif /* armv7 / armv8 */ #endif /* gcc || clang */ #if !defined(BROTLI_RBIT) static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/version.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/version.h index 435371c2d8d..54470f6006f 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/version.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/common/version.h @@ -14,13 +14,13 @@ BrotliEncoderVersion methods. */ /* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */ -#define BROTLI_VERSION 0x1000003 +#define BROTLI_VERSION 0x1000004 /* This macro is used by build system to produce Libtool-friendly soname. See https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html */ /* ABI version, calculated as (CURRENT << 24) | (REVISION << 12) | AGE */ -#define BROTLI_ABI_VERSION 0x1003000 +#define BROTLI_ABI_VERSION 0x1004000 #endif /* BROTLI_COMMON_VERSION_H_ */ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references.c index 62ecea75dfb..3dd897b217a 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references.c +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references.c @@ -49,6 +49,7 @@ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance, #define CAT(a, b) a ## b #define FN(X) EXPAND_CAT(X, HASHER()) #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER())) + #define PREFIX() N #define HASHER() H2 @@ -97,6 +98,7 @@ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance, #undef HASHER #undef PREFIX + #undef EXPORT_FN #undef FN #undef CAT diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references_hq.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references_hq.c index 62c6ba24a7b..e7486c4584b 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references_hq.c +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/backward_references_hq.c @@ -76,7 +76,7 @@ typedef struct ZopfliCostModel { /* The insert and copy length symbols. */ float cost_cmd_[BROTLI_NUM_COMMAND_SYMBOLS]; float* cost_dist_; - uint32_t distance_alphabet_size; + uint32_t distance_histogram_size; /* Cumulative costs of literals per position in the stream. */ float* literal_costs_; float min_cost_cmd_; @@ -86,10 +86,14 @@ typedef struct ZopfliCostModel { static void InitZopfliCostModel( MemoryManager* m, ZopfliCostModel* self, const BrotliDistanceParams* dist, size_t num_bytes) { + uint32_t distance_histogram_size = dist->alphabet_size; + if (distance_histogram_size > BROTLI_MAX_EFFECTIVE_DISTANCE_ALPHABET_SIZE) { + distance_histogram_size = BROTLI_MAX_EFFECTIVE_DISTANCE_ALPHABET_SIZE; + } self->num_bytes_ = num_bytes; self->literal_costs_ = BROTLI_ALLOC(m, float, num_bytes + 2); self->cost_dist_ = BROTLI_ALLOC(m, float, dist->alphabet_size); - self->distance_alphabet_size = dist->alphabet_size; + self->distance_histogram_size = distance_histogram_size; if (BROTLI_IS_OOM(m)) return; } @@ -171,7 +175,7 @@ static void ZopfliCostModelSetFromCommands(ZopfliCostModel* self, cost_literal); SetCost(histogram_cmd, BROTLI_NUM_COMMAND_SYMBOLS, BROTLI_FALSE, cost_cmd); - SetCost(histogram_dist, self->distance_alphabet_size, BROTLI_FALSE, + SetCost(histogram_dist, self->distance_histogram_size, BROTLI_FALSE, self->cost_dist_); for (i = 0; i < BROTLI_NUM_COMMAND_SYMBOLS; ++i) { @@ -214,7 +218,7 @@ static void ZopfliCostModelSetFromLiteralCosts(ZopfliCostModel* self, for (i = 0; i < BROTLI_NUM_COMMAND_SYMBOLS; ++i) { cost_cmd[i] = (float)FastLog2(11 + (uint32_t)i); } - for (i = 0; i < self->distance_alphabet_size; ++i) { + for (i = 0; i < self->distance_histogram_size; ++i) { cost_dist[i] = (float)FastLog2(20 + (uint32_t)i); } self->min_cost_cmd_ = (float)FastLog2(11); diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/command.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/command.h index 6075dfe5b18..3fcf186b49f 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/command.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/command.h @@ -145,11 +145,11 @@ static BROTLI_INLINE void InitInsertCommand(Command* self, size_t insertlen) { static BROTLI_INLINE uint32_t CommandRestoreDistanceCode( const Command* self, const BrotliDistanceParams* dist) { - if ((self->dist_prefix_ & 0x3FF) < + if ((self->dist_prefix_ & 0x3FFu) < BROTLI_NUM_DISTANCE_SHORT_CODES + dist->num_direct_distance_codes) { - return self->dist_prefix_ & 0x3FF; + return self->dist_prefix_ & 0x3FFu; } else { - uint32_t dcode = self->dist_prefix_ & 0x3FF; + uint32_t dcode = self->dist_prefix_ & 0x3FFu; uint32_t nbits = self->dist_prefix_ >> 10; uint32_t extra = self->dist_extra_; uint32_t postfix_mask = (1U << dist->distance_postfix_bits) - 1U; diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/context.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/context.h deleted file mode 100644 index 0e2e453a4b5..00000000000 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/context.h +++ /dev/null @@ -1,184 +0,0 @@ -/* Copyright 2013 Google Inc. All Rights Reserved. - - Distributed under MIT license. - See file LICENSE for detail or copy at https://opensource.org/licenses/MIT -*/ - -/* Functions to map previous bytes into a context id. */ - -#ifndef BROTLI_ENC_CONTEXT_H_ -#define BROTLI_ENC_CONTEXT_H_ - -#include <brotli/port.h> -#include <brotli/types.h> - -#if defined(__cplusplus) || defined(c_plusplus) -extern "C" { -#endif - -/* Second-order context lookup table for UTF8 byte streams. - - If p1 and p2 are the previous two bytes, we calculate the context as - - context = kUTF8ContextLookup[p1] | kUTF8ContextLookup[p2 + 256]. - - If the previous two bytes are ASCII characters (i.e. < 128), this will be - equivalent to - - context = 4 * context1(p1) + context2(p2), - - where context1 is based on the previous byte in the following way: - - 0 : non-ASCII control - 1 : \t, \n, \r - 2 : space - 3 : other punctuation - 4 : " ' - 5 : % - 6 : ( < [ { - 7 : ) > ] } - 8 : , ; : - 9 : . - 10 : = - 11 : number - 12 : upper-case vowel - 13 : upper-case consonant - 14 : lower-case vowel - 15 : lower-case consonant - - and context2 is based on the second last byte: - - 0 : control, space - 1 : punctuation - 2 : upper-case letter, number - 3 : lower-case letter - - If the last byte is ASCII, and the second last byte is not (in a valid UTF8 - stream it will be a continuation byte, value between 128 and 191), the - context is the same as if the second last byte was an ASCII control or space. - - If the last byte is a UTF8 lead byte (value >= 192), then the next byte will - be a continuation byte and the context id is 2 or 3 depending on the LSB of - the last byte and to a lesser extent on the second last byte if it is ASCII. - - If the last byte is a UTF8 continuation byte, the second last byte can be: - - continuation byte: the next byte is probably ASCII or lead byte (assuming - 4-byte UTF8 characters are rare) and the context id is 0 or 1. - - lead byte (192 - 207): next byte is ASCII or lead byte, context is 0 or 1 - - lead byte (208 - 255): next byte is continuation byte, context is 2 or 3 - - The possible value combinations of the previous two bytes, the range of - context ids and the type of the next byte is summarized in the table below: - - |--------\-----------------------------------------------------------------| - | \ Last byte | - | Second \---------------------------------------------------------------| - | last byte \ ASCII | cont. byte | lead byte | - | \ (0-127) | (128-191) | (192-) | - |=============|===================|=====================|==================| - | ASCII | next: ASCII/lead | not valid | next: cont. | - | (0-127) | context: 4 - 63 | | context: 2 - 3 | - |-------------|-------------------|---------------------|------------------| - | cont. byte | next: ASCII/lead | next: ASCII/lead | next: cont. | - | (128-191) | context: 4 - 63 | context: 0 - 1 | context: 2 - 3 | - |-------------|-------------------|---------------------|------------------| - | lead byte | not valid | next: ASCII/lead | not valid | - | (192-207) | | context: 0 - 1 | | - |-------------|-------------------|---------------------|------------------| - | lead byte | not valid | next: cont. | not valid | - | (208-) | | context: 2 - 3 | | - |-------------|-------------------|---------------------|------------------| -*/ -static const uint8_t kUTF8ContextLookup[512] = { - /* Last byte. */ - /* */ - /* ASCII range. */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 8, 12, 16, 12, 12, 20, 12, 16, 24, 28, 12, 12, 32, 12, 36, 12, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 32, 32, 24, 40, 28, 12, - 12, 48, 52, 52, 52, 48, 52, 52, 52, 48, 52, 52, 52, 52, 52, 48, - 52, 52, 52, 52, 52, 48, 52, 52, 52, 52, 52, 24, 12, 28, 12, 12, - 12, 56, 60, 60, 60, 56, 60, 60, 60, 56, 60, 60, 60, 60, 60, 56, - 60, 60, 60, 60, 60, 56, 60, 60, 60, 60, 60, 24, 12, 28, 12, 0, - /* UTF8 continuation byte range. */ - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - /* UTF8 lead byte range. */ - 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, - 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, - 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, - 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, - /* Second last byte. */ - /* */ - /* ASCII range. */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, - 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, - 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 0, - /* UTF8 continuation byte range. */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* UTF8 lead byte range. */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -}; - -/* Context lookup table for small signed integers. */ -static const uint8_t kSigned3BitContextLookup[] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, -}; - -typedef enum ContextType { - CONTEXT_LSB6 = 0, - CONTEXT_MSB6 = 1, - CONTEXT_UTF8 = 2, - CONTEXT_SIGNED = 3 -} ContextType; - -static BROTLI_INLINE uint8_t Context(uint8_t p1, uint8_t p2, ContextType mode) { - switch (mode) { - case CONTEXT_LSB6: - return p1 & 0x3f; - case CONTEXT_MSB6: - return (uint8_t)(p1 >> 2); - case CONTEXT_UTF8: - return kUTF8ContextLookup[p1] | kUTF8ContextLookup[p2 + 256]; - case CONTEXT_SIGNED: - return (uint8_t)((kSigned3BitContextLookup[p1] << 3) + - kSigned3BitContextLookup[p2]); - default: - return 0; - } -} - -#if defined(__cplusplus) || defined(c_plusplus) -} /* extern "C" */ -#endif - -#endif /* BROTLI_ENC_CONTEXT_H_ */ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/encode.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/encode.c index 563c8270a61..4bf0cb4d98a 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/encode.c +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/encode.c @@ -167,6 +167,14 @@ BROTLI_BOOL BrotliEncoderSetParameter( state->params.large_window = TO_BROTLI_BOOL(!!value); return BROTLI_TRUE; + case BROTLI_PARAM_NPOSTFIX: + state->params.dist.distance_postfix_bits = value; + return BROTLI_TRUE; + + case BROTLI_PARAM_NDIRECT: + state->params.dist.num_direct_distance_codes = value; + return BROTLI_TRUE; + default: return BROTLI_FALSE; } } @@ -545,6 +553,7 @@ static void WriteMetaBlockInternal(MemoryManager* m, uint16_t last_bytes; uint8_t last_bytes_bits; ContextLut literal_context_lut = BROTLI_CONTEXT_LUT(literal_context_mode); + BrotliEncoderParams block_params = *params; if (bytes == 0) { /* Write the ISLAST and ISEMPTY bits. */ @@ -596,7 +605,7 @@ static void WriteMetaBlockInternal(MemoryManager* m, literal_context_map, commands, num_commands, &mb); if (BROTLI_IS_OOM(m)) return; } else { - BrotliBuildMetaBlock(m, data, wrapped_last_flush_pos, mask, params, + BrotliBuildMetaBlock(m, data, wrapped_last_flush_pos, mask, &block_params, prev_byte, prev_byte2, commands, num_commands, literal_context_mode, @@ -604,9 +613,10 @@ static void WriteMetaBlockInternal(MemoryManager* m, if (BROTLI_IS_OOM(m)) return; } if (params->quality >= MIN_QUALITY_FOR_OPTIMIZE_HISTOGRAMS) { - /* The number of distance symbols effectively used by - "Large Window Brotli" (32-bit). */ - uint32_t num_effective_dist_codes = params->dist.alphabet_size; + /* The number of distance symbols effectively used for distance + histograms. It might be less than distance alphabet size + for "Large Window Brotli" (32-bit). */ + uint32_t num_effective_dist_codes = block_params.dist.alphabet_size; if (num_effective_dist_codes > BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS) { num_effective_dist_codes = BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS; } @@ -615,7 +625,7 @@ static void WriteMetaBlockInternal(MemoryManager* m, BrotliStoreMetaBlock(m, data, wrapped_last_flush_pos, bytes, mask, prev_byte, prev_byte2, is_last, - params, + &block_params, literal_context_mode, commands, num_commands, &mb, @@ -636,37 +646,29 @@ static void WriteMetaBlockInternal(MemoryManager* m, } static void ChooseDistanceParams(BrotliEncoderParams* params) { - /* NDIRECT, NPOSTFIX must be both zero for qualities - up to MIN_QUALITY_FOR_BLOCK_SPLIT == 3. */ - uint32_t num_direct_distance_codes = 0; uint32_t distance_postfix_bits = 0; - uint32_t alphabet_size; - size_t max_distance = BROTLI_MAX_DISTANCE; - - if (params->quality >= MIN_QUALITY_FOR_RECOMPUTE_DISTANCE_PREFIXES && - params->mode == BROTLI_MODE_FONT) { - num_direct_distance_codes = 12; - distance_postfix_bits = 1; - max_distance = (1U << 27) + 4; - } - - alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE( - num_direct_distance_codes, distance_postfix_bits, - BROTLI_MAX_DISTANCE_BITS); - if (params->large_window) { - max_distance = BROTLI_MAX_ALLOWED_DISTANCE; - if (num_direct_distance_codes != 0 || distance_postfix_bits != 0) { - max_distance = (3U << 29) - 4; + uint32_t num_direct_distance_codes = 0; + + if (params->quality >= MIN_QUALITY_FOR_NONZERO_DISTANCE_PARAMS) { + uint32_t ndirect_msb; + if (params->mode == BROTLI_MODE_FONT) { + distance_postfix_bits = 1; + num_direct_distance_codes = 12; + } else { + distance_postfix_bits = params->dist.distance_postfix_bits; + num_direct_distance_codes = params->dist.num_direct_distance_codes; + } + ndirect_msb = (num_direct_distance_codes >> distance_postfix_bits) & 0x0F; + if (distance_postfix_bits > BROTLI_MAX_NPOSTFIX || + num_direct_distance_codes > BROTLI_MAX_NDIRECT || + (ndirect_msb << distance_postfix_bits) != num_direct_distance_codes) { + distance_postfix_bits = 0; + num_direct_distance_codes = 0; } - alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE( - num_direct_distance_codes, distance_postfix_bits, - BROTLI_LARGE_MAX_DISTANCE_BITS); } - params->dist.num_direct_distance_codes = num_direct_distance_codes; - params->dist.distance_postfix_bits = distance_postfix_bits; - params->dist.alphabet_size = alphabet_size; - params->dist.max_distance = max_distance; + BrotliInitDistanceParams( + params, distance_postfix_bits, num_direct_distance_codes); } static BROTLI_BOOL EnsureInitialized(BrotliEncoderState* s) { @@ -710,8 +712,8 @@ static void BrotliEncoderInitParams(BrotliEncoderParams* params) { params->size_hint = 0; params->disable_literal_context_modeling = BROTLI_FALSE; BrotliInitEncoderDictionary(¶ms->dictionary); - params->dist.num_direct_distance_codes = 0; params->dist.distance_postfix_bits = 0; + params->dist.num_direct_distance_codes = 0; params->dist.alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE(0, 0, BROTLI_MAX_DISTANCE_BITS); params->dist.max_distance = BROTLI_MAX_DISTANCE; @@ -1307,20 +1309,25 @@ static BROTLI_BOOL BrotliCompressBufferQuality10( &storage_ix, storage); } else { MetaBlockSplit mb; - /* The number of distance symbols effectively used by - "Large Window Brotli" (32-bit). */ - uint32_t num_effective_dist_codes = params.dist.alphabet_size; - if (num_effective_dist_codes > BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS) { - num_effective_dist_codes = BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS; - } + BrotliEncoderParams block_params = params; InitMetaBlockSplit(&mb); - BrotliBuildMetaBlock(m, input_buffer, metablock_start, mask, ¶ms, + BrotliBuildMetaBlock(m, input_buffer, metablock_start, mask, + &block_params, prev_byte, prev_byte2, commands, num_commands, literal_context_mode, &mb); if (BROTLI_IS_OOM(m)) goto oom; - BrotliOptimizeHistograms(num_effective_dist_codes, &mb); + { + /* The number of distance symbols effectively used for distance + histograms. It might be less than distance alphabet size + for "Large Window Brotli" (32-bit). */ + uint32_t num_effective_dist_codes = block_params.dist.alphabet_size; + if (num_effective_dist_codes > BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS) { + num_effective_dist_codes = BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS; + } + BrotliOptimizeHistograms(num_effective_dist_codes, &mb); + } storage = BROTLI_ALLOC(m, uint8_t, 2 * metablock_size + 503); if (BROTLI_IS_OOM(m)) goto oom; storage[0] = (uint8_t)last_bytes; @@ -1328,7 +1335,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10( BrotliStoreMetaBlock(m, input_buffer, metablock_start, metablock_size, mask, prev_byte, prev_byte2, is_last, - ¶ms, + &block_params, literal_context_mode, commands, num_commands, &mb, diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/memory.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/memory.h index 2d56e97961a..ab928d019be 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/memory.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/memory.h @@ -80,6 +80,21 @@ R: requested size } \ } +/* +Appends value and dynamically grows array capacity when needed +M: MemoryManager +T: data type +A: array +C: array capacity +S: array size +V: value to append +*/ +#define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \ + (S)++; \ + BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \ + A[(S) - 1] = (V); \ +} + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.c index 621929291f4..641f95e5def 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.c +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.c @@ -25,14 +25,116 @@ extern "C" { #endif +void BrotliInitDistanceParams(BrotliEncoderParams* params, + uint32_t npostfix, uint32_t ndirect) { + BrotliDistanceParams* dist_params = ¶ms->dist; + uint32_t alphabet_size, max_distance; + + dist_params->distance_postfix_bits = npostfix; + dist_params->num_direct_distance_codes = ndirect; + + alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE( + npostfix, ndirect, BROTLI_MAX_DISTANCE_BITS); + max_distance = ndirect + (1U << (BROTLI_MAX_DISTANCE_BITS + npostfix + 2)) - + (1U << (npostfix + 2)); + + if (params->large_window) { + static const uint32_t bound[BROTLI_MAX_NPOSTFIX + 1] = {0, 4, 12, 28}; + uint32_t postfix = 1U << npostfix; + alphabet_size = BROTLI_DISTANCE_ALPHABET_SIZE( + npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITS); + /* The maximum distance is set so that no distance symbol used can encode + a distance larger than BROTLI_MAX_ALLOWED_DISTANCE with all + its extra bits set. */ + if (ndirect < bound[npostfix]) { + max_distance = BROTLI_MAX_ALLOWED_DISTANCE - (bound[npostfix] - ndirect); + } else if (ndirect >= bound[npostfix] + postfix) { + max_distance = (3U << 29) - 4 + (ndirect - bound[npostfix]); + } else { + max_distance = BROTLI_MAX_ALLOWED_DISTANCE; + } + } + + dist_params->alphabet_size = alphabet_size; + dist_params->max_distance = max_distance; +} + +static void RecomputeDistancePrefixes(Command* cmds, + size_t num_commands, + const BrotliDistanceParams* orig_params, + const BrotliDistanceParams* new_params) { + size_t i; + + if (orig_params->distance_postfix_bits == new_params->distance_postfix_bits && + orig_params->num_direct_distance_codes == + new_params->num_direct_distance_codes) { + return; + } + + for (i = 0; i < num_commands; ++i) { + Command* cmd = &cmds[i]; + if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) { + PrefixEncodeCopyDistance(CommandRestoreDistanceCode(cmd, orig_params), + new_params->num_direct_distance_codes, + new_params->distance_postfix_bits, + &cmd->dist_prefix_, + &cmd->dist_extra_); + } + } +} + +static BROTLI_BOOL ComputeDistanceCost(const Command* cmds, + size_t num_commands, + const BrotliDistanceParams* orig_params, + const BrotliDistanceParams* new_params, + double* cost) { + size_t i; + BROTLI_BOOL equal_params = BROTLI_FALSE; + uint16_t dist_prefix; + uint32_t dist_extra; + double extra_bits = 0.0; + HistogramDistance histo; + HistogramClearDistance(&histo); + + if (orig_params->distance_postfix_bits == new_params->distance_postfix_bits && + orig_params->num_direct_distance_codes == + new_params->num_direct_distance_codes) { + equal_params = BROTLI_TRUE; + } + + for (i = 0; i < num_commands; i++) { + const Command* cmd = &cmds[i]; + if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) { + if (equal_params) { + dist_prefix = cmd->dist_prefix_; + } else { + uint32_t distance = CommandRestoreDistanceCode(cmd, orig_params); + if (distance > new_params->max_distance) { + return BROTLI_FALSE; + } + PrefixEncodeCopyDistance(distance, + new_params->num_direct_distance_codes, + new_params->distance_postfix_bits, + &dist_prefix, + &dist_extra); + } + HistogramAddDistance(&histo, dist_prefix & 0x3FF); + extra_bits += dist_prefix >> 10; + } + } + + *cost = BrotliPopulationCostDistance(&histo) + extra_bits; + return BROTLI_TRUE; +} + void BrotliBuildMetaBlock(MemoryManager* m, const uint8_t* ringbuffer, const size_t pos, const size_t mask, - const BrotliEncoderParams* params, + BrotliEncoderParams* params, uint8_t prev_byte, uint8_t prev_byte2, - const Command* cmds, + Command* cmds, size_t num_commands, ContextType literal_context_mode, MetaBlockSplit* mb) { @@ -45,6 +147,46 @@ void BrotliBuildMetaBlock(MemoryManager* m, size_t distance_histograms_size; size_t i; size_t literal_context_multiplier = 1; + uint32_t npostfix; + uint32_t ndirect_msb = 0; + BROTLI_BOOL check_orig = BROTLI_TRUE; + double best_dist_cost = 1e99; + BrotliEncoderParams orig_params = *params; + BrotliEncoderParams new_params = *params; + + for (npostfix = 0; npostfix <= BROTLI_MAX_NPOSTFIX; npostfix++) { + for (; ndirect_msb < 16; ndirect_msb++) { + uint32_t ndirect = ndirect_msb << npostfix; + BROTLI_BOOL skip; + double dist_cost; + BrotliInitDistanceParams(&new_params, npostfix, ndirect); + if (npostfix == orig_params.dist.distance_postfix_bits && + ndirect == orig_params.dist.num_direct_distance_codes) { + check_orig = BROTLI_FALSE; + } + skip = !ComputeDistanceCost( + cmds, num_commands, + &orig_params.dist, &new_params.dist, &dist_cost); + if (skip || (dist_cost > best_dist_cost)) { + break; + } + best_dist_cost = dist_cost; + params->dist = new_params.dist; + } + if (ndirect_msb > 0) ndirect_msb--; + ndirect_msb /= 2; + } + if (check_orig) { + double dist_cost; + ComputeDistanceCost(cmds, num_commands, + &orig_params.dist, &orig_params.dist, &dist_cost); + if (dist_cost < best_dist_cost) { + best_dist_cost = dist_cost; + params->dist = orig_params.dist; + } + } + RecomputeDistancePrefixes(cmds, num_commands, + &orig_params.dist, ¶ms->dist); BrotliSplitBlock(m, cmds, num_commands, ringbuffer, pos, mask, params, diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.h index 76a65940a92..334a79a443c 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/metablock.h @@ -67,15 +67,18 @@ static BROTLI_INLINE void DestroyMetaBlockSplit( BROTLI_FREE(m, mb->distance_histograms); } -/* Uses the slow shortest-path block splitter and does context clustering. */ +/* Uses the slow shortest-path block splitter and does context clustering. + The distance parameters are dynamically selected based on the commands + which get recomputed under the new distance parameters. The new distance + parameters are stored into *params. */ BROTLI_INTERNAL void BrotliBuildMetaBlock(MemoryManager* m, const uint8_t* ringbuffer, const size_t pos, const size_t mask, - const BrotliEncoderParams* params, + BrotliEncoderParams* params, uint8_t prev_byte, uint8_t prev_byte2, - const Command* cmds, + Command* cmds, size_t num_commands, ContextType literal_context_mode, MetaBlockSplit* mb); @@ -92,6 +95,9 @@ BROTLI_INTERNAL void BrotliBuildMetaBlockGreedy( BROTLI_INTERNAL void BrotliOptimizeHistograms(uint32_t num_distance_codes, MetaBlockSplit* mb); +BROTLI_INTERNAL void BrotliInitDistanceParams(BrotliEncoderParams* params, + uint32_t npostfix, uint32_t ndirect); + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/params.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/params.h index 9bcf2361219..6ecf1d3f995 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/params.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/params.h @@ -21,8 +21,8 @@ typedef struct BrotliHasherParams { } BrotliHasherParams; typedef struct BrotliDistanceParams { - uint32_t num_direct_distance_codes; uint32_t distance_postfix_bits; + uint32_t num_direct_distance_codes; uint32_t alphabet_size; size_t max_distance; } BrotliDistanceParams; diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/port.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/port.h deleted file mode 100644 index c3befdf17f5..00000000000 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/port.h +++ /dev/null @@ -1,192 +0,0 @@ -/* Copyright 2013 Google Inc. All Rights Reserved. - - Distributed under MIT license. - See file LICENSE for detail or copy at https://opensource.org/licenses/MIT -*/ - -/* Macros for endianness, branch prediction and unaligned loads and stores. */ - -#ifndef BROTLI_ENC_PORT_H_ -#define BROTLI_ENC_PORT_H_ - -#include <assert.h> -#include <string.h> /* memcpy */ - -#include <brotli/port.h> -#include <brotli/types.h> - -#if defined OS_LINUX || defined OS_CYGWIN -#include <endian.h> -#elif defined OS_FREEBSD -#include <machine/endian.h> -#elif defined OS_MACOSX -#include <machine/endian.h> -/* Let's try and follow the Linux convention */ -#define __BYTE_ORDER BYTE_ORDER -#define __LITTLE_ENDIAN LITTLE_ENDIAN -#endif - -/* define the macro BROTLI_LITTLE_ENDIAN - using the above endian definitions from endian.h if - endian.h was included */ -#ifdef __BYTE_ORDER -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define BROTLI_LITTLE_ENDIAN -#endif - -#else - -#if defined(__LITTLE_ENDIAN__) -#define BROTLI_LITTLE_ENDIAN -#endif -#endif /* __BYTE_ORDER */ - -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -#define BROTLI_LITTLE_ENDIAN -#endif - -/* Enable little-endian optimization for x64 architecture on Windows. */ -#if (defined(_WIN32) || defined(_WIN64)) && defined(_M_X64) -#define BROTLI_LITTLE_ENDIAN -#endif - -/* Portable handling of unaligned loads, stores, and copies. - On some platforms, like ARM, the copy functions can be more efficient - then a load and a store. */ - -#if defined(BROTLI_LITTLE_ENDIAN) && (\ - defined(ARCH_PIII) || defined(ARCH_ATHLON) || \ - defined(ARCH_K8) || defined(_ARCH_PPC)) - -/* x86 and x86-64 can perform unaligned loads/stores directly; - modern PowerPC hardware can also do unaligned integer loads and stores; - but note: the FPU still sends unaligned loads and stores to a trap handler! -*/ - -#define BROTLI_UNALIGNED_LOAD32(_p) (*(const uint32_t *)(_p)) -#define BROTLI_UNALIGNED_LOAD64LE(_p) (*(const uint64_t *)(_p)) - -#define BROTLI_UNALIGNED_STORE64LE(_p, _val) \ - (*(uint64_t *)(_p) = (_val)) - -#elif defined(BROTLI_LITTLE_ENDIAN) && defined(__arm__) && \ - !defined(__ARM_ARCH_5__) && \ - !defined(__ARM_ARCH_5T__) && \ - !defined(__ARM_ARCH_5TE__) && \ - !defined(__ARM_ARCH_5TEJ__) && \ - !defined(__ARM_ARCH_6__) && \ - !defined(__ARM_ARCH_6J__) && \ - !defined(__ARM_ARCH_6K__) && \ - !defined(__ARM_ARCH_6Z__) && \ - !defined(__ARM_ARCH_6ZK__) && \ - !defined(__ARM_ARCH_6T2__) - -/* ARMv7 and newer support native unaligned accesses, but only of 16-bit - and 32-bit values (not 64-bit); older versions either raise a fatal signal, - do an unaligned read and rotate the words around a bit, or do the reads very - slowly (trip through kernel mode). */ - -#define BROTLI_UNALIGNED_LOAD32(_p) (*(const uint32_t *)(_p)) - -static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) { - uint64_t t; - memcpy(&t, p, sizeof t); - return t; -} - -static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) { - memcpy(p, &v, sizeof v); -} - -#else - -/* These functions are provided for architectures that don't support */ -/* unaligned loads and stores. */ - -static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32(const void *p) { - uint32_t t; - memcpy(&t, p, sizeof t); - return t; -} - -#if defined(BROTLI_LITTLE_ENDIAN) - -static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) { - uint64_t t; - memcpy(&t, p, sizeof t); - return t; -} - -static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) { - memcpy(p, &v, sizeof v); -} - -#else /* BROTLI_LITTLE_ENDIAN */ - -static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) { - const uint8_t* in = (const uint8_t*)p; - uint64_t value = (uint64_t)(in[0]); - value |= (uint64_t)(in[1]) << 8; - value |= (uint64_t)(in[2]) << 16; - value |= (uint64_t)(in[3]) << 24; - value |= (uint64_t)(in[4]) << 32; - value |= (uint64_t)(in[5]) << 40; - value |= (uint64_t)(in[6]) << 48; - value |= (uint64_t)(in[7]) << 56; - return value; -} - -static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) { - uint8_t* out = (uint8_t*)p; - out[0] = (uint8_t)v; - out[1] = (uint8_t)(v >> 8); - out[2] = (uint8_t)(v >> 16); - out[3] = (uint8_t)(v >> 24); - out[4] = (uint8_t)(v >> 32); - out[5] = (uint8_t)(v >> 40); - out[6] = (uint8_t)(v >> 48); - out[7] = (uint8_t)(v >> 56); -} - -#endif /* BROTLI_LITTLE_ENDIAN */ - -#endif - -#define TEMPLATE_(T) \ - static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \ - static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; } -TEMPLATE_(double) TEMPLATE_(float) TEMPLATE_(int) -TEMPLATE_(size_t) TEMPLATE_(uint32_t) TEMPLATE_(uint8_t) -#undef TEMPLATE_ -#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B))) -#define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B))) - -#define BROTLI_SWAP(T, A, I, J) { \ - T __brotli_swap_tmp = (A)[(I)]; \ - (A)[(I)] = (A)[(J)]; \ - (A)[(J)] = __brotli_swap_tmp; \ -} - -/* -Dynamically grows array capacity to at least the requested size -M: MemoryManager -T: data type -A: array -C: capacity -R: requested size -*/ -#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \ - if (C < (R)) { \ - size_t _new_size = (C == 0) ? (R) : C; \ - T* new_array; \ - while (_new_size < (R)) _new_size *= 2; \ - new_array = BROTLI_ALLOC((M), T, _new_size); \ - if (!BROTLI_IS_OOM(M) && C != 0) \ - memcpy(new_array, A, C * sizeof(T)); \ - BROTLI_FREE((M), A); \ - A = new_array; \ - C = _new_size; \ - } \ -} - -#endif /* BROTLI_ENC_PORT_H_ */ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/quality.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/quality.h index f9b11117381..aa7ba0d82c8 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/quality.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/quality.h @@ -21,13 +21,12 @@ #define MAX_QUALITY_FOR_STATIC_ENTROPY_CODES 2 #define MIN_QUALITY_FOR_BLOCK_SPLIT 4 +#define MIN_QUALITY_FOR_NONZERO_DISTANCE_PARAMS 4 #define MIN_QUALITY_FOR_OPTIMIZE_HISTOGRAMS 4 #define MIN_QUALITY_FOR_EXTENSIVE_REFERENCE_SEARCH 5 #define MIN_QUALITY_FOR_CONTEXT_MODELING 5 #define MIN_QUALITY_FOR_HQ_CONTEXT_MODELING 7 #define MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING 10 -/* Only for "font" mode. */ -#define MIN_QUALITY_FOR_RECOMPUTE_DISTANCE_PREFIXES 10 /* For quality below MIN_QUALITY_FOR_BLOCK_SPLIT there is no block splitting, so we buffer at most this much literals and commands. */ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/write_bits.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/write_bits.h index 7733d925b1c..ddfebeb7eb8 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/write_bits.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/write_bits.h @@ -44,7 +44,7 @@ static BROTLI_INLINE void BrotliWriteBits(size_t n_bits, bits are in *p and we write 57 bits, then the next write will access a byte that was never initialized). */ uint8_t* p = &array[*pos >> 3]; - uint64_t v = *p; + uint64_t v = (uint64_t)(*p); /* Zero-extend 8 to 64 bits. */ BROTLI_LOG(("WriteBits %2d 0x%08x%08x %10d\n", (int)n_bits, (uint32_t)(bits >> 32), (uint32_t)(bits & 0xFFFFFFFF), (int)*pos)); diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/decode.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/decode.h index 61a4326c1ac..0f5c8f9d111 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/decode.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/decode.h @@ -85,9 +85,8 @@ typedef enum { BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \ \ - /* -17 code is reserved */ \ + /* -17..-18 codes are reserved */ \ \ - BROTLI_ERROR_CODE(_ERROR_, COMPOUND_DICTIONARY, -18) SEPARATOR \ BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \ BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \ \ diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/encode.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/encode.h index 0b5c8c7d2f5..0ced7e55be7 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/encode.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/include/brotli/encode.h @@ -185,7 +185,23 @@ typedef enum BrotliEncoderParameter { /** * Flag that determines if "Large Window Brotli" is used. */ - BROTLI_PARAM_LARGE_WINDOW = 6 + BROTLI_PARAM_LARGE_WINDOW = 6, + /** + * Recommended number of postfix bits (NPOSTFIX). + * + * Encoder may change this value. + * + * Range is from 0 to ::BROTLI_MAX_NPOSTFIX. + */ + BROTLI_PARAM_NPOSTFIX = 7, + /** + * Recommended number of direct distance codes (NDIRECT). + * + * Encoder may change this value. + * + * Range is from 0 to (15 << NPOSTFIX) in steps of (1 << NPOSTFIX). + */ + BROTLI_PARAM_NDIRECT = 8 } BrotliEncoderParameter; /** diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.c index 63a11711c8a..da06ea72bff 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.c +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.c @@ -54,7 +54,7 @@ || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) # define XXH_FORCE_MEMORY_ACCESS 2 -# elif defined(__INTEL_COMPILER) || \ +# elif (defined(__INTEL_COMPILER) && !defined(_WIN32)) || \ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ || defined(__ARM_ARCH_7S__) )) @@ -111,6 +111,8 @@ static void XXH_free (void* p) { free(p); } #include <string.h> static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); } +#include <assert.h> /* assert */ + #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" @@ -215,8 +217,12 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; /* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example on the compiler command line */ #ifndef XXH_CPU_LITTLE_ENDIAN - static const int g_one = 1; -# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&g_one)) +static int XXH_isLittleEndian(void) +{ + const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ + return one.c[0]; +} +# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian() #endif @@ -252,7 +258,7 @@ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; } /* ******************************************************************* -* 32-bits hash functions +* 32-bit hash functions *********************************************************************/ static const U32 PRIME32_1 = 2654435761U; static const U32 PRIME32_2 = 2246822519U; @@ -268,12 +274,87 @@ static U32 XXH32_round(U32 seed, U32 input) return seed; } -FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align) +/* mix all bits */ +static U32 XXH32_avalanche(U32 h32) +{ + h32 ^= h32 >> 15; + h32 *= PRIME32_2; + h32 ^= h32 >> 13; + h32 *= PRIME32_3; + h32 ^= h32 >> 16; + return(h32); +} + +#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align) + +static U32 +XXH32_finalize(U32 h32, const void* ptr, size_t len, + XXH_endianess endian, XXH_alignment align) + +{ + const BYTE* p = (const BYTE*)ptr; +#define PROCESS1 \ + h32 += (*p) * PRIME32_5; \ + p++; \ + h32 = XXH_rotl32(h32, 11) * PRIME32_1 ; + +#define PROCESS4 \ + h32 += XXH_get32bits(p) * PRIME32_3; \ + p+=4; \ + h32 = XXH_rotl32(h32, 17) * PRIME32_4 ; + + switch(len&15) /* or switch(bEnd - p) */ + { + case 12: PROCESS4; + /* fallthrough */ + case 8: PROCESS4; + /* fallthrough */ + case 4: PROCESS4; + return XXH32_avalanche(h32); + + case 13: PROCESS4; + /* fallthrough */ + case 9: PROCESS4; + /* fallthrough */ + case 5: PROCESS4; + PROCESS1; + return XXH32_avalanche(h32); + + case 14: PROCESS4; + /* fallthrough */ + case 10: PROCESS4; + /* fallthrough */ + case 6: PROCESS4; + PROCESS1; + PROCESS1; + return XXH32_avalanche(h32); + + case 15: PROCESS4; + /* fallthrough */ + case 11: PROCESS4; + /* fallthrough */ + case 7: PROCESS4; + /* fallthrough */ + case 3: PROCESS1; + /* fallthrough */ + case 2: PROCESS1; + /* fallthrough */ + case 1: PROCESS1; + /* fallthrough */ + case 0: return XXH32_avalanche(h32); + } + assert(0); + return h32; /* reaching this point is deemed impossible */ +} + + +FORCE_INLINE U32 +XXH32_endian_align(const void* input, size_t len, U32 seed, + XXH_endianess endian, XXH_alignment align) { const BYTE* p = (const BYTE*)input; const BYTE* bEnd = p + len; U32 h32; -#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align) #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) if (p==NULL) { @@ -283,7 +364,7 @@ FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH #endif if (len>=16) { - const BYTE* const limit = bEnd - 16; + const BYTE* const limit = bEnd - 15; U32 v1 = seed + PRIME32_1 + PRIME32_2; U32 v2 = seed + PRIME32_2; U32 v3 = seed + 0; @@ -294,34 +375,17 @@ FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4; v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4; v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4; - } while (p<=limit); + } while (p < limit); - h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); + h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); } else { h32 = seed + PRIME32_5; } - h32 += (U32) len; + h32 += (U32)len; - while (p+4<=bEnd) { - h32 += XXH_get32bits(p) * PRIME32_3; - h32 = XXH_rotl32(h32, 17) * PRIME32_4 ; - p+=4; - } - - while (p<bEnd) { - h32 += (*p) * PRIME32_5; - h32 = XXH_rotl32(h32, 11) * PRIME32_1 ; - p++; - } - - h32 ^= h32 >> 15; - h32 *= PRIME32_2; - h32 ^= h32 >> 13; - h32 *= PRIME32_3; - h32 ^= h32 >> 16; - - return h32; + return XXH32_finalize(h32, p, len&15, endian, align); } @@ -446,6 +510,7 @@ XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size return XXH_OK; } + XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len) { XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; @@ -457,11 +522,9 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* } - -FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian) +FORCE_INLINE U32 +XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian) { - const BYTE * p = (const BYTE*)state->mem32; - const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize; U32 h32; if (state->large_len) { @@ -475,25 +538,7 @@ FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess h32 += state->total_len_32; - while (p+4<=bEnd) { - h32 += XXH_readLE32(p, endian) * PRIME32_3; - h32 = XXH_rotl32(h32, 17) * PRIME32_4; - p+=4; - } - - while (p<bEnd) { - h32 += (*p) * PRIME32_5; - h32 = XXH_rotl32(h32, 11) * PRIME32_1; - p++; - } - - h32 ^= h32 >> 15; - h32 *= PRIME32_2; - h32 ^= h32 >> 13; - h32 *= PRIME32_3; - h32 ^= h32 >> 16; - - return h32; + return XXH32_finalize(h32, state->mem32, state->memsize, endian, XXH_aligned); } @@ -532,7 +577,7 @@ XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src #ifndef XXH_NO_LONG_LONG /* ******************************************************************* -* 64-bits hash functions +* 64-bit hash functions *********************************************************************/ /*====== Memory access ======*/ @@ -639,12 +684,136 @@ static U64 XXH64_mergeRound(U64 acc, U64 val) return acc; } -FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align) +static U64 XXH64_avalanche(U64 h64) +{ + h64 ^= h64 >> 33; + h64 *= PRIME64_2; + h64 ^= h64 >> 29; + h64 *= PRIME64_3; + h64 ^= h64 >> 32; + return h64; +} + + +#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align) + +static U64 +XXH64_finalize(U64 h64, const void* ptr, size_t len, + XXH_endianess endian, XXH_alignment align) +{ + const BYTE* p = (const BYTE*)ptr; + +#define PROCESS1_64 \ + h64 ^= (*p) * PRIME64_5; \ + p++; \ + h64 = XXH_rotl64(h64, 11) * PRIME64_1; + +#define PROCESS4_64 \ + h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; \ + p+=4; \ + h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; + +#define PROCESS8_64 { \ + U64 const k1 = XXH64_round(0, XXH_get64bits(p)); \ + p+=8; \ + h64 ^= k1; \ + h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \ +} + + switch(len&31) { + case 24: PROCESS8_64; + /* fallthrough */ + case 16: PROCESS8_64; + /* fallthrough */ + case 8: PROCESS8_64; + return XXH64_avalanche(h64); + + case 28: PROCESS8_64; + /* fallthrough */ + case 20: PROCESS8_64; + /* fallthrough */ + case 12: PROCESS8_64; + /* fallthrough */ + case 4: PROCESS4_64; + return XXH64_avalanche(h64); + + case 25: PROCESS8_64; + /* fallthrough */ + case 17: PROCESS8_64; + /* fallthrough */ + case 9: PROCESS8_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 29: PROCESS8_64; + /* fallthrough */ + case 21: PROCESS8_64; + /* fallthrough */ + case 13: PROCESS8_64; + /* fallthrough */ + case 5: PROCESS4_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 26: PROCESS8_64; + /* fallthrough */ + case 18: PROCESS8_64; + /* fallthrough */ + case 10: PROCESS8_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 30: PROCESS8_64; + /* fallthrough */ + case 22: PROCESS8_64; + /* fallthrough */ + case 14: PROCESS8_64; + /* fallthrough */ + case 6: PROCESS4_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 27: PROCESS8_64; + /* fallthrough */ + case 19: PROCESS8_64; + /* fallthrough */ + case 11: PROCESS8_64; + PROCESS1_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 31: PROCESS8_64; + /* fallthrough */ + case 23: PROCESS8_64; + /* fallthrough */ + case 15: PROCESS8_64; + /* fallthrough */ + case 7: PROCESS4_64; + /* fallthrough */ + case 3: PROCESS1_64; + /* fallthrough */ + case 2: PROCESS1_64; + /* fallthrough */ + case 1: PROCESS1_64; + /* fallthrough */ + case 0: return XXH64_avalanche(h64); + } + + /* impossible to reach */ + assert(0); + return 0; /* unreachable, but some compilers complain without it */ +} + +FORCE_INLINE U64 +XXH64_endian_align(const void* input, size_t len, U64 seed, + XXH_endianess endian, XXH_alignment align) { const BYTE* p = (const BYTE*)input; const BYTE* bEnd = p + len; U64 h64; -#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align) #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) if (p==NULL) { @@ -679,32 +848,7 @@ FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH h64 += (U64) len; - while (p+8<=bEnd) { - U64 const k1 = XXH64_round(0, XXH_get64bits(p)); - h64 ^= k1; - h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; - p+=8; - } - - if (p+4<=bEnd) { - h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; - h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; - p+=4; - } - - while (p<bEnd) { - h64 ^= (*p) * PRIME64_5; - h64 = XXH_rotl64(h64, 11) * PRIME64_1; - p++; - } - - h64 ^= h64 >> 33; - h64 *= PRIME64_2; - h64 ^= h64 >> 29; - h64 *= PRIME64_3; - h64 ^= h64 >> 32; - - return h64; + return XXH64_finalize(h64, p, len, endian, align); } @@ -835,8 +979,6 @@ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian) { - const BYTE * p = (const BYTE*)state->mem64; - const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize; U64 h64; if (state->total_len >= 32) { @@ -851,37 +993,12 @@ FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess h64 = XXH64_mergeRound(h64, v3); h64 = XXH64_mergeRound(h64, v4); } else { - h64 = state->v3 + PRIME64_5; + h64 = state->v3 /*seed*/ + PRIME64_5; } h64 += (U64) state->total_len; - while (p+8<=bEnd) { - U64 const k1 = XXH64_round(0, XXH_readLE64(p, endian)); - h64 ^= k1; - h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; - p+=8; - } - - if (p+4<=bEnd) { - h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1; - h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; - p+=4; - } - - while (p<bEnd) { - h64 ^= (*p) * PRIME64_5; - h64 = XXH_rotl64(h64, 11) * PRIME64_1; - p++; - } - - h64 ^= h64 >> 33; - h64 *= PRIME64_2; - h64 ^= h64 >> 29; - h64 *= PRIME64_3; - h64 ^= h64 >> 32; - - return h64; + return XXH64_finalize(h64, state->mem64, (size_t)state->total_len, endian, XXH_aligned); } XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t* state_in) diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.h b/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.h index 13136633843..d6bad943358 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/libs/xxHash/xxhash.h @@ -57,8 +57,8 @@ Q.Score is a measure of quality of the hash function. It depends on successfully passing SMHasher test set. 10 is a perfect score. -A 64-bits version, named XXH64, is available since r35. -It offers much better speed, but for 64-bits applications only. +A 64-bit version, named XXH64, is available since r35. +It offers much better speed, but for 64-bit applications only. Name Speed on 64 bits Speed on 32 bits XXH64 13.8 GB/s 1.9 GB/s XXH32 6.8 GB/s 6.0 GB/s @@ -80,18 +80,19 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; /* **************************** -* API modifier -******************************/ -/** XXH_PRIVATE_API -* This is useful to include xxhash functions in `static` mode -* in order to inline them, and remove their symbol from the public list. -* Methodology : -* #define XXH_PRIVATE_API -* #include "xxhash.h" -* `xxhash.c` is automatically included. -* It's not useful to compile and link it as a separate module. -*/ -#ifdef XXH_PRIVATE_API + * API modifier + ******************************/ +/** XXH_INLINE_ALL (and XXH_PRIVATE_API) + * This is useful to include xxhash functions in `static` mode + * in order to inline them, and remove their symbol from the public list. + * Inlining can offer dramatic performance improvement on small keys. + * Methodology : + * #define XXH_INLINE_ALL + * #include "xxhash.h" + * `xxhash.c` is automatically included. + * It's not useful to compile and link it as a separate module. + */ +#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) # ifndef XXH_STATIC_LINKING_ONLY # define XXH_STATIC_LINKING_ONLY # endif @@ -107,19 +108,19 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; # endif #else # define XXH_PUBLIC_API /* do nothing */ -#endif /* XXH_PRIVATE_API */ - -/*!XXH_NAMESPACE, aka Namespace Emulation : - -If you want to include _and expose_ xxHash functions from within your own library, -but also want to avoid symbol collisions with other libraries which may also include xxHash, - -you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library -with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values). - -Note that no change is required within the calling program as long as it includes `xxhash.h` : -regular symbol name will be automatically translated by this header. -*/ +#endif /* XXH_INLINE_ALL || XXH_PRIVATE_API */ + +/*! XXH_NAMESPACE, aka Namespace Emulation : + * + * If you want to include _and expose_ xxHash functions from within your own library, + * but also want to avoid symbol collisions with other libraries which may also include xxHash, + * + * you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library + * with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values). + * + * Note that no change is required within the calling program as long as it includes `xxhash.h` : + * regular symbol name will be automatically translated by this header. + */ #ifdef XXH_NAMESPACE # define XXH_CAT(A,B) A##B # define XXH_NAME2(A,B) XXH_CAT(A,B) @@ -150,18 +151,18 @@ regular symbol name will be automatically translated by this header. ***************************************/ #define XXH_VERSION_MAJOR 0 #define XXH_VERSION_MINOR 6 -#define XXH_VERSION_RELEASE 4 +#define XXH_VERSION_RELEASE 5 #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) XXH_PUBLIC_API unsigned XXH_versionNumber (void); /*-********************************************************************** -* 32-bits hash +* 32-bit hash ************************************************************************/ typedef unsigned int XXH32_hash_t; /*! XXH32() : - Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". + Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input". The memory between input & input+length must be valid (allocated and read-accessible). "seed" can be used to alter the result predictably. Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s */ @@ -178,26 +179,25 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); /* -These functions generate the xxHash of an input provided in multiple segments. -Note that, for small input, they are slower than single-call functions, due to state management. -For small input, prefer `XXH32()` and `XXH64()` . - -XXH state must first be allocated, using XXH*_createState() . - -Start a new hash by initializing state with a seed, using XXH*_reset(). - -Then, feed the hash state by calling XXH*_update() as many times as necessary. -Obviously, input must be allocated and read accessible. -The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. - -Finally, a hash value can be produced anytime, by using XXH*_digest(). -This function returns the nn-bits hash as an int or long long. - -It's still possible to continue inserting input into the hash state after a digest, -and generate some new hashes later on, by calling again XXH*_digest(). - -When done, free XXH state space if it was allocated dynamically. -*/ + * Streaming functions generate the xxHash of an input provided in multiple segments. + * Note that, for small input, they are slower than single-call functions, due to state management. + * For small inputs, prefer `XXH32()` and `XXH64()`, which are better optimized. + * + * XXH state must first be allocated, using XXH*_createState() . + * + * Start a new hash by initializing state with a seed, using XXH*_reset(). + * + * Then, feed the hash state by calling XXH*_update() as many times as necessary. + * The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. + * + * Finally, a hash value can be produced anytime, by using XXH*_digest(). + * This function returns the nn-bits hash as an int or long long. + * + * It's still possible to continue inserting input into the hash state after a digest, + * and generate some new hashes later on, by calling again XXH*_digest(). + * + * When done, free XXH state space if it was allocated dynamically. + */ /*====== Canonical representation ======*/ @@ -206,22 +206,22 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); /* Default result type for XXH functions are primitive unsigned 32 and 64 bits. -* The canonical representation uses human-readable write convention, aka big-endian (large digits first). -* These functions allow transformation of hash result into and from its canonical format. -* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs. -*/ + * The canonical representation uses human-readable write convention, aka big-endian (large digits first). + * These functions allow transformation of hash result into and from its canonical format. + * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs. + */ #ifndef XXH_NO_LONG_LONG /*-********************************************************************** -* 64-bits hash +* 64-bit hash ************************************************************************/ typedef unsigned long long XXH64_hash_t; /*! XXH64() : - Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". + Calculate the 64-bit hash of sequence of length "len" stored at memory address "input". "seed" can be used to alter the result predictably. - This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark). + This function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark). */ XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); @@ -242,6 +242,7 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src #endif /* XXH_NO_LONG_LONG */ + #ifdef XXH_STATIC_LINKING_ONLY /* ================================================================================================ @@ -251,9 +252,39 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src Never use them in association with dynamic linking ! =================================================================================================== */ -/* These definitions are only meant to make possible - static allocation of XXH state, on stack or in a struct for example. - Never use members directly. */ +/* These definitions are only present to allow + * static allocation of XXH state, on stack or in a struct for example. + * Never **ever** use members directly. */ + +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include <stdint.h> + +struct XXH32_state_s { + uint32_t total_len_32; + uint32_t large_len; + uint32_t v1; + uint32_t v2; + uint32_t v3; + uint32_t v4; + uint32_t mem32[4]; + uint32_t memsize; + uint32_t reserved; /* never read nor write, might be removed in a future version */ +}; /* typedef'd to XXH32_state_t */ + +struct XXH64_state_s { + uint64_t total_len; + uint64_t v1; + uint64_t v2; + uint64_t v3; + uint64_t v4; + uint64_t mem64[4]; + uint32_t memsize; + uint32_t reserved[2]; /* never read nor write, might be removed in a future version */ +}; /* typedef'd to XXH64_state_t */ + +# else struct XXH32_state_s { unsigned total_len_32; @@ -262,25 +293,28 @@ struct XXH32_state_s { unsigned v2; unsigned v3; unsigned v4; - unsigned mem32[4]; /* buffer defined as U32 for alignment */ + unsigned mem32[4]; unsigned memsize; - unsigned reserved; /* never read nor write, will be removed in a future version */ + unsigned reserved; /* never read nor write, might be removed in a future version */ }; /* typedef'd to XXH32_state_t */ -#ifndef XXH_NO_LONG_LONG /* remove 64-bits support */ +# ifndef XXH_NO_LONG_LONG /* remove 64-bit support */ struct XXH64_state_s { unsigned long long total_len; unsigned long long v1; unsigned long long v2; unsigned long long v3; unsigned long long v4; - unsigned long long mem64[4]; /* buffer defined as U64 for alignment */ + unsigned long long mem64[4]; unsigned memsize; - unsigned reserved[2]; /* never read nor write, will be removed in a future version */ + unsigned reserved[2]; /* never read nor write, might be removed in a future version */ }; /* typedef'd to XXH64_state_t */ -#endif +# endif + +# endif + -#ifdef XXH_PRIVATE_API +#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) # include "xxhash.c" /* include xxhash function bodies as `static`, for inlining */ #endif |