| 1 | /* Copyright 2013 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 | /* Function to find backward reference copies. */ |
| 8 | |
| 9 | #include "backward_references_hq.h"cxx . . $ `<file>/c/enc/backward_references_hq.h`/ |
| 10 | |
| 11 | #include "../common/constants.h"cxx . . $ `<file>/c/common/constants.h`/ |
| 12 | #include "../common/context.h"cxx . . $ `<file>/c/common/context.h`/ |
| 13 | #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/ |
| 14 | #include "command.h"cxx . . $ `<file>/c/enc/command.h`/ |
| 15 | #include "compound_dictionary.h"cxx . . $ `<file>/c/enc/compound_dictionary.h`/ |
| 16 | #include "encoder_dict.h"cxx . . $ `<file>/c/enc/encoder_dict.h`/ |
| 17 | #include "fast_log.h"cxx . . $ `<file>/c/enc/fast_log.h`/ |
| 18 | #include "find_match_length.h"cxx . . $ `<file>/c/enc/find_match_length.h`/ |
| 19 | #include "hash.h"cxx . . $ `<file>/c/enc/hash.h`/ |
| 20 | #include "literal_cost.h"cxx . . $ `<file>/c/enc/literal_cost.h`/ |
| 21 | #include "memory.h"cxx . . $ `<file>/c/enc/memory.h`/ |
| 22 | #include "params.h"cxx . . $ `<file>/c/enc/params.h`/ |
| 23 | #include "prefix.h"cxx . . $ `<file>/c/enc/prefix.h`/ |
| 24 | #include "quality.h"cxx . . $ `<file>/c/enc/quality.h`/ |
| 25 | |
| 26 | #if defined(__cplusplus) || defined(c_plusplus) |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
| 30 | /* BrotliCalculateDistanceCodeLimit(BROTLI_MAX_ALLOWED_DISTANCE, 3, 120). */ |
| 31 | #define BROTLI_MAX_EFFECTIVE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/backward_references_hq.c:31:9`! 544 |
| 32 | |
| 33 | static const float kInfinitycxx . . $ kInfinity. = 1.7e38f; /* ~= 2 ^ 127 */ |
| 34 | |
| 35 | static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small") uint32_tcxx . . $ uint32_t# kDistanceCacheIndexcxx . . $ kDistanceCacheIndex.[] = { |
| 36 | 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, |
| 37 | }; |
| 38 | static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small") int kDistanceCacheOffsetcxx . . $ kDistanceCacheOffset.[] = { |
| 39 | 0, 0, 0, 0, -1, 1, -2, 2, -3, 3, -1, 1, -2, 2, -3, 3 |
| 40 | }; |
| 41 | |
| 42 | void BrotliInitZopfliNodescxx . . $ BrotliInitZopfliNodes(8999d8ffe0627287).(ZopfliNodecxx . . $ ZopfliNode#* array, size_tcxx . . $ size_t# length) { |
| 43 | ZopfliNodecxx . . $ ZopfliNode# stub; |
| 44 | size_tcxx . . $ size_t# i; |
| 45 | stub.lengthcxx . . $ ZopfliNode#length. = 1; |
| 46 | stub.distancecxx . . $ ZopfliNode#distance. = 0; |
| 47 | stub.dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. = 0; |
| 48 | stub.ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost. = kInfinitycxx . . $ kInfinity.; |
| 49 | for (i = 0; i < length; ++i) array[i] = stub; |
| 50 | } |
| 51 | |
| 52 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(const ZopfliNodecxx . . $ ZopfliNode#* self) { |
| 53 | return self->lengthcxx . . $ ZopfliNode#length. & 0x1FFFFFF; |
| 54 | } |
| 55 | |
| 56 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# ZopfliNodeLengthCodecxx . . $ ZopfliNodeLengthCode(be45bea1a8e379b1).(const ZopfliNodecxx . . $ ZopfliNode#* self) { |
| 57 | const uint32_tcxx . . $ uint32_t# modifier = self->lengthcxx . . $ ZopfliNode#length. >> 25; |
| 58 | return ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(self) + 9u - modifier; |
| 59 | } |
| 60 | |
| 61 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# ZopfliNodeCopyDistancecxx . . $ ZopfliNodeCopyDistance(be45bea1a8e379b1).(const ZopfliNodecxx . . $ ZopfliNode#* self) { |
| 62 | return self->distancecxx . . $ ZopfliNode#distance.; |
| 63 | } |
| 64 | |
| 65 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# ZopfliNodeDistanceCodecxx . . $ ZopfliNodeDistanceCode(be45bea1a8e379b1).(const ZopfliNodecxx . . $ ZopfliNode#* self) { |
| 66 | const uint32_tcxx . . $ uint32_t# short_code = self->dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. >> 27; |
| 67 | return short_code == 0 ? |
| 68 | ZopfliNodeCopyDistancecxx . . $ ZopfliNodeCopyDistance(be45bea1a8e379b1).(self) + BROTLI_NUM_DISTANCE_SHORT_CODEScxx . . $ `c/common/constants.h:58:9`! - 1 : |
| 69 | short_code - 1; |
| 70 | } |
| 71 | |
| 72 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# ZopfliNodeCommandLengthcxx . . $ ZopfliNodeCommandLength(be45bea1a8e379b1).(const ZopfliNodecxx . . $ ZopfliNode#* self) { |
| 73 | return ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(self) + (self->dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. & 0x7FFFFFF); |
| 74 | } |
| 75 | |
| 76 | /* Temporary data for ZopfliCostModelSetFromCommands. */ |
| 77 | typedef struct ZopfliCostModelArenacxx . . $ ZopfliCostModelArena# { |
| 78 | uint32_tcxx . . $ uint32_t# histogram_literalcxx . . $ ZopfliCostModelArena#histogram_literal.[BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!]; |
| 79 | uint32_tcxx . . $ uint32_t# histogram_cmdcxx . . $ ZopfliCostModelArena#histogram_cmd.[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!]; |
| 80 | uint32_tcxx . . $ uint32_t# histogram_distcxx . . $ ZopfliCostModelArena#histogram_dist.[BROTLI_MAX_EFFECTIVE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/backward_references_hq.c:31:9`!]; |
| 81 | float cost_literalcxx . . $ ZopfliCostModelArena#cost_literal.[BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!]; |
| 82 | } ZopfliCostModelArenacxx . . $ ZopfliCostModelArena#; |
| 83 | |
| 84 | /* Histogram based cost model for zopflification. */ |
| 85 | typedef struct ZopfliCostModelcxx . . $ ZopfliCostModel# { |
| 86 | /* The insert and copy length symbols. */ |
| 87 | float cost_cmd_cxx . . $ ZopfliCostModel#cost_cmd_.[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!]; |
| 88 | float* cost_dist_cxx . . $ ZopfliCostModel#cost_dist_.; |
| 89 | uint32_tcxx . . $ uint32_t# distance_histogram_sizecxx . . $ ZopfliCostModel#distance_histogram_size.; |
| 90 | /* Cumulative costs of literals per position in the stream. */ |
| 91 | float* literal_costs_cxx . . $ ZopfliCostModel#literal_costs_.; |
| 92 | float min_cost_cmd_cxx . . $ ZopfliCostModel#min_cost_cmd_.; |
| 93 | size_tcxx . . $ size_t# num_bytes_cxx . . $ ZopfliCostModel#num_bytes_.; |
| 94 | |
| 95 | /* Temporary data. */ |
| 96 | unioncxx . . $ ZopfliCostModel#$anonymous_type_0# { |
| 97 | size_tcxx . . $ size_t# literal_histogramscxx . . $ ZopfliCostModel#$anonymous_type_0#literal_histograms.[3 * 256]; |
| 98 | ZopfliCostModelArenacxx . . $ ZopfliCostModelArena# arenacxx . . $ ZopfliCostModel#$anonymous_type_0#arena.; |
| 99 | }; |
| 100 | } ZopfliCostModelcxx . . $ ZopfliCostModel#; |
| 101 | |
| 102 | static void InitZopfliCostModelcxx . . $ InitZopfliCostModel(421ebed0d8b0f66d).( |
| 103 | MemoryManagercxx . . $ MemoryManager#* m, ZopfliCostModelcxx . . $ ZopfliCostModel#* self, const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* dist, |
| 104 | size_tcxx . . $ size_t# num_bytes) { |
| 105 | self->num_bytes_cxx . . $ ZopfliCostModel#num_bytes_. = num_bytes; |
| 106 | self->literal_costs_cxx . . $ ZopfliCostModel#literal_costs_. = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, float, num_bytes + 2); |
| 107 | self->cost_dist_cxx . . $ ZopfliCostModel#cost_dist_. = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, float, dist->alphabet_size_limit); |
| 108 | self->distance_histogram_sizecxx . . $ ZopfliCostModel#distance_histogram_size. = dist->alphabet_size_limitcxx . . $ BrotliDistanceParams#alphabet_size_limit.; |
| 109 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 110 | } |
| 111 | |
| 112 | static void CleanupZopfliCostModelcxx . . $ CleanupZopfliCostModel(4e2bd2fde6673136).(MemoryManagercxx . . $ MemoryManager#* m, ZopfliCostModelcxx . . $ ZopfliCostModel#* self) { |
| 113 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, self->literal_costs_); |
| 114 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, self->cost_dist_); |
| 115 | } |
| 116 | |
| 117 | static void SetCostcxx . . $ SetCost(e3781a8bd7b08b3c).(const uint32_tcxx . . $ uint32_t#* histogram, size_tcxx . . $ size_t# histogram_size, |
| 118 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! literal_histogram, float* cost) { |
| 119 | size_tcxx . . $ size_t# sum = 0; |
| 120 | size_tcxx . . $ size_t# missing_symbol_sum; |
| 121 | float log2sum; |
| 122 | float missing_symbol_cost; |
| 123 | size_tcxx . . $ size_t# i; |
| 124 | for (i = 0; i < histogram_size; i++) { |
| 125 | sum += histogram[i]; |
| 126 | } |
| 127 | log2sum = (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(sum); |
| 128 | missing_symbol_sum = sum; |
| 129 | if (!literal_histogram) { |
| 130 | for (i = 0; i < histogram_size; i++) { |
| 131 | if (histogram[i] == 0) missing_symbol_sum++; |
| 132 | } |
| 133 | } |
| 134 | missing_symbol_cost = (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(missing_symbol_sum) + 2; |
| 135 | for (i = 0; i < histogram_size; i++) { |
| 136 | if (histogram[i] == 0) { |
| 137 | cost[i] = missing_symbol_cost; |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | /* Shannon bits for this symbol. */ |
| 142 | cost[i] = log2sum - (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(histogram[i]); |
| 143 | |
| 144 | /* Cannot be coded with less than 1 bit */ |
| 145 | if (cost[i] < 1) cost[i] = 1; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static void ZopfliCostModelSetFromCommandscxx . . $ ZopfliCostModelSetFromCommands(36d046442783dec0).(ZopfliCostModelcxx . . $ ZopfliCostModel#* self, |
| 150 | size_tcxx . . $ size_t# position, |
| 151 | const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 152 | size_tcxx . . $ size_t# ringbuffer_mask, |
| 153 | const Commandcxx . . $ Command#* commands, |
| 154 | size_tcxx . . $ size_t# num_commands, |
| 155 | size_tcxx . . $ size_t# last_insert_len) { |
| 156 | ZopfliCostModelArenacxx . . $ ZopfliCostModelArena#* arena = &self->arenacxx . . $ ZopfliCostModel#$anonymous_type_0#arena.; |
| 157 | size_tcxx . . $ size_t# pos = position - last_insert_len; |
| 158 | float min_cost_cmd = kInfinitycxx . . $ kInfinity.; |
| 159 | size_tcxx . . $ size_t# i; |
| 160 | float* cost_cmd = self->cost_cmd_cxx . . $ ZopfliCostModel#cost_cmd_.; |
| 161 | |
| 162 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(arena->histogram_literalcxx . . $ ZopfliCostModelArena#histogram_literal., 0, sizeof(arena->histogram_literalcxx . . $ ZopfliCostModelArena#histogram_literal.)); |
| 163 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(arena->histogram_cmdcxx . . $ ZopfliCostModelArena#histogram_cmd., 0, sizeof(arena->histogram_cmdcxx . . $ ZopfliCostModelArena#histogram_cmd.)); |
| 164 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(arena->histogram_distcxx . . $ ZopfliCostModelArena#histogram_dist., 0, sizeof(arena->histogram_distcxx . . $ ZopfliCostModelArena#histogram_dist.)); |
| 165 | |
| 166 | for (i = 0; i < num_commands; i++) { |
| 167 | size_tcxx . . $ size_t# inslength = commands[i].insert_len_cxx . . $ Command#insert_len_.; |
| 168 | size_tcxx . . $ size_t# copylength = CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&commands[i]); |
| 169 | size_tcxx . . $ size_t# distcode = commands[i].dist_prefix_cxx . . $ Command#dist_prefix_. & 0x3FF; |
| 170 | size_tcxx . . $ size_t# cmdcode = commands[i].cmd_prefix_cxx . . $ Command#cmd_prefix_.; |
| 171 | size_tcxx . . $ size_t# j; |
| 172 | |
| 173 | arena->histogram_cmdcxx . . $ ZopfliCostModelArena#histogram_cmd.[cmdcode]++; |
| 174 | if (cmdcode >= 128) arena->histogram_distcxx . . $ ZopfliCostModelArena#histogram_dist.[distcode]++; |
| 175 | |
| 176 | for (j = 0; j < inslength; j++) { |
| 177 | arena->histogram_literalcxx . . $ ZopfliCostModelArena#histogram_literal.[ringbuffer[(pos + j) & ringbuffer_mask]]++; |
| 178 | } |
| 179 | |
| 180 | pos += inslength + copylength; |
| 181 | } |
| 182 | |
| 183 | SetCostcxx . . $ SetCost(e3781a8bd7b08b3c).(arena->histogram_literalcxx . . $ ZopfliCostModelArena#histogram_literal., BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!, BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!, |
| 184 | arena->cost_literalcxx . . $ ZopfliCostModelArena#cost_literal.); |
| 185 | SetCostcxx . . $ SetCost(e3781a8bd7b08b3c).(arena->histogram_cmdcxx . . $ ZopfliCostModelArena#histogram_cmd., BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!, |
| 186 | cost_cmd); |
| 187 | SetCostcxx . . $ SetCost(e3781a8bd7b08b3c).(arena->histogram_distcxx . . $ ZopfliCostModelArena#histogram_dist., self->distance_histogram_sizecxx . . $ ZopfliCostModel#distance_histogram_size., BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!, |
| 188 | self->cost_dist_cxx . . $ ZopfliCostModel#cost_dist_.); |
| 189 | |
| 190 | for (i = 0; i < BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!; ++i) { |
| 191 | min_cost_cmd = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(float, min_cost_cmd, cost_cmd[i]); |
| 192 | } |
| 193 | self->min_cost_cmd_cxx . . $ ZopfliCostModel#min_cost_cmd_. = min_cost_cmd; |
| 194 | |
| 195 | { |
| 196 | float* literal_costs = self->literal_costs_cxx . . $ ZopfliCostModel#literal_costs_.; |
| 197 | float literal_carry = 0.0; |
| 198 | size_tcxx . . $ size_t# num_bytes = self->num_bytes_cxx . . $ ZopfliCostModel#num_bytes_.; |
| 199 | literal_costs[0] = 0.0; |
| 200 | for (i = 0; i < num_bytes; ++i) { |
| 201 | literal_carry += |
| 202 | arena->cost_literalcxx . . $ ZopfliCostModelArena#cost_literal.[ringbuffer[(position + i) & ringbuffer_mask]]; |
| 203 | literal_costs[i + 1] = literal_costs[i] + literal_carry; |
| 204 | literal_carry -= literal_costs[i + 1] - literal_costs[i]; |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | static void ZopfliCostModelSetFromLiteralCostscxx . . $ ZopfliCostModelSetFromLiteralCosts(63cddf20daa9ab2d).(ZopfliCostModelcxx . . $ ZopfliCostModel#* self, |
| 210 | size_tcxx . . $ size_t# position, |
| 211 | const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 212 | size_tcxx . . $ size_t# ringbuffer_mask) { |
| 213 | float* literal_costs = self->literal_costs_cxx . . $ ZopfliCostModel#literal_costs_.; |
| 214 | float literal_carry = 0.0; |
| 215 | float* cost_dist = self->cost_dist_cxx . . $ ZopfliCostModel#cost_dist_.; |
| 216 | float* cost_cmd = self->cost_cmd_cxx . . $ ZopfliCostModel#cost_cmd_.; |
| 217 | size_tcxx . . $ size_t# num_bytes = self->num_bytes_cxx . . $ ZopfliCostModel#num_bytes_.; |
| 218 | size_tcxx . . $ size_t# i; |
| 219 | BrotliEstimateBitCostsForLiteralscxx . . $ BrotliEstimateBitCostsForLiterals(13b4dd8cd095fb8).(position, num_bytes, ringbuffer_mask, |
| 220 | ringbuffer, self->literal_histogramscxx . . $ ZopfliCostModel#$anonymous_type_0#literal_histograms., |
| 221 | &literal_costs[1]); |
| 222 | literal_costs[0] = 0.0; |
| 223 | for (i = 0; i < num_bytes; ++i) { |
| 224 | literal_carry += literal_costs[i + 1]; |
| 225 | literal_costs[i + 1] = literal_costs[i] + literal_carry; |
| 226 | literal_carry -= literal_costs[i + 1] - literal_costs[i]; |
| 227 | } |
| 228 | for (i = 0; i < BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!; ++i) { |
| 229 | cost_cmd[i] = (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(11 + (uint32_tcxx . . $ uint32_t#)i); |
| 230 | } |
| 231 | for (i = 0; i < self->distance_histogram_sizecxx . . $ ZopfliCostModel#distance_histogram_size.; ++i) { |
| 232 | cost_dist[i] = (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(20 + (uint32_tcxx . . $ uint32_t#)i); |
| 233 | } |
| 234 | self->min_cost_cmd_cxx . . $ ZopfliCostModel#min_cost_cmd_. = (float)FastLog2cxx . . $ FastLog2(78051de35c49feff).(11); |
| 235 | } |
| 236 | |
| 237 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! float ZopfliCostModelGetCommandCostcxx . . $ ZopfliCostModelGetCommandCost(7f747e157b07713c).( |
| 238 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* self, uint16_tcxx . . $ uint16_t# cmdcode) { |
| 239 | return self->cost_cmd_cxx . . $ ZopfliCostModel#cost_cmd_.[cmdcode]; |
| 240 | } |
| 241 | |
| 242 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! float ZopfliCostModelGetDistanceCostcxx . . $ ZopfliCostModelGetDistanceCost(fb5302b6692ff742).( |
| 243 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* self, size_tcxx . . $ size_t# distcode) { |
| 244 | return self->cost_dist_cxx . . $ ZopfliCostModel#cost_dist_.[distcode]; |
| 245 | } |
| 246 | |
| 247 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! float ZopfliCostModelGetLiteralCostscxx . . $ ZopfliCostModelGetLiteralCosts(73bb9fb9e07bcd5f).( |
| 248 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* self, size_tcxx . . $ size_t# from, size_tcxx . . $ size_t# to) { |
| 249 | return self->literal_costs_cxx . . $ ZopfliCostModel#literal_costs_.[to] - self->literal_costs_cxx . . $ ZopfliCostModel#literal_costs_.[from]; |
| 250 | } |
| 251 | |
| 252 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! float ZopfliCostModelGetMinCostCmdcxx . . $ ZopfliCostModelGetMinCostCmd(d7b6a8fba5b5aa3b).( |
| 253 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* self) { |
| 254 | return self->min_cost_cmd_cxx . . $ ZopfliCostModel#min_cost_cmd_.; |
| 255 | } |
| 256 | |
| 257 | /* REQUIRES: len >= 2, start_pos <= pos */ |
| 258 | /* REQUIRES: cost < kInfinity, nodes[start_pos].cost < kInfinity */ |
| 259 | /* Maintains the "ZopfliNode array invariant". */ |
| 260 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void UpdateZopfliNodecxx . . $ UpdateZopfliNode(e40a5b8ede863c9a).(ZopfliNodecxx . . $ ZopfliNode#* nodes, size_tcxx . . $ size_t# pos, |
| 261 | size_tcxx . . $ size_t# start_pos, size_tcxx . . $ size_t# len, size_tcxx . . $ size_t# len_code, size_tcxx . . $ size_t# dist, |
| 262 | size_tcxx . . $ size_t# short_code, float cost) { |
| 263 | ZopfliNodecxx . . $ ZopfliNode#* next = &nodes[pos + len]; |
| 264 | next->lengthcxx . . $ ZopfliNode#length. = (uint32_tcxx . . $ uint32_t#)(len | ((len + 9u - len_code) << 25)); |
| 265 | next->distancecxx . . $ ZopfliNode#distance. = (uint32_tcxx . . $ uint32_t#)dist; |
| 266 | next->dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. = (uint32_tcxx . . $ uint32_t#)( |
| 267 | (short_code << 27) | (pos - start_pos)); |
| 268 | next->ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost. = cost; |
| 269 | } |
| 270 | |
| 271 | typedef struct PosDatacxx . . $ PosData# { |
| 272 | size_tcxx . . $ size_t# poscxx . . $ PosData#pos.; |
| 273 | int distance_cachecxx . . $ PosData#distance_cache.[4]; |
| 274 | float costdiffcxx . . $ PosData#costdiff.; |
| 275 | float costcxx . . $ PosData#cost.; |
| 276 | } PosDatacxx . . $ PosData#; |
| 277 | |
| 278 | /* Maintains the smallest 8 cost difference together with their positions */ |
| 279 | typedef struct StartPosQueuecxx . . $ StartPosQueue# { |
| 280 | PosDatacxx . . $ PosData# q_cxx . . $ StartPosQueue#q_.[8]; |
| 281 | size_tcxx . . $ size_t# idx_cxx . . $ StartPosQueue#idx_.; |
| 282 | } StartPosQueuecxx . . $ StartPosQueue#; |
| 283 | |
| 284 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void InitStartPosQueuecxx . . $ InitStartPosQueue(b8d6329df9d7a96).(StartPosQueuecxx . . $ StartPosQueue#* self) { |
| 285 | self->idx_cxx . . $ StartPosQueue#idx_. = 0; |
| 286 | } |
| 287 | |
| 288 | static size_tcxx . . $ size_t# StartPosQueueSizecxx . . $ StartPosQueueSize(eee5210362e3aba6).(const StartPosQueuecxx . . $ StartPosQueue#* self) { |
| 289 | return BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, self->idx_, 8); |
| 290 | } |
| 291 | |
| 292 | static void StartPosQueuePushcxx . . $ StartPosQueuePush(33233ede6816ea78).(StartPosQueuecxx . . $ StartPosQueue#* self, const PosDatacxx . . $ PosData#* posdata) { |
| 293 | size_tcxx . . $ size_t# offset = ~(self->idx_cxx . . $ StartPosQueue#idx_.++) & 7; |
| 294 | size_tcxx . . $ size_t# len = StartPosQueueSizecxx . . $ StartPosQueueSize(eee5210362e3aba6).(self); |
| 295 | size_tcxx . . $ size_t# i; |
| 296 | PosDatacxx . . $ PosData#* q = self->q_cxx . . $ StartPosQueue#q_.; |
| 297 | q[offset] = *posdata; |
| 298 | /* Restore the sorted order. In the list of |len| items at most |len - 1| |
| 299 | adjacent element comparisons / swaps are required. */ |
| 300 | for (i = 1; i < len; ++i) { |
| 301 | if (q[offset & 7].costdiffcxx . . $ PosData#costdiff. > q[(offset + 1) & 7].costdiffcxx . . $ PosData#costdiff.) { |
| 302 | BROTLI_SWAPcxx . . $ `c/common/platform.h:525:9`!(PosData, q, offset & 7, (offset + 1) & 7); |
| 303 | } |
| 304 | ++offset; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | static const PosDatacxx . . $ PosData#* StartPosQueueAtcxx . . $ StartPosQueueAt(7cb1ddd2eae2dee2).(const StartPosQueuecxx . . $ StartPosQueue#* self, size_tcxx . . $ size_t# k) { |
| 309 | return &self->q_cxx . . $ StartPosQueue#q_.[(k - self->idx_cxx . . $ StartPosQueue#idx_.) & 7]; |
| 310 | } |
| 311 | |
| 312 | /* Returns the minimum possible copy length that can improve the cost of any */ |
| 313 | /* future position. */ |
| 314 | static size_tcxx . . $ size_t# ComputeMinimumCopyLengthcxx . . $ ComputeMinimumCopyLength(683f578ddeb104c1).(const float start_cost, |
| 315 | const ZopfliNodecxx . . $ ZopfliNode#* nodes, |
| 316 | const size_tcxx . . $ size_t# num_bytes, |
| 317 | const size_tcxx . . $ size_t# pos) { |
| 318 | /* Compute the minimum possible cost of reaching any future position. */ |
| 319 | float min_cost = start_cost; |
| 320 | size_tcxx . . $ size_t# len = 2; |
| 321 | size_tcxx . . $ size_t# next_len_bucket = 4; |
| 322 | size_tcxx . . $ size_t# next_len_offset = 10; |
| 323 | while (pos + len <= num_bytes && nodes[pos + len].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost. <= min_cost) { |
| 324 | /* We already reached (pos + len) with no more cost than the minimum |
| 325 | possible cost of reaching anything from this pos, so there is no point in |
| 326 | looking for lengths <= len. */ |
| 327 | ++len; |
| 328 | if (len == next_len_offset) { |
| 329 | /* We reached the next copy length code bucket, so we add one more |
| 330 | extra bit to the minimum cost. */ |
| 331 | min_cost += 1.0f; |
| 332 | next_len_offset += next_len_bucket; |
| 333 | next_len_bucket *= 2; |
| 334 | } |
| 335 | } |
| 336 | return len; |
| 337 | } |
| 338 | |
| 339 | /* REQUIRES: nodes[pos].cost < kInfinity |
| 340 | REQUIRES: nodes[0..pos] satisfies that "ZopfliNode array invariant". */ |
| 341 | static uint32_tcxx . . $ uint32_t# ComputeDistanceShortcutcxx . . $ ComputeDistanceShortcut(ffff03e8c5a49897).(const size_tcxx . . $ size_t# block_start, |
| 342 | const size_tcxx . . $ size_t# pos, |
| 343 | const size_tcxx . . $ size_t# max_backward_limit, |
| 344 | const size_tcxx . . $ size_t# gap, |
| 345 | const ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 346 | const size_tcxx . . $ size_t# c_len = ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(&nodes[pos]); |
| 347 | const size_tcxx . . $ size_t# i_len = nodes[pos].dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. & 0x7FFFFFF; |
| 348 | const size_tcxx . . $ size_t# dist = ZopfliNodeCopyDistancecxx . . $ ZopfliNodeCopyDistance(be45bea1a8e379b1).(&nodes[pos]); |
| 349 | /* Since |block_start + pos| is the end position of the command, the copy part |
| 350 | starts from |block_start + pos - c_len|. Distances that are greater than |
| 351 | this or greater than |max_backward_limit| + |gap| are static dictionary |
| 352 | references, and do not update the last distances. |
| 353 | Also distance code 0 (last distance) does not update the last distances. */ |
| 354 | if (pos == 0) { |
| 355 | return 0; |
| 356 | } else if (dist + c_len <= block_start + pos + gap && |
| 357 | dist <= max_backward_limit + gap && |
| 358 | ZopfliNodeDistanceCodecxx . . $ ZopfliNodeDistanceCode(be45bea1a8e379b1).(&nodes[pos]) > 0) { |
| 359 | return (uint32_tcxx . . $ uint32_t#)pos; |
| 360 | } else { |
| 361 | return nodes[pos - c_len - i_len].ucxx . . $ ZopfliNode#u..shortcutcxx . . $ ZopfliNode#$anonymous_type_0#shortcut.; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /* Fills in dist_cache[0..3] with the last four distances (as defined by |
| 366 | Section 4. of the Spec) that would be used at (block_start + pos) if we |
| 367 | used the shortest path of commands from block_start, computed from |
| 368 | nodes[0..pos]. The last four distances at block_start are in |
| 369 | starting_dist_cache[0..3]. |
| 370 | REQUIRES: nodes[pos].cost < kInfinity |
| 371 | REQUIRES: nodes[0..pos] satisfies that "ZopfliNode array invariant". */ |
| 372 | static void ComputeDistanceCachecxx . . $ ComputeDistanceCache(8472f81b7b1f1047).(const size_tcxx . . $ size_t# pos, |
| 373 | const int* starting_dist_cache, |
| 374 | const ZopfliNodecxx . . $ ZopfliNode#* nodes, |
| 375 | int* dist_cache) { |
| 376 | int idx = 0; |
| 377 | size_tcxx . . $ size_t# p = nodes[pos].ucxx . . $ ZopfliNode#u..shortcutcxx . . $ ZopfliNode#$anonymous_type_0#shortcut.; |
| 378 | while (idx < 4 && p > 0) { |
| 379 | const size_tcxx . . $ size_t# i_len = nodes[p].dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. & 0x7FFFFFF; |
| 380 | const size_tcxx . . $ size_t# c_len = ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(&nodes[p]); |
| 381 | const size_tcxx . . $ size_t# dist = ZopfliNodeCopyDistancecxx . . $ ZopfliNodeCopyDistance(be45bea1a8e379b1).(&nodes[p]); |
| 382 | dist_cache[idx++] = (int)dist; |
| 383 | /* Because of prerequisite, p >= c_len + i_len >= 2. */ |
| 384 | p = nodes[p - c_len - i_len].ucxx . . $ ZopfliNode#u..shortcutcxx . . $ ZopfliNode#$anonymous_type_0#shortcut.; |
| 385 | } |
| 386 | for (; idx < 4; ++idx) { |
| 387 | dist_cache[idx] = *starting_dist_cache++; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* Maintains "ZopfliNode array invariant" and pushes node to the queue, if it |
| 392 | is eligible. */ |
| 393 | static void EvaluateNodecxx . . $ EvaluateNode(4be0c448d85264e0).( |
| 394 | const size_tcxx . . $ size_t# block_start, const size_tcxx . . $ size_t# pos, const size_tcxx . . $ size_t# max_backward_limit, |
| 395 | const size_tcxx . . $ size_t# gap, const int* starting_dist_cache, |
| 396 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* model, StartPosQueuecxx . . $ StartPosQueue#* queue, ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 397 | /* Save cost, because ComputeDistanceCache invalidates it. */ |
| 398 | float node_cost = nodes[pos].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost.; |
| 399 | nodes[pos].ucxx . . $ ZopfliNode#u..shortcutcxx . . $ ZopfliNode#$anonymous_type_0#shortcut. = ComputeDistanceShortcutcxx . . $ ComputeDistanceShortcut(ffff03e8c5a49897).( |
| 400 | block_start, pos, max_backward_limit, gap, nodes); |
| 401 | if (node_cost <= ZopfliCostModelGetLiteralCostscxx . . $ ZopfliCostModelGetLiteralCosts(73bb9fb9e07bcd5f).(model, 0, pos)) { |
| 402 | PosDatacxx . . $ PosData# posdata; |
| 403 | posdata.poscxx . . $ PosData#pos. = pos; |
| 404 | posdata.costcxx . . $ PosData#cost. = node_cost; |
| 405 | posdata.costdiffcxx . . $ PosData#costdiff. = node_cost - |
| 406 | ZopfliCostModelGetLiteralCostscxx . . $ ZopfliCostModelGetLiteralCosts(73bb9fb9e07bcd5f).(model, 0, pos); |
| 407 | ComputeDistanceCachecxx . . $ ComputeDistanceCache(8472f81b7b1f1047).( |
| 408 | pos, starting_dist_cache, nodes, posdata.distance_cachecxx . . $ PosData#distance_cache.); |
| 409 | StartPosQueuePushcxx . . $ StartPosQueuePush(33233ede6816ea78).(queue, &posdata); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /* Returns longest copy length. */ |
| 414 | static size_tcxx . . $ size_t# UpdateNodescxx . . $ UpdateNodes(dbe1d98d67fa0e3a).( |
| 415 | const size_tcxx . . $ size_t# num_bytes, const size_tcxx . . $ size_t# block_start, const size_tcxx . . $ size_t# pos, |
| 416 | const uint8_tcxx . . $ uint8_t#* ringbuffer, const size_tcxx . . $ size_t# ringbuffer_mask, |
| 417 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, const size_tcxx . . $ size_t# max_backward_limit, |
| 418 | const int* starting_dist_cache, const size_tcxx . . $ size_t# num_matches, |
| 419 | const BackwardMatchcxx . . $ BackwardMatch#* matches, const ZopfliCostModelcxx . . $ ZopfliCostModel#* model, |
| 420 | StartPosQueuecxx . . $ StartPosQueue#* queue, ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 421 | const size_tcxx . . $ size_t# stream_offset = params->stream_offsetcxx . . $ BrotliEncoderParams#stream_offset.; |
| 422 | const size_tcxx . . $ size_t# cur_ix = block_start + pos; |
| 423 | const size_tcxx . . $ size_t# cur_ix_masked = cur_ix & ringbuffer_mask; |
| 424 | const size_tcxx . . $ size_t# max_distance = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, cur_ix, max_backward_limit); |
| 425 | const size_tcxx . . $ size_t# dictionary_start = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, |
| 426 | cur_ix + stream_offset, max_backward_limit); |
| 427 | const size_tcxx . . $ size_t# max_len = num_bytes - pos; |
| 428 | const size_tcxx . . $ size_t# max_zopfli_len = MaxZopfliLencxx . . $ MaxZopfliLen(76b5aa81b68a1b65).(params); |
| 429 | const size_tcxx . . $ size_t# max_iters = MaxZopfliCandidatescxx . . $ MaxZopfliCandidates(76b5aa81b68a1b65).(params); |
| 430 | size_tcxx . . $ size_t# min_len; |
| 431 | size_tcxx . . $ size_t# result = 0; |
| 432 | size_tcxx . . $ size_t# k; |
| 433 | const CompoundDictionarycxx . . $ CompoundDictionary#* addon = ¶ms->dictionarycxx . . $ BrotliEncoderParams#dictionary..compoundcxx . . $ SharedEncoderDictionary#compound.; |
| 434 | size_tcxx . . $ size_t# gap = addon->total_sizecxx . . $ CompoundDictionary#total_size.; |
| 435 | |
| 436 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(cur_ix_masked + max_len <= ringbuffer_mask); |
| 437 | |
| 438 | EvaluateNodecxx . . $ EvaluateNode(4be0c448d85264e0).(block_start + stream_offset, pos, max_backward_limit, gap, |
| 439 | starting_dist_cache, model, queue, nodes); |
| 440 | |
| 441 | { |
| 442 | const PosDatacxx . . $ PosData#* posdata = StartPosQueueAtcxx . . $ StartPosQueueAt(7cb1ddd2eae2dee2).(queue, 0); |
| 443 | float min_cost = (posdata->costcxx . . $ PosData#cost. + ZopfliCostModelGetMinCostCmdcxx . . $ ZopfliCostModelGetMinCostCmd(d7b6a8fba5b5aa3b).(model) + |
| 444 | ZopfliCostModelGetLiteralCostscxx . . $ ZopfliCostModelGetLiteralCosts(73bb9fb9e07bcd5f).(model, posdata->poscxx . . $ PosData#pos., pos)); |
| 445 | min_len = ComputeMinimumCopyLengthcxx . . $ ComputeMinimumCopyLength(683f578ddeb104c1).(min_cost, nodes, num_bytes, pos); |
| 446 | } |
| 447 | |
| 448 | /* Go over the command starting positions in order of increasing cost |
| 449 | difference. */ |
| 450 | for (k = 0; k < max_iters && k < StartPosQueueSizecxx . . $ StartPosQueueSize(eee5210362e3aba6).(queue); ++k) { |
| 451 | const PosDatacxx . . $ PosData#* posdata = StartPosQueueAtcxx . . $ StartPosQueueAt(7cb1ddd2eae2dee2).(queue, k); |
| 452 | const size_tcxx . . $ size_t# start = posdata->poscxx . . $ PosData#pos.; |
| 453 | const uint16_tcxx . . $ uint16_t# inscode = GetInsertLengthCodecxx . . $ GetInsertLengthCode(91f8ed6d6bcecca7).(pos - start); |
| 454 | const float start_costdiff = posdata->costdiffcxx . . $ PosData#costdiff.; |
| 455 | const float base_cost = start_costdiff + (float)GetInsertExtracxx . . $ GetInsertExtra(909d59720f161188).(inscode) + |
| 456 | ZopfliCostModelGetLiteralCostscxx . . $ ZopfliCostModelGetLiteralCosts(73bb9fb9e07bcd5f).(model, 0, pos); |
| 457 | |
| 458 | /* Look for last distance matches using the distance cache from this |
| 459 | starting position. */ |
| 460 | size_tcxx . . $ size_t# best_len = min_len - 1; |
| 461 | size_tcxx . . $ size_t# j = 0; |
| 462 | for (; j < BROTLI_NUM_DISTANCE_SHORT_CODEScxx . . $ `c/common/constants.h:58:9`! && best_len < max_len; ++j) { |
| 463 | const size_tcxx . . $ size_t# idx = kDistanceCacheIndexcxx . . $ kDistanceCacheIndex.[j]; |
| 464 | const size_tcxx . . $ size_t# backward = |
| 465 | (size_tcxx . . $ size_t#)(posdata->distance_cachecxx . . $ PosData#distance_cache.[idx] + kDistanceCacheOffsetcxx . . $ kDistanceCacheOffset.[j]); |
| 466 | size_tcxx . . $ size_t# prev_ix = cur_ix - backward; |
| 467 | size_tcxx . . $ size_t# len = 0; |
| 468 | uint8_tcxx . . $ uint8_t# continuation = ringbuffer[cur_ix_masked + best_len]; |
| 469 | if (cur_ix_masked + best_len > ringbuffer_mask) { |
| 470 | break; |
| 471 | } |
| 472 | if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(backward > dictionary_start + gap)) { |
| 473 | /* Word dictionary -> ignore. */ |
| 474 | continue; |
| 475 | } |
| 476 | if (backward <= max_distance) { |
| 477 | /* Regular backward reference. */ |
| 478 | if (prev_ix >= cur_ix) { |
| 479 | continue; |
| 480 | } |
| 481 | |
| 482 | prev_ix &= ringbuffer_mask; |
| 483 | if (prev_ix + best_len > ringbuffer_mask || |
| 484 | continuation != ringbuffer[prev_ix + best_len]) { |
| 485 | continue; |
| 486 | } |
| 487 | len = FindMatchLengthWithLimitcxx . . $ FindMatchLengthWithLimit(c2ccccc71581acc8).(&ringbuffer[prev_ix], |
| 488 | &ringbuffer[cur_ix_masked], |
| 489 | max_len); |
| 490 | } else if (backward > dictionary_start) { |
| 491 | size_tcxx . . $ size_t# d = 0; |
| 492 | size_tcxx . . $ size_t# offset; |
| 493 | size_tcxx . . $ size_t# limit; |
| 494 | const uint8_tcxx . . $ uint8_t#* source; |
| 495 | offset = dictionary_start + 1 + addon->total_sizecxx . . $ CompoundDictionary#total_size. - 1; |
| 496 | while (offset >= backward + addon->chunk_offsetscxx . . $ CompoundDictionary#chunk_offsets.[d + 1]) d++; |
| 497 | source = addon->chunk_sourcecxx . . $ CompoundDictionary#chunk_source.[d]; |
| 498 | offset = offset - addon->chunk_offsetscxx . . $ CompoundDictionary#chunk_offsets.[d] - backward; |
| 499 | limit = addon->chunk_offsetscxx . . $ CompoundDictionary#chunk_offsets.[d + 1] - addon->chunk_offsetscxx . . $ CompoundDictionary#chunk_offsets.[d] - offset; |
| 500 | limit = limit > max_len ? max_len : limit; |
| 501 | if (best_len >= limit || |
| 502 | continuation != source[offset + best_len]) { |
| 503 | continue; |
| 504 | } |
| 505 | len = FindMatchLengthWithLimitcxx . . $ FindMatchLengthWithLimit(c2ccccc71581acc8).(&source[offset], |
| 506 | &ringbuffer[cur_ix_masked], |
| 507 | limit); |
| 508 | } else { |
| 509 | /* "Gray" area. It is addressable by decoder, but this encoder |
| 510 | instance does not have that data -> should not touch it. */ |
| 511 | continue; |
| 512 | } |
| 513 | { |
| 514 | const float dist_cost = base_cost + |
| 515 | ZopfliCostModelGetDistanceCostcxx . . $ ZopfliCostModelGetDistanceCost(fb5302b6692ff742).(model, j); |
| 516 | size_tcxx . . $ size_t# l; |
| 517 | for (l = best_len + 1; l <= len; ++l) { |
| 518 | const uint16_tcxx . . $ uint16_t# copycode = GetCopyLengthCodecxx . . $ GetCopyLengthCode(91f8ed6d6bcecca7).(l); |
| 519 | const uint16_tcxx . . $ uint16_t# cmdcode = |
| 520 | CombineLengthCodescxx . . $ CombineLengthCodes(e376afdf389bac60).(inscode, copycode, j == 0); |
| 521 | const float cost = (cmdcode < 128 ? base_cost : dist_cost) + |
| 522 | (float)GetCopyExtracxx . . $ GetCopyExtra(909d59720f161188).(copycode) + |
| 523 | ZopfliCostModelGetCommandCostcxx . . $ ZopfliCostModelGetCommandCost(7f747e157b07713c).(model, cmdcode); |
| 524 | if (cost < nodes[pos + l].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost.) { |
| 525 | UpdateZopfliNodecxx . . $ UpdateZopfliNode(e40a5b8ede863c9a).(nodes, pos, start, l, l, backward, j + 1, cost); |
| 526 | result = BROTLI_MAXcxx . . $ `c/common/platform.h:523:9`!(size_t, result, l); |
| 527 | } |
| 528 | best_len = l; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /* At higher iterations look only for new last distance matches, since |
| 534 | looking only for new command start positions with the same distances |
| 535 | does not help much. */ |
| 536 | if (k >= 2) continue; |
| 537 | |
| 538 | { |
| 539 | /* Loop through all possible copy lengths at this position. */ |
| 540 | size_tcxx . . $ size_t# len = min_len; |
| 541 | for (j = 0; j < num_matches; ++j) { |
| 542 | BackwardMatchcxx . . $ BackwardMatch# match = matches[j]; |
| 543 | size_tcxx . . $ size_t# dist = match.distancecxx . . $ BackwardMatch#distance.; |
| 544 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_dictionary_match = |
| 545 | TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(dist > dictionary_start + gap); |
| 546 | /* We already tried all possible last distance matches, so we can use |
| 547 | normal distance code here. */ |
| 548 | size_tcxx . . $ size_t# dist_code = dist + BROTLI_NUM_DISTANCE_SHORT_CODEScxx . . $ `c/common/constants.h:58:9`! - 1; |
| 549 | uint16_tcxx . . $ uint16_t# dist_symbol; |
| 550 | uint32_tcxx . . $ uint32_t# distextra; |
| 551 | uint32_tcxx . . $ uint32_t# distnumextra; |
| 552 | float dist_cost; |
| 553 | size_tcxx . . $ size_t# max_match_len; |
| 554 | PrefixEncodeCopyDistancecxx . . $ PrefixEncodeCopyDistance(ddce29df8a9022a3).( |
| 555 | dist_code, params->distcxx . . $ BrotliEncoderParams#dist..num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes., |
| 556 | params->distcxx . . $ BrotliEncoderParams#dist..distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits., &dist_symbol, &distextra); |
| 557 | distnumextra = dist_symbol >> 10; |
| 558 | dist_cost = base_cost + (float)distnumextra + |
| 559 | ZopfliCostModelGetDistanceCostcxx . . $ ZopfliCostModelGetDistanceCost(fb5302b6692ff742).(model, dist_symbol & 0x3FF); |
| 560 | |
| 561 | /* Try all copy lengths up until the maximum copy length corresponding |
| 562 | to this distance. If the distance refers to the static dictionary, or |
| 563 | the maximum length is long enough, try only one maximum length. */ |
| 564 | max_match_len = BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(&match); |
| 565 | if (len < max_match_len && |
| 566 | (is_dictionary_match || max_match_len > max_zopfli_len)) { |
| 567 | len = max_match_len; |
| 568 | } |
| 569 | for (; len <= max_match_len; ++len) { |
| 570 | const size_tcxx . . $ size_t# len_code = |
| 571 | is_dictionary_match ? BackwardMatchLengthCodecxx . . $ BackwardMatchLengthCode(a1892b62ee829aa2).(&match) : len; |
| 572 | const uint16_tcxx . . $ uint16_t# copycode = GetCopyLengthCodecxx . . $ GetCopyLengthCode(91f8ed6d6bcecca7).(len_code); |
| 573 | const uint16_tcxx . . $ uint16_t# cmdcode = CombineLengthCodescxx . . $ CombineLengthCodes(e376afdf389bac60).(inscode, copycode, 0); |
| 574 | const float cost = dist_cost + (float)GetCopyExtracxx . . $ GetCopyExtra(909d59720f161188).(copycode) + |
| 575 | ZopfliCostModelGetCommandCostcxx . . $ ZopfliCostModelGetCommandCost(7f747e157b07713c).(model, cmdcode); |
| 576 | if (cost < nodes[pos + len].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost.) { |
| 577 | UpdateZopfliNodecxx . . $ UpdateZopfliNode(e40a5b8ede863c9a).(nodes, pos, start, len, len_code, dist, 0, cost); |
| 578 | result = BROTLI_MAXcxx . . $ `c/common/platform.h:523:9`!(size_t, result, len); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | return result; |
| 585 | } |
| 586 | |
| 587 | static size_tcxx . . $ size_t# ComputeShortestPathFromNodescxx . . $ ComputeShortestPathFromNodes(e66215a3f70bb1c4).(size_tcxx . . $ size_t# num_bytes, |
| 588 | ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 589 | size_tcxx . . $ size_t# index = num_bytes; |
| 590 | size_tcxx . . $ size_t# num_commands = 0; |
| 591 | while ((nodes[index].dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. & 0x7FFFFFF) == 0 && |
| 592 | nodes[index].lengthcxx . . $ ZopfliNode#length. == 1) --index; |
| 593 | nodes[index].ucxx . . $ ZopfliNode#u..nextcxx . . $ ZopfliNode#$anonymous_type_0#next. = BROTLI_UINT32_MAXcxx . . $ `c/include/brotli/types.h:59:9`!; |
| 594 | while (index != 0) { |
| 595 | size_tcxx . . $ size_t# len = ZopfliNodeCommandLengthcxx . . $ ZopfliNodeCommandLength(be45bea1a8e379b1).(&nodes[index]); |
| 596 | index -= len; |
| 597 | nodes[index].ucxx . . $ ZopfliNode#u..nextcxx . . $ ZopfliNode#$anonymous_type_0#next. = (uint32_tcxx . . $ uint32_t#)len; |
| 598 | num_commands++; |
| 599 | } |
| 600 | return num_commands; |
| 601 | } |
| 602 | |
| 603 | /* REQUIRES: nodes != NULL and len(nodes) >= num_bytes + 1 */ |
| 604 | void BrotliZopfliCreateCommandscxx . . $ BrotliZopfliCreateCommands(426b03b768448b1b).(const size_tcxx . . $ size_t# num_bytes, |
| 605 | const size_tcxx . . $ size_t# block_start, const ZopfliNodecxx . . $ ZopfliNode#* nodes, int* dist_cache, |
| 606 | size_tcxx . . $ size_t#* last_insert_len, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, |
| 607 | Commandcxx . . $ Command#* commands, size_tcxx . . $ size_t#* num_literals) { |
| 608 | const size_tcxx . . $ size_t# stream_offset = params->stream_offsetcxx . . $ BrotliEncoderParams#stream_offset.; |
| 609 | const size_tcxx . . $ size_t# max_backward_limit = BROTLI_MAX_BACKWARD_LIMITcxx . . $ `c/common/constants.h:101:9`!(params->lgwin); |
| 610 | size_tcxx . . $ size_t# pos = 0; |
| 611 | uint32_tcxx . . $ uint32_t# offset = nodes[0].ucxx . . $ ZopfliNode#u..nextcxx . . $ ZopfliNode#$anonymous_type_0#next.; |
| 612 | size_tcxx . . $ size_t# i; |
| 613 | size_tcxx . . $ size_t# gap = params->dictionarycxx . . $ BrotliEncoderParams#dictionary..compoundcxx . . $ SharedEncoderDictionary#compound..total_sizecxx . . $ CompoundDictionary#total_size.; |
| 614 | for (i = 0; offset != BROTLI_UINT32_MAXcxx . . $ `c/include/brotli/types.h:59:9`!; i++) { |
| 615 | const ZopfliNodecxx . . $ ZopfliNode#* next = &nodes[pos + offset]; |
| 616 | size_tcxx . . $ size_t# copy_length = ZopfliNodeCopyLengthcxx . . $ ZopfliNodeCopyLength(be45bea1a8e379b1).(next); |
| 617 | size_tcxx . . $ size_t# insert_length = next->dcode_insert_lengthcxx . . $ ZopfliNode#dcode_insert_length. & 0x7FFFFFF; |
| 618 | pos += insert_length; |
| 619 | offset = next->ucxx . . $ ZopfliNode#u..nextcxx . . $ ZopfliNode#$anonymous_type_0#next.; |
| 620 | if (i == 0) { |
| 621 | insert_length += *last_insert_len; |
| 622 | *last_insert_len = 0; |
| 623 | } |
| 624 | { |
| 625 | size_tcxx . . $ size_t# distance = ZopfliNodeCopyDistancecxx . . $ ZopfliNodeCopyDistance(be45bea1a8e379b1).(next); |
| 626 | size_tcxx . . $ size_t# len_code = ZopfliNodeLengthCodecxx . . $ ZopfliNodeLengthCode(be45bea1a8e379b1).(next); |
| 627 | size_tcxx . . $ size_t# dictionary_start = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, |
| 628 | block_start + pos + stream_offset, max_backward_limit); |
| 629 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_dictionary = |
| 630 | TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(distance > dictionary_start + gap); |
| 631 | size_tcxx . . $ size_t# dist_code = ZopfliNodeDistanceCodecxx . . $ ZopfliNodeDistanceCode(be45bea1a8e379b1).(next); |
| 632 | InitCommandcxx . . $ InitCommand(a0b400081f9cd273).(&commands[i], ¶ms->distcxx . . $ BrotliEncoderParams#dist., insert_length, |
| 633 | copy_length, (int)len_code - (int)copy_length, dist_code); |
| 634 | |
| 635 | if (!is_dictionary && dist_code > 0) { |
| 636 | dist_cache[3] = dist_cache[2]; |
| 637 | dist_cache[2] = dist_cache[1]; |
| 638 | dist_cache[1] = dist_cache[0]; |
| 639 | dist_cache[0] = (int)distance; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | *num_literals += insert_length; |
| 644 | pos += copy_length; |
| 645 | } |
| 646 | *last_insert_len += num_bytes - pos; |
| 647 | } |
| 648 | |
| 649 | static size_tcxx . . $ size_t# ZopfliIteratecxx . . $ ZopfliIterate(b51fba148683124c).(size_tcxx . . $ size_t# num_bytes, size_tcxx . . $ size_t# position, |
| 650 | const uint8_tcxx . . $ uint8_t#* ringbuffer, size_tcxx . . $ size_t# ringbuffer_mask, |
| 651 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, const size_tcxx . . $ size_t# gap, const int* dist_cache, |
| 652 | const ZopfliCostModelcxx . . $ ZopfliCostModel#* model, const uint32_tcxx . . $ uint32_t#* num_matches, |
| 653 | const BackwardMatchcxx . . $ BackwardMatch#* matches, ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 654 | const size_tcxx . . $ size_t# stream_offset = params->stream_offsetcxx . . $ BrotliEncoderParams#stream_offset.; |
| 655 | const size_tcxx . . $ size_t# max_backward_limit = BROTLI_MAX_BACKWARD_LIMITcxx . . $ `c/common/constants.h:101:9`!(params->lgwin); |
| 656 | const size_tcxx . . $ size_t# max_zopfli_len = MaxZopfliLencxx . . $ MaxZopfliLen(76b5aa81b68a1b65).(params); |
| 657 | StartPosQueuecxx . . $ StartPosQueue# queue; |
| 658 | size_tcxx . . $ size_t# cur_match_pos = 0; |
| 659 | size_tcxx . . $ size_t# i; |
| 660 | nodes[0].lengthcxx . . $ ZopfliNode#length. = 0; |
| 661 | nodes[0].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost. = 0; |
| 662 | InitStartPosQueuecxx . . $ InitStartPosQueue(b8d6329df9d7a96).(&queue); |
| 663 | for (i = 0; i + 3 < num_bytes; i++) { |
| 664 | size_tcxx . . $ size_t# skip = UpdateNodescxx . . $ UpdateNodes(dbe1d98d67fa0e3a).(num_bytes, position, i, ringbuffer, |
| 665 | ringbuffer_mask, params, max_backward_limit, dist_cache, |
| 666 | num_matches[i], &matches[cur_match_pos], model, &queue, nodes); |
| 667 | if (skip < BROTLI_LONG_COPY_QUICK_STEPcxx . . $ `c/enc/quality.h:45:9`!) skip = 0; |
| 668 | cur_match_pos += num_matches[i]; |
| 669 | if (num_matches[i] == 1 && |
| 670 | BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(&matches[cur_match_pos - 1]) > max_zopfli_len) { |
| 671 | skip = BROTLI_MAXcxx . . $ `c/common/platform.h:523:9`!(size_t, |
| 672 | BackwardMatchLength(&matches[cur_match_pos - 1]), skip); |
| 673 | } |
| 674 | if (skip > 1) { |
| 675 | skip--; |
| 676 | while (skip) { |
| 677 | i++; |
| 678 | if (i + 3 >= num_bytes) break; |
| 679 | EvaluateNodecxx . . $ EvaluateNode(4be0c448d85264e0).(position + stream_offset, i, max_backward_limit, gap, |
| 680 | dist_cache, model, &queue, nodes); |
| 681 | cur_match_pos += num_matches[i]; |
| 682 | skip--; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | return ComputeShortestPathFromNodescxx . . $ ComputeShortestPathFromNodes(e66215a3f70bb1c4).(num_bytes, nodes); |
| 687 | } |
| 688 | |
| 689 | static void MergeMatchescxx . . $ MergeMatches(352fbbd9aebab3da).(BackwardMatchcxx . . $ BackwardMatch#* dst, |
| 690 | BackwardMatchcxx . . $ BackwardMatch#* src1, size_tcxx . . $ size_t# len1, BackwardMatchcxx . . $ BackwardMatch#* src2, size_tcxx . . $ size_t# len2) { |
| 691 | while (len1 > 0 && len2 > 0) { |
| 692 | size_tcxx . . $ size_t# l1 = BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(src1); |
| 693 | size_tcxx . . $ size_t# l2 = BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(src2); |
| 694 | if (l1 < l2 || ((l1 == l2) && (src1->distancecxx . . $ BackwardMatch#distance. < src2->distancecxx . . $ BackwardMatch#distance.))) { |
| 695 | *dst++ = *src1++; |
| 696 | len1--; |
| 697 | } else { |
| 698 | *dst++ = *src2++; |
| 699 | len2--; |
| 700 | } |
| 701 | } |
| 702 | while (len1-- > 0) *dst++ = *src1++; |
| 703 | while (len2-- > 0) *dst++ = *src2++; |
| 704 | } |
| 705 | |
| 706 | /* REQUIRES: nodes != NULL and len(nodes) >= num_bytes + 1 */ |
| 707 | size_tcxx . . $ size_t# BrotliZopfliComputeShortestPathcxx . . $ BrotliZopfliComputeShortestPath(7f1f18aaf03fb24d).(MemoryManagercxx . . $ MemoryManager#* m, size_tcxx . . $ size_t# num_bytes, |
| 708 | size_tcxx . . $ size_t# position, const uint8_tcxx . . $ uint8_t#* ringbuffer, size_tcxx . . $ size_t# ringbuffer_mask, |
| 709 | ContextLutcxx . . $ ContextLut# literal_context_lut, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, |
| 710 | const int* dist_cache, Hashercxx . . $ Hasher#* hasher, ZopfliNodecxx . . $ ZopfliNode#* nodes) { |
| 711 | const size_tcxx . . $ size_t# stream_offset = params->stream_offsetcxx . . $ BrotliEncoderParams#stream_offset.; |
| 712 | const size_tcxx . . $ size_t# max_backward_limit = BROTLI_MAX_BACKWARD_LIMITcxx . . $ `c/common/constants.h:101:9`!(params->lgwin); |
| 713 | const size_tcxx . . $ size_t# max_zopfli_len = MaxZopfliLencxx . . $ MaxZopfliLen(76b5aa81b68a1b65).(params); |
| 714 | StartPosQueuecxx . . $ StartPosQueue# queue; |
| 715 | BackwardMatchcxx . . $ BackwardMatch#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! matches = |
| 716 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, BackwardMatch, 2 * (MAX_NUM_MATCHES_H10cxx . . $ `c/enc/hash.h:237:9`! + 64)); |
| 717 | const size_tcxx . . $ size_t# store_end = num_bytes >= StoreLookaheadH10cxx . . $ StoreLookaheadH10(f708dce9a8856c70).() ? |
| 718 | position + num_bytes - StoreLookaheadH10cxx . . $ StoreLookaheadH10(f708dce9a8856c70).() + 1 : position; |
| 719 | size_tcxx . . $ size_t# i; |
| 720 | const CompoundDictionarycxx . . $ CompoundDictionary#* addon = ¶ms->dictionarycxx . . $ BrotliEncoderParams#dictionary..compoundcxx . . $ SharedEncoderDictionary#compound.; |
| 721 | size_tcxx . . $ size_t# gap = addon->total_sizecxx . . $ CompoundDictionary#total_size.; |
| 722 | size_tcxx . . $ size_t# lz_matches_offset = |
| 723 | (addon->num_chunkscxx . . $ CompoundDictionary#num_chunks. != 0) ? (MAX_NUM_MATCHES_H10cxx . . $ `c/enc/hash.h:237:9`! + 128) : 0; |
| 724 | ZopfliCostModelcxx . . $ ZopfliCostModel#* model = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, ZopfliCostModel, 1); |
| 725 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(model) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(matches)) { |
| 726 | return 0; |
| 727 | } |
| 728 | nodes[0].lengthcxx . . $ ZopfliNode#length. = 0; |
| 729 | nodes[0].ucxx . . $ ZopfliNode#u..costcxx . . $ ZopfliNode#$anonymous_type_0#cost. = 0; |
| 730 | InitZopfliCostModelcxx . . $ InitZopfliCostModel(421ebed0d8b0f66d).(m, model, ¶ms->distcxx . . $ BrotliEncoderParams#dist., num_bytes); |
| 731 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return 0; |
| 732 | ZopfliCostModelSetFromLiteralCostscxx . . $ ZopfliCostModelSetFromLiteralCosts(63cddf20daa9ab2d).( |
| 733 | model, position, ringbuffer, ringbuffer_mask); |
| 734 | InitStartPosQueuecxx . . $ InitStartPosQueue(b8d6329df9d7a96).(&queue); |
| 735 | for (i = 0; i + HashTypeLengthH10cxx . . $ HashTypeLengthH10(f708dce9a8856c70).() - 1 < num_bytes; i++) { |
| 736 | const size_tcxx . . $ size_t# pos = position + i; |
| 737 | const size_tcxx . . $ size_t# max_distance = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, pos, max_backward_limit); |
| 738 | const size_tcxx . . $ size_t# dictionary_start = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, |
| 739 | pos + stream_offset, max_backward_limit); |
| 740 | size_tcxx . . $ size_t# skip; |
| 741 | size_tcxx . . $ size_t# num_matches; |
| 742 | int dict_id = 0; |
| 743 | if (params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..context_basedcxx . . $ ContextualEncoderDictionary#context_based.) { |
| 744 | uint8_tcxx . . $ uint8_t# p1 = pos >= 1 ? |
| 745 | ringbuffer[(size_tcxx . . $ size_t#)(pos - 1) & ringbuffer_mask] : 0; |
| 746 | uint8_tcxx . . $ uint8_t# p2 = pos >= 2 ? |
| 747 | ringbuffer[(size_tcxx . . $ size_t#)(pos - 2) & ringbuffer_mask] : 0; |
| 748 | dict_id = params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..context_mapcxx . . $ ContextualEncoderDictionary#context_map.[ |
| 749 | BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(p1, p2, literal_context_lut)]; |
| 750 | } |
| 751 | num_matches = FindAllMatchesH10cxx . . $ FindAllMatchesH10(79c7c83183768884).(&hasher->privatcxx . . $ $anonymous_type_5b62deaf4afff4b7_1#privat.._H10cxx . . $ $anonymous_type_5b62deaf4afff4b7_1#$anonymous_type_2#_H10., |
| 752 | params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..dictcxx . . $ ContextualEncoderDictionary#dict.[dict_id], |
| 753 | ringbuffer, ringbuffer_mask, pos, num_bytes - i, max_distance, |
| 754 | dictionary_start + gap, params, &matches[lz_matches_offset]); |
| 755 | if (addon->num_chunkscxx . . $ CompoundDictionary#num_chunks. != 0) { |
| 756 | size_tcxx . . $ size_t# cd_matches = LookupAllCompoundDictionaryMatchescxx . . $ LookupAllCompoundDictionaryMatches(3ea4f1eecfe09d33).(addon, |
| 757 | ringbuffer, ringbuffer_mask, pos, 3, num_bytes - i, |
| 758 | dictionary_start, params->distcxx . . $ BrotliEncoderParams#dist..max_distancecxx . . $ BrotliDistanceParams#max_distance., |
| 759 | &matches[lz_matches_offset - 64], 64); |
| 760 | MergeMatchescxx . . $ MergeMatches(352fbbd9aebab3da).(matches, &matches[lz_matches_offset - 64], cd_matches, |
| 761 | &matches[lz_matches_offset], num_matches); |
| 762 | num_matches += cd_matches; |
| 763 | } |
| 764 | if (num_matches > 0 && |
| 765 | BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(&matches[num_matches - 1]) > max_zopfli_len) { |
| 766 | matches[0] = matches[num_matches - 1]; |
| 767 | num_matches = 1; |
| 768 | } |
| 769 | skip = UpdateNodescxx . . $ UpdateNodes(dbe1d98d67fa0e3a).(num_bytes, position, i, ringbuffer, ringbuffer_mask, |
| 770 | params, max_backward_limit, dist_cache, num_matches, matches, model, |
| 771 | &queue, nodes); |
| 772 | if (skip < BROTLI_LONG_COPY_QUICK_STEPcxx . . $ `c/enc/quality.h:45:9`!) skip = 0; |
| 773 | if (num_matches == 1 && BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(&matches[0]) > max_zopfli_len) { |
| 774 | skip = BROTLI_MAXcxx . . $ `c/common/platform.h:523:9`!(size_t, BackwardMatchLength(&matches[0]), skip); |
| 775 | } |
| 776 | if (skip > 1) { |
| 777 | /* Add the tail of the copy to the hasher. */ |
| 778 | StoreRangeH10cxx . . $ StoreRangeH10(1090477b0db0914d).(&hasher->privatcxx . . $ $anonymous_type_5b62deaf4afff4b7_1#privat.._H10cxx . . $ $anonymous_type_5b62deaf4afff4b7_1#$anonymous_type_2#_H10., |
| 779 | ringbuffer, ringbuffer_mask, pos + 1, BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!( |
| 780 | size_t, pos + skip, store_end)); |
| 781 | skip--; |
| 782 | while (skip) { |
| 783 | i++; |
| 784 | if (i + HashTypeLengthH10cxx . . $ HashTypeLengthH10(f708dce9a8856c70).() - 1 >= num_bytes) break; |
| 785 | EvaluateNodecxx . . $ EvaluateNode(4be0c448d85264e0).(position + stream_offset, i, max_backward_limit, gap, |
| 786 | dist_cache, model, &queue, nodes); |
| 787 | skip--; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | CleanupZopfliCostModelcxx . . $ CleanupZopfliCostModel(4e2bd2fde6673136).(m, model); |
| 792 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, model); |
| 793 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, matches); |
| 794 | return ComputeShortestPathFromNodescxx . . $ ComputeShortestPathFromNodes(e66215a3f70bb1c4).(num_bytes, nodes); |
| 795 | } |
| 796 | |
| 797 | void BrotliCreateZopfliBackwardReferencescxx . . $ BrotliCreateZopfliBackwardReferences(77af74dfdc9f4df3).(MemoryManagercxx . . $ MemoryManager#* m, size_tcxx . . $ size_t# num_bytes, |
| 798 | size_tcxx . . $ size_t# position, const uint8_tcxx . . $ uint8_t#* ringbuffer, size_tcxx . . $ size_t# ringbuffer_mask, |
| 799 | ContextLutcxx . . $ ContextLut# literal_context_lut, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, |
| 800 | Hashercxx . . $ Hasher#* hasher, int* dist_cache, size_tcxx . . $ size_t#* last_insert_len, |
| 801 | Commandcxx . . $ Command#* commands, size_tcxx . . $ size_t#* num_commands, size_tcxx . . $ size_t#* num_literals) { |
| 802 | ZopfliNodecxx . . $ ZopfliNode#* nodes = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, ZopfliNode, num_bytes + 1); |
| 803 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(nodes)) return; |
| 804 | BrotliInitZopfliNodescxx . . $ BrotliInitZopfliNodes(8999d8ffe0627287).(nodes, num_bytes + 1); |
| 805 | *num_commands += BrotliZopfliComputeShortestPathcxx . . $ BrotliZopfliComputeShortestPath(7f1f18aaf03fb24d).(m, num_bytes, |
| 806 | position, ringbuffer, ringbuffer_mask, literal_context_lut, params, |
| 807 | dist_cache, hasher, nodes); |
| 808 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 809 | BrotliZopfliCreateCommandscxx . . $ BrotliZopfliCreateCommands(426b03b768448b1b).(num_bytes, position, nodes, dist_cache, |
| 810 | last_insert_len, params, commands, num_literals); |
| 811 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, nodes); |
| 812 | } |
| 813 | |
| 814 | void BrotliCreateHqZopfliBackwardReferencescxx . . $ BrotliCreateHqZopfliBackwardReferences(77af74dfdc9f4df3).(MemoryManagercxx . . $ MemoryManager#* m, size_tcxx . . $ size_t# num_bytes, |
| 815 | size_tcxx . . $ size_t# position, const uint8_tcxx . . $ uint8_t#* ringbuffer, size_tcxx . . $ size_t# ringbuffer_mask, |
| 816 | ContextLutcxx . . $ ContextLut# literal_context_lut, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, |
| 817 | Hashercxx . . $ Hasher#* hasher, int* dist_cache, size_tcxx . . $ size_t#* last_insert_len, |
| 818 | Commandcxx . . $ Command#* commands, size_tcxx . . $ size_t#* num_commands, size_tcxx . . $ size_t#* num_literals) { |
| 819 | const size_tcxx . . $ size_t# stream_offset = params->stream_offsetcxx . . $ BrotliEncoderParams#stream_offset.; |
| 820 | const size_tcxx . . $ size_t# max_backward_limit = BROTLI_MAX_BACKWARD_LIMITcxx . . $ `c/common/constants.h:101:9`!(params->lgwin); |
| 821 | uint32_tcxx . . $ uint32_t#* num_matches = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, uint32_t, num_bytes); |
| 822 | size_tcxx . . $ size_t# matches_size = 4 * num_bytes; |
| 823 | const size_tcxx . . $ size_t# store_end = num_bytes >= StoreLookaheadH10cxx . . $ StoreLookaheadH10(f708dce9a8856c70).() ? |
| 824 | position + num_bytes - StoreLookaheadH10cxx . . $ StoreLookaheadH10(f708dce9a8856c70).() + 1 : position; |
| 825 | size_tcxx . . $ size_t# cur_match_pos = 0; |
| 826 | size_tcxx . . $ size_t# i; |
| 827 | size_tcxx . . $ size_t# orig_num_literals; |
| 828 | size_tcxx . . $ size_t# orig_last_insert_len; |
| 829 | int orig_dist_cache[4]; |
| 830 | size_tcxx . . $ size_t# orig_num_commands; |
| 831 | ZopfliCostModelcxx . . $ ZopfliCostModel#* model = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, ZopfliCostModel, 1); |
| 832 | ZopfliNodecxx . . $ ZopfliNode#* nodes; |
| 833 | BackwardMatchcxx . . $ BackwardMatch#* matches = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, BackwardMatch, matches_size); |
| 834 | const CompoundDictionarycxx . . $ CompoundDictionary#* addon = ¶ms->dictionarycxx . . $ BrotliEncoderParams#dictionary..compoundcxx . . $ SharedEncoderDictionary#compound.; |
| 835 | size_tcxx . . $ size_t# gap = addon->total_sizecxx . . $ CompoundDictionary#total_size.; |
| 836 | size_tcxx . . $ size_t# shadow_matches = |
| 837 | (addon->num_chunkscxx . . $ CompoundDictionary#num_chunks. != 0) ? (MAX_NUM_MATCHES_H10cxx . . $ `c/enc/hash.h:237:9`! + 128) : 0; |
| 838 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(model) || |
| 839 | BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(num_matches) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(matches)) { |
| 840 | return; |
| 841 | } |
| 842 | for (i = 0; i + HashTypeLengthH10cxx . . $ HashTypeLengthH10(f708dce9a8856c70).() - 1 < num_bytes; ++i) { |
| 843 | const size_tcxx . . $ size_t# pos = position + i; |
| 844 | size_tcxx . . $ size_t# max_distance = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, pos, max_backward_limit); |
| 845 | size_tcxx . . $ size_t# dictionary_start = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, |
| 846 | pos + stream_offset, max_backward_limit); |
| 847 | size_tcxx . . $ size_t# max_length = num_bytes - i; |
| 848 | size_tcxx . . $ size_t# num_found_matches; |
| 849 | size_tcxx . . $ size_t# cur_match_end; |
| 850 | size_tcxx . . $ size_t# j; |
| 851 | int dict_id = 0; |
| 852 | if (params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..context_basedcxx . . $ ContextualEncoderDictionary#context_based.) { |
| 853 | uint8_tcxx . . $ uint8_t# p1 = pos >= 1 ? |
| 854 | ringbuffer[(size_tcxx . . $ size_t#)(pos - 1) & ringbuffer_mask] : 0; |
| 855 | uint8_tcxx . . $ uint8_t# p2 = pos >= 2 ? |
| 856 | ringbuffer[(size_tcxx . . $ size_t#)(pos - 2) & ringbuffer_mask] : 0; |
| 857 | dict_id = params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..context_mapcxx . . $ ContextualEncoderDictionary#context_map.[ |
| 858 | BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(p1, p2, literal_context_lut)]; |
| 859 | } |
| 860 | /* Ensure that we have enough free slots. */ |
| 861 | BROTLI_ENSURE_CAPACITYcxx . . $ `c/enc/memory.h:88:9`!(m, BackwardMatch, matches, matches_size, |
| 862 | cur_match_pos + MAX_NUM_MATCHES_H10cxx . . $ `c/enc/hash.h:237:9`! + shadow_matches); |
| 863 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 864 | num_found_matches = FindAllMatchesH10cxx . . $ FindAllMatchesH10(79c7c83183768884).(&hasher->privatcxx . . $ $anonymous_type_5b62deaf4afff4b7_1#privat.._H10cxx . . $ $anonymous_type_5b62deaf4afff4b7_1#$anonymous_type_2#_H10., |
| 865 | params->dictionarycxx . . $ BrotliEncoderParams#dictionary..contextualcxx . . $ SharedEncoderDictionary#contextual..dictcxx . . $ ContextualEncoderDictionary#dict.[dict_id], |
| 866 | ringbuffer, ringbuffer_mask, pos, max_length, |
| 867 | max_distance, dictionary_start + gap, params, |
| 868 | &matches[cur_match_pos + shadow_matches]); |
| 869 | if (addon->num_chunkscxx . . $ CompoundDictionary#num_chunks. != 0) { |
| 870 | size_tcxx . . $ size_t# cd_matches = LookupAllCompoundDictionaryMatchescxx . . $ LookupAllCompoundDictionaryMatches(3ea4f1eecfe09d33).(addon, |
| 871 | ringbuffer, ringbuffer_mask, pos, 3, max_length, |
| 872 | dictionary_start, params->distcxx . . $ BrotliEncoderParams#dist..max_distancecxx . . $ BrotliDistanceParams#max_distance., |
| 873 | &matches[cur_match_pos + shadow_matches - 64], 64); |
| 874 | MergeMatchescxx . . $ MergeMatches(352fbbd9aebab3da).(&matches[cur_match_pos], |
| 875 | &matches[cur_match_pos + shadow_matches - 64], cd_matches, |
| 876 | &matches[cur_match_pos + shadow_matches], num_found_matches); |
| 877 | num_found_matches += cd_matches; |
| 878 | } |
| 879 | cur_match_end = cur_match_pos + num_found_matches; |
| 880 | for (j = cur_match_pos; j + 1 < cur_match_end; ++j) { |
| 881 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(BackwardMatchLength(&matches[j]) <= |
| 882 | BackwardMatchLength(&matches[j + 1])); |
| 883 | } |
| 884 | num_matches[i] = (uint32_tcxx . . $ uint32_t#)num_found_matches; |
| 885 | if (num_found_matches > 0) { |
| 886 | const size_tcxx . . $ size_t# match_len = BackwardMatchLengthcxx . . $ BackwardMatchLength(a1892b62ee829aa2).(&matches[cur_match_end - 1]); |
| 887 | if (match_len > MAX_ZOPFLI_LEN_QUALITY_11cxx . . $ `c/enc/quality.h:42:9`!) { |
| 888 | const size_tcxx . . $ size_t# skip = match_len - 1; |
| 889 | matches[cur_match_pos++] = matches[cur_match_end - 1]; |
| 890 | num_matches[i] = 1; |
| 891 | /* Add the tail of the copy to the hasher. */ |
| 892 | StoreRangeH10cxx . . $ StoreRangeH10(1090477b0db0914d).(&hasher->privatcxx . . $ $anonymous_type_5b62deaf4afff4b7_1#privat.._H10cxx . . $ $anonymous_type_5b62deaf4afff4b7_1#$anonymous_type_2#_H10., |
| 893 | ringbuffer, ringbuffer_mask, pos + 1, |
| 894 | BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, pos + match_len, store_end)); |
| 895 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&num_matches[i + 1], 0, skip * sizeof(num_matches[0])); |
| 896 | i += skip; |
| 897 | } else { |
| 898 | cur_match_pos = cur_match_end; |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | orig_num_literals = *num_literals; |
| 903 | orig_last_insert_len = *last_insert_len; |
| 904 | memcpycxx . . $ memcpy(cc817cb175f282d).(orig_dist_cache, dist_cache, 4 * sizeof(dist_cache[0])); |
| 905 | orig_num_commands = *num_commands; |
| 906 | nodes = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, ZopfliNode, num_bytes + 1); |
| 907 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(nodes)) return; |
| 908 | InitZopfliCostModelcxx . . $ InitZopfliCostModel(421ebed0d8b0f66d).(m, model, ¶ms->distcxx . . $ BrotliEncoderParams#dist., num_bytes); |
| 909 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 910 | for (i = 0; i < 2; i++) { |
| 911 | BrotliInitZopfliNodescxx . . $ BrotliInitZopfliNodes(8999d8ffe0627287).(nodes, num_bytes + 1); |
| 912 | if (i == 0) { |
| 913 | ZopfliCostModelSetFromLiteralCostscxx . . $ ZopfliCostModelSetFromLiteralCosts(63cddf20daa9ab2d).( |
| 914 | model, position, ringbuffer, ringbuffer_mask); |
| 915 | } else { |
| 916 | ZopfliCostModelSetFromCommandscxx . . $ ZopfliCostModelSetFromCommands(36d046442783dec0).(model, position, ringbuffer, |
| 917 | ringbuffer_mask, commands, *num_commands - orig_num_commands, |
| 918 | orig_last_insert_len); |
| 919 | } |
| 920 | *num_commands = orig_num_commands; |
| 921 | *num_literals = orig_num_literals; |
| 922 | *last_insert_len = orig_last_insert_len; |
| 923 | memcpycxx . . $ memcpy(cc817cb175f282d).(dist_cache, orig_dist_cache, 4 * sizeof(dist_cache[0])); |
| 924 | *num_commands += ZopfliIteratecxx . . $ ZopfliIterate(b51fba148683124c).(num_bytes, position, ringbuffer, |
| 925 | ringbuffer_mask, params, gap, dist_cache, model, num_matches, matches, |
| 926 | nodes); |
| 927 | BrotliZopfliCreateCommandscxx . . $ BrotliZopfliCreateCommands(426b03b768448b1b).(num_bytes, position, nodes, dist_cache, |
| 928 | last_insert_len, params, commands, num_literals); |
| 929 | } |
| 930 | CleanupZopfliCostModelcxx . . $ CleanupZopfliCostModel(4e2bd2fde6673136).(m, model); |
| 931 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, model); |
| 932 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, nodes); |
| 933 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, matches); |
| 934 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, num_matches); |
| 935 | } |
| 936 | |
| 937 | #if defined(__cplusplus) || defined(c_plusplus) |
| 938 | } /* extern "C" */ |
| 939 | #endif |