| 1 | /* Copyright 2015 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 | /* Algorithms for distributing the literals and commands of a metablock between |
| 8 | block types and contexts. */ |
| 9 | |
| 10 | #include "metablock.h"cxx . . $ `<file>/c/enc/metablock.h`/ |
| 11 | |
| 12 | #include "../common/constants.h"cxx . . $ `<file>/c/common/constants.h`/ |
| 13 | #include "../common/context.h"cxx . . $ `<file>/c/common/context.h`/ |
| 14 | #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/ |
| 15 | #include "bit_cost.h"cxx . . $ `<file>/c/enc/bit_cost.h`/ |
| 16 | #include "block_splitter.h"cxx . . $ `<file>/c/enc/block_splitter.h`/ |
| 17 | #include "cluster.h"cxx . . $ `<file>/c/enc/cluster.h`/ |
| 18 | #include "command.h"cxx . . $ `<file>/c/enc/command.h`/ |
| 19 | #include "entropy_encode.h"cxx . . $ `<file>/c/enc/entropy_encode.h`/ |
| 20 | #include "histogram.h"cxx . . $ `<file>/c/enc/histogram.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 | |
| 25 | #if defined(__cplusplus) || defined(c_plusplus) |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | void BrotliInitDistanceParamscxx . . $ BrotliInitDistanceParams(2c01c44e4661ed90).(BrotliDistanceParamscxx . . $ BrotliDistanceParams#* dist_params, |
| 30 | uint32_tcxx . . $ uint32_t# npostfix, uint32_tcxx . . $ uint32_t# ndirect, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! large_window) { |
| 31 | uint32_tcxx . . $ uint32_t# alphabet_size_max; |
| 32 | uint32_tcxx . . $ uint32_t# alphabet_size_limit; |
| 33 | uint32_tcxx . . $ uint32_t# max_distance; |
| 34 | |
| 35 | dist_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. = npostfix; |
| 36 | dist_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes. = ndirect; |
| 37 | |
| 38 | alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZEcxx . . $ `c/common/constants.h:67:9`!( |
| 39 | npostfix, ndirect, BROTLI_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:66:9`!); |
| 40 | alphabet_size_limit = alphabet_size_max; |
| 41 | max_distance = ndirect + (1U << (BROTLI_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:66:9`! + npostfix + 2)) - |
| 42 | (1U << (npostfix + 2)); |
| 43 | |
| 44 | if (large_window) { |
| 45 | BrotliDistanceCodeLimitcxx . . $ BrotliDistanceCodeLimit# limit = BrotliCalculateDistanceCodeLimitcxx . . $ BrotliCalculateDistanceCodeLimit(708cfc2bb1accb2c).( |
| 46 | BROTLI_MAX_ALLOWED_DISTANCEcxx . . $ `c/common/constants.h:84:9`!, npostfix, ndirect); |
| 47 | alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZEcxx . . $ `c/common/constants.h:67:9`!( |
| 48 | npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:48:9`!); |
| 49 | alphabet_size_limit = limit.max_alphabet_sizecxx . . $ BrotliDistanceCodeLimit#max_alphabet_size.; |
| 50 | max_distance = limit.max_distancecxx . . $ BrotliDistanceCodeLimit#max_distance.; |
| 51 | } |
| 52 | |
| 53 | dist_params->alphabet_size_maxcxx . . $ BrotliDistanceParams#alphabet_size_max. = alphabet_size_max; |
| 54 | dist_params->alphabet_size_limitcxx . . $ BrotliDistanceParams#alphabet_size_limit. = alphabet_size_limit; |
| 55 | dist_params->max_distancecxx . . $ BrotliDistanceParams#max_distance. = max_distance; |
| 56 | } |
| 57 | |
| 58 | static void RecomputeDistancePrefixescxx . . $ RecomputeDistancePrefixes(b60534555fe58dba).(Commandcxx . . $ Command#* cmds, |
| 59 | size_t num_commands, |
| 60 | const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* orig_params, |
| 61 | const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* new_params) { |
| 62 | size_t i; |
| 63 | |
| 64 | if (orig_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. == new_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. && |
| 65 | orig_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes. == |
| 66 | new_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes.) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | for (i = 0; i < num_commands; ++i) { |
| 71 | Commandcxx . . $ Command#* cmd = &cmds[i]; |
| 72 | if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(cmd) && cmd->cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) { |
| 73 | PrefixEncodeCopyDistancecxx . . $ PrefixEncodeCopyDistance(ddce29df8a9022a3).(CommandRestoreDistanceCodecxx . . $ CommandRestoreDistanceCode(cf5fcb3ffd6846bc).(cmd, orig_params), |
| 74 | new_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes., |
| 75 | new_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits., |
| 76 | &cmd->dist_prefix_cxx . . $ Command#dist_prefix_., |
| 77 | &cmd->dist_extra_cxx . . $ Command#dist_extra_.); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! ComputeDistanceCostcxx . . $ ComputeDistanceCost(cd7840c8fbb11193).(const Commandcxx . . $ Command#* cmds, |
| 83 | size_t num_commands, |
| 84 | const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* orig_params, |
| 85 | const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* new_params, |
| 86 | double* cost, |
| 87 | HistogramDistance* tmp) { |
| 88 | size_t i; |
| 89 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! equal_params = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 90 | uint16_tcxx . . $ uint16_t# dist_prefix; |
| 91 | uint32_tcxx . . $ uint32_t# dist_extra; |
| 92 | double extra_bits = 0.0; |
| 93 | HistogramClearDistance(tmp); |
| 94 | |
| 95 | if (orig_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. == new_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. && |
| 96 | orig_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes. == |
| 97 | new_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes.) { |
| 98 | equal_params = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 99 | } |
| 100 | |
| 101 | for (i = 0; i < num_commands; i++) { |
| 102 | const Commandcxx . . $ Command#* cmd = &cmds[i]; |
| 103 | if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(cmd) && cmd->cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) { |
| 104 | if (equal_params) { |
| 105 | dist_prefix = cmd->dist_prefix_cxx . . $ Command#dist_prefix_.; |
| 106 | } else { |
| 107 | uint32_tcxx . . $ uint32_t# distance = CommandRestoreDistanceCodecxx . . $ CommandRestoreDistanceCode(cf5fcb3ffd6846bc).(cmd, orig_params); |
| 108 | if (distance > new_params->max_distancecxx . . $ BrotliDistanceParams#max_distance.) { |
| 109 | return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 110 | } |
| 111 | PrefixEncodeCopyDistancecxx . . $ PrefixEncodeCopyDistance(ddce29df8a9022a3).(distance, |
| 112 | new_params->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes., |
| 113 | new_params->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits., |
| 114 | &dist_prefix, |
| 115 | &dist_extra); |
| 116 | } |
| 117 | HistogramAddDistance(tmp, dist_prefix & 0x3FF); |
| 118 | extra_bits += dist_prefix >> 10; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | *cost = BrotliPopulationCostDistancecxx . . $ BrotliPopulationCostDistance(3992520b5fe99915).(tmp) + extra_bits; |
| 123 | return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 124 | } |
| 125 | |
| 126 | void BrotliBuildMetaBlockcxx . . $ BrotliBuildMetaBlock(4422c24fa3803156).(MemoryManagercxx . . $ MemoryManager#* m, |
| 127 | const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 128 | const size_t pos, |
| 129 | const size_t mask, |
| 130 | BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, |
| 131 | uint8_tcxx . . $ uint8_t# prev_byte, |
| 132 | uint8_tcxx . . $ uint8_t# prev_byte2, |
| 133 | Commandcxx . . $ Command#* cmds, |
| 134 | size_t num_commands, |
| 135 | ContextTypecxx . . $ ContextType# literal_context_mode, |
| 136 | MetaBlockSplitcxx . . $ MetaBlockSplit#* mb) { |
| 137 | /* Histogram ids need to fit in one byte. */ |
| 138 | static const size_t kMaxNumberOfHistograms = 256; |
| 139 | HistogramDistance* distance_histograms; |
| 140 | HistogramLiteralcxx . . $ HistogramLiteral#* literal_histograms; |
| 141 | ContextTypecxx . . $ ContextType#* literal_context_modes = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 142 | size_t literal_histograms_size; |
| 143 | size_t distance_histograms_size; |
| 144 | size_t i; |
| 145 | size_t literal_context_multiplier = 1; |
| 146 | uint32_tcxx . . $ uint32_t# npostfix; |
| 147 | uint32_tcxx . . $ uint32_t# ndirect_msb = 0; |
| 148 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! check_orig = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 149 | double best_dist_cost = 1e99; |
| 150 | BrotliDistanceParamscxx . . $ BrotliDistanceParams# orig_params = params->distcxx . . $ BrotliEncoderParams#dist.; |
| 151 | BrotliDistanceParamscxx . . $ BrotliDistanceParams# new_params = params->distcxx . . $ BrotliEncoderParams#dist.; |
| 152 | HistogramDistance* tmp = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramDistance, 1); |
| 153 | |
| 154 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(tmp)) return; |
| 155 | |
| 156 | for (npostfix = 0; npostfix <= BROTLI_MAX_NPOSTFIXcxx . . $ `c/common/constants.h:64:9`!; npostfix++) { |
| 157 | for (; ndirect_msb < 16; ndirect_msb++) { |
| 158 | uint32_tcxx . . $ uint32_t# ndirect = ndirect_msb << npostfix; |
| 159 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! skip; |
| 160 | double dist_cost; |
| 161 | BrotliInitDistanceParamscxx . . $ BrotliInitDistanceParams(2c01c44e4661ed90).(&new_params, npostfix, ndirect, |
| 162 | params->large_windowcxx . . $ BrotliEncoderParams#large_window.); |
| 163 | if (npostfix == orig_params.distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits. && |
| 164 | ndirect == orig_params.num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes.) { |
| 165 | check_orig = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 166 | } |
| 167 | skip = !ComputeDistanceCostcxx . . $ ComputeDistanceCost(cd7840c8fbb11193).( |
| 168 | cmds, num_commands, &orig_params, &new_params, &dist_cost, tmp); |
| 169 | if (skip || (dist_cost > best_dist_cost)) { |
| 170 | break; |
| 171 | } |
| 172 | best_dist_cost = dist_cost; |
| 173 | params->distcxx . . $ BrotliEncoderParams#dist. = new_params; |
| 174 | } |
| 175 | if (ndirect_msb > 0) ndirect_msb--; |
| 176 | ndirect_msb /= 2; |
| 177 | } |
| 178 | if (check_orig) { |
| 179 | double dist_cost; |
| 180 | ComputeDistanceCostcxx . . $ ComputeDistanceCost(cd7840c8fbb11193).(cmds, num_commands, &orig_params, &orig_params, |
| 181 | &dist_cost, tmp); |
| 182 | if (dist_cost < best_dist_cost) { |
| 183 | /* NB: currently unused; uncomment when more param tuning is added. */ |
| 184 | /* best_dist_cost = dist_cost; */ |
| 185 | params->distcxx . . $ BrotliEncoderParams#dist. = orig_params; |
| 186 | } |
| 187 | } |
| 188 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, tmp); |
| 189 | RecomputeDistancePrefixescxx . . $ RecomputeDistancePrefixes(b60534555fe58dba).(cmds, num_commands, &orig_params, ¶ms->distcxx . . $ BrotliEncoderParams#dist.); |
| 190 | |
| 191 | BrotliSplitBlockcxx . . $ BrotliSplitBlock(dba73011e4417e6d).(m, cmds, num_commands, |
| 192 | ringbuffer, pos, mask, params, |
| 193 | &mb->literal_splitcxx . . $ MetaBlockSplit#literal_split., |
| 194 | &mb->command_splitcxx . . $ MetaBlockSplit#command_split., |
| 195 | &mb->distance_splitcxx . . $ MetaBlockSplit#distance_split.); |
| 196 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 197 | |
| 198 | if (!params->disable_literal_context_modelingcxx . . $ BrotliEncoderParams#disable_literal_context_modeling.) { |
| 199 | literal_context_multiplier = 1 << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!; |
| 200 | literal_context_modes = |
| 201 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, ContextType, mb->literal_split.num_types); |
| 202 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(literal_context_modes)) return; |
| 203 | for (i = 0; i < mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types.; ++i) { |
| 204 | literal_context_modes[i] = literal_context_mode; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | literal_histograms_size = |
| 209 | mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types. * literal_context_multiplier; |
| 210 | literal_histograms = |
| 211 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramLiteral, literal_histograms_size); |
| 212 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(literal_histograms)) return; |
| 213 | ClearHistogramsLiteralcxx . . $ ClearHistogramsLiteral(9ae2b9a392f850a1).(literal_histograms, literal_histograms_size); |
| 214 | |
| 215 | distance_histograms_size = |
| 216 | mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..num_typescxx . . $ BlockSplit#num_types. << BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!; |
| 217 | distance_histograms = |
| 218 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramDistance, distance_histograms_size); |
| 219 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(distance_histograms)) return; |
| 220 | ClearHistogramsDistance(distance_histograms, distance_histograms_size); |
| 221 | |
| 222 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->command_histograms == 0); |
| 223 | mb->command_histograms_sizecxx . . $ MetaBlockSplit#command_histograms_size. = mb->command_splitcxx . . $ MetaBlockSplit#command_split..num_typescxx . . $ BlockSplit#num_types.; |
| 224 | mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms. = |
| 225 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramCommand, mb->command_histograms_size); |
| 226 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->command_histograms)) return; |
| 227 | ClearHistogramsCommand(mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms., mb->command_histograms_sizecxx . . $ MetaBlockSplit#command_histograms_size.); |
| 228 | |
| 229 | BrotliBuildHistogramsWithContextcxx . . $ BrotliBuildHistogramsWithContext(f0e7c0d57a73a3d2).(cmds, num_commands, |
| 230 | &mb->literal_splitcxx . . $ MetaBlockSplit#literal_split., &mb->command_splitcxx . . $ MetaBlockSplit#command_split., &mb->distance_splitcxx . . $ MetaBlockSplit#distance_split., |
| 231 | ringbuffer, pos, mask, prev_byte, prev_byte2, literal_context_modes, |
| 232 | literal_histograms, mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms., distance_histograms); |
| 233 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, literal_context_modes); |
| 234 | |
| 235 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->literal_context_map == 0); |
| 236 | mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size. = |
| 237 | mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types. << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!; |
| 238 | mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map. = |
| 239 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, uint32_t, mb->literal_context_map_size); |
| 240 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->literal_context_map)) return; |
| 241 | |
| 242 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->literal_histograms == 0); |
| 243 | mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size. = mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size.; |
| 244 | mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms. = |
| 245 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramLiteral, mb->literal_histograms_size); |
| 246 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->literal_histograms)) return; |
| 247 | |
| 248 | BrotliClusterHistogramsLiteral(m, literal_histograms, literal_histograms_size, |
| 249 | kMaxNumberOfHistograms, mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms., |
| 250 | &mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size., mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map.); |
| 251 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 252 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, literal_histograms); |
| 253 | |
| 254 | if (params->disable_literal_context_modelingcxx . . $ BrotliEncoderParams#disable_literal_context_modeling.) { |
| 255 | /* Distribute assignment to all contexts. */ |
| 256 | for (i = mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types.; i != 0;) { |
| 257 | size_t j = 0; |
| 258 | i--; |
| 259 | for (; j < (1 << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!); j++) { |
| 260 | mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map.[(i << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!) + j] = |
| 261 | mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map.[i]; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->distance_context_map == 0); |
| 267 | mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size. = |
| 268 | mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..num_typescxx . . $ BlockSplit#num_types. << BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!; |
| 269 | mb->distance_context_mapcxx . . $ MetaBlockSplit#distance_context_map. = |
| 270 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, uint32_t, mb->distance_context_map_size); |
| 271 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->distance_context_map)) return; |
| 272 | |
| 273 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->distance_histograms == 0); |
| 274 | mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size. = mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size.; |
| 275 | mb->distance_histogramscxx . . $ MetaBlockSplit#distance_histograms. = |
| 276 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramDistance, mb->distance_histograms_size); |
| 277 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->distance_histograms)) return; |
| 278 | |
| 279 | BrotliClusterHistogramsDistancecxx . . $ BrotliClusterHistogramsDistance(cbc268d0252df6b1).(m, distance_histograms, |
| 280 | mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size., |
| 281 | kMaxNumberOfHistograms, |
| 282 | mb->distance_histogramscxx . . $ MetaBlockSplit#distance_histograms., |
| 283 | &mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size., |
| 284 | mb->distance_context_mapcxx . . $ MetaBlockSplit#distance_context_map.); |
| 285 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 286 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, distance_histograms); |
| 287 | } |
| 288 | |
| 289 | #define FNcxx . . $ `c/enc/metablock.c:289:9`!(X) X ## Literal |
| 290 | #include "metablock_inc.h"cxx . . $ `<file>/c/enc/metablock_inc.h`/ /* NOLINT(build/include) */ |
| 291 | #undef FNcxx . . $ `c/enc/metablock.c:289:9`! |
| 292 | |
| 293 | #define FNcxx . . $ `c/enc/metablock.c:293:9`!(X) X ## Command |
| 294 | #include "metablock_inc.h"cxx . . $ `<file>/c/enc/metablock_inc.h`/ /* NOLINT(build/include) */ |
| 295 | #undef FNcxx . . $ `c/enc/metablock.c:293:9`! |
| 296 | |
| 297 | #define FNcxx . . $ `c/enc/metablock.c:297:9`!(X) X ## Distance |
| 298 | #include "metablock_inc.h"cxx . . $ `<file>/c/enc/metablock_inc.h`/ /* NOLINT(build/include) */ |
| 299 | #undef FNcxx . . $ `c/enc/metablock.c:297:9`! |
| 300 | |
| 301 | /* Greedy block splitter for one block category (literal, command or distance). |
| 302 | Gathers histograms for all context buckets. */ |
| 303 | typedef struct ContextBlockSplittercxx . . $ ContextBlockSplitter# { |
| 304 | /* Alphabet size of particular block category. */ |
| 305 | size_t alphabet_size_cxx . . $ ContextBlockSplitter#alphabet_size_.; |
| 306 | size_t num_contexts_cxx . . $ ContextBlockSplitter#num_contexts_.; |
| 307 | size_t max_block_types_cxx . . $ ContextBlockSplitter#max_block_types_.; |
| 308 | /* We collect at least this many symbols for each block. */ |
| 309 | size_t min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.; |
| 310 | /* We merge histograms A and B if |
| 311 | entropy(A+B) < entropy(A) + entropy(B) + split_threshold_, |
| 312 | where A is the current histogram and B is the histogram of the last or the |
| 313 | second last block type. */ |
| 314 | double split_threshold_cxx . . $ ContextBlockSplitter#split_threshold_.; |
| 315 | |
| 316 | size_t num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.; |
| 317 | BlockSplitcxx . . $ BlockSplit#* split_cxx . . $ ContextBlockSplitter#split_.; /* not owned */ |
| 318 | HistogramLiteralcxx . . $ HistogramLiteral#* histograms_cxx . . $ ContextBlockSplitter#histograms_.; /* not owned */ |
| 319 | size_t* histograms_size_cxx . . $ ContextBlockSplitter#histograms_size_.; /* not owned */ |
| 320 | |
| 321 | /* The number of symbols that we want to collect before deciding on whether |
| 322 | or not to merge the block with a previous one or emit a new block. */ |
| 323 | size_t target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_.; |
| 324 | /* The number of symbols in the current histogram. */ |
| 325 | size_t block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 326 | /* Offset of the current histogram. */ |
| 327 | size_t curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_.; |
| 328 | /* Offset of the histograms of the previous two block types. */ |
| 329 | size_t last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[2]; |
| 330 | /* Entropy of the previous two block types. */ |
| 331 | double last_entropy_cxx . . $ ContextBlockSplitter#last_entropy_.[2 * BROTLI_MAX_STATIC_CONTEXTScxx . . $ `c/enc/metablock.h:25:9`!]; |
| 332 | /* The number of times we merged the current block with the last one. */ |
| 333 | size_t merge_last_count_cxx . . $ ContextBlockSplitter#merge_last_count_.; |
| 334 | } ContextBlockSplittercxx . . $ ContextBlockSplitter#; |
| 335 | |
| 336 | static void InitContextBlockSplittercxx . . $ InitContextBlockSplitter(4961d4319cf619b).( |
| 337 | MemoryManagercxx . . $ MemoryManager#* m, ContextBlockSplittercxx . . $ ContextBlockSplitter#* self, size_t alphabet_size, |
| 338 | size_t num_contexts, size_t min_block_size, double split_threshold, |
| 339 | size_t num_symbols, BlockSplitcxx . . $ BlockSplit#* split, HistogramLiteralcxx . . $ HistogramLiteral#** histograms, |
| 340 | size_t* histograms_size) { |
| 341 | size_t max_num_blocks = num_symbols / min_block_size + 1; |
| 342 | size_t max_num_types; |
| 343 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(num_contexts <= BROTLI_MAX_STATIC_CONTEXTS); |
| 344 | |
| 345 | self->alphabet_size_cxx . . $ ContextBlockSplitter#alphabet_size_. = alphabet_size; |
| 346 | self->num_contexts_cxx . . $ ContextBlockSplitter#num_contexts_. = num_contexts; |
| 347 | self->max_block_types_cxx . . $ ContextBlockSplitter#max_block_types_. = BROTLI_MAX_NUMBER_OF_BLOCK_TYPEScxx . . $ `c/common/constants.h:21:9`! / num_contexts; |
| 348 | self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_. = min_block_size; |
| 349 | self->split_threshold_cxx . . $ ContextBlockSplitter#split_threshold_. = split_threshold; |
| 350 | self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_. = 0; |
| 351 | self->split_cxx . . $ ContextBlockSplitter#split_. = split; |
| 352 | self->histograms_size_cxx . . $ ContextBlockSplitter#histograms_size_. = histograms_size; |
| 353 | self->target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_. = min_block_size; |
| 354 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = 0; |
| 355 | self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. = 0; |
| 356 | self->merge_last_count_cxx . . $ ContextBlockSplitter#merge_last_count_. = 0; |
| 357 | |
| 358 | /* We have to allocate one more histogram than the maximum number of block |
| 359 | types for the current histogram when the meta-block is too big. */ |
| 360 | max_num_types = |
| 361 | BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(size_t, max_num_blocks, self->max_block_types_ + 1); |
| 362 | BROTLI_ENSURE_CAPACITYcxx . . $ `c/enc/memory.h:88:9`!(m, uint8_t, |
| 363 | split->types, split->types_alloc_size, max_num_blocks); |
| 364 | BROTLI_ENSURE_CAPACITYcxx . . $ `c/enc/memory.h:88:9`!(m, uint32_t, |
| 365 | split->lengths, split->lengths_alloc_size, max_num_blocks); |
| 366 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 367 | split->num_blockscxx . . $ BlockSplit#num_blocks. = max_num_blocks; |
| 368 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 369 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(*histograms == 0); |
| 370 | *histograms_size = max_num_types * num_contexts; |
| 371 | *histograms = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramLiteral, *histograms_size); |
| 372 | self->histograms_cxx . . $ ContextBlockSplitter#histograms_. = *histograms; |
| 373 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(*histograms)) return; |
| 374 | /* Clear only current histogram. */ |
| 375 | ClearHistogramsLiteralcxx . . $ ClearHistogramsLiteral(9ae2b9a392f850a1).(&self->histograms_cxx . . $ ContextBlockSplitter#histograms_.[0], num_contexts); |
| 376 | self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[0] = self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[1] = 0; |
| 377 | } |
| 378 | |
| 379 | /* Does either of three things: |
| 380 | (1) emits the current block with a new block type; |
| 381 | (2) emits the current block with the type of the second last block; |
| 382 | (3) merges the current block with the last block. */ |
| 383 | static void ContextBlockSplitterFinishBlockcxx . . $ ContextBlockSplitterFinishBlock(bd152ba8e878c5a1).( |
| 384 | ContextBlockSplittercxx . . $ ContextBlockSplitter#* self, MemoryManagercxx . . $ MemoryManager#* m, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_final) { |
| 385 | BlockSplitcxx . . $ BlockSplit#* split = self->split_cxx . . $ ContextBlockSplitter#split_.; |
| 386 | const size_t num_contexts = self->num_contexts_cxx . . $ ContextBlockSplitter#num_contexts_.; |
| 387 | double* last_entropy = self->last_entropy_cxx . . $ ContextBlockSplitter#last_entropy_.; |
| 388 | HistogramLiteralcxx . . $ HistogramLiteral#* histograms = self->histograms_cxx . . $ ContextBlockSplitter#histograms_.; |
| 389 | |
| 390 | if (self->block_size_cxx . . $ ContextBlockSplitter#block_size_. < self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.) { |
| 391 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.; |
| 392 | } |
| 393 | if (self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_. == 0) { |
| 394 | size_t i; |
| 395 | /* Create first block. */ |
| 396 | split->lengthscxx . . $ BlockSplit#lengths.[0] = (uint32_tcxx . . $ uint32_t#)self->block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 397 | split->typescxx . . $ BlockSplit#types.[0] = 0; |
| 398 | |
| 399 | for (i = 0; i < num_contexts; ++i) { |
| 400 | last_entropy[i] = |
| 401 | BrotliBitsEntropycxx . . $ BrotliBitsEntropy(5f24fb80db41cf8c).(histograms[i].data_cxx . . $ HistogramLiteral#data_., self->alphabet_size_cxx . . $ ContextBlockSplitter#alphabet_size_.); |
| 402 | last_entropy[num_contexts + i] = last_entropy[i]; |
| 403 | } |
| 404 | ++self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.; |
| 405 | ++split->num_typescxx . . $ BlockSplit#num_types.; |
| 406 | self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. += num_contexts; |
| 407 | if (self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. < *self->histograms_size_cxx . . $ ContextBlockSplitter#histograms_size_.) { |
| 408 | ClearHistogramsLiteralcxx . . $ ClearHistogramsLiteral(9ae2b9a392f850a1).( |
| 409 | &self->histograms_cxx . . $ ContextBlockSplitter#histograms_.[self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_.], self->num_contexts_cxx . . $ ContextBlockSplitter#num_contexts_.); |
| 410 | } |
| 411 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = 0; |
| 412 | } else if (self->block_size_cxx . . $ ContextBlockSplitter#block_size_. > 0) { |
| 413 | /* Try merging the set of histograms for the current block type with the |
| 414 | respective set of histograms for the last and second last block types. |
| 415 | Decide over the split based on the total reduction of entropy across |
| 416 | all contexts. */ |
| 417 | double entropy[BROTLI_MAX_STATIC_CONTEXTScxx . . $ `c/enc/metablock.h:25:9`!]; |
| 418 | HistogramLiteralcxx . . $ HistogramLiteral#* combined_histo = |
| 419 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HistogramLiteral, 2 * num_contexts); |
| 420 | double combined_entropy[2 * BROTLI_MAX_STATIC_CONTEXTScxx . . $ `c/enc/metablock.h:25:9`!]; |
| 421 | double diff[2] = { 0.0 }; |
| 422 | size_t i; |
| 423 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(combined_histo)) return; |
| 424 | for (i = 0; i < num_contexts; ++i) { |
| 425 | size_t curr_histo_ix = self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. + i; |
| 426 | size_t j; |
| 427 | entropy[i] = BrotliBitsEntropycxx . . $ BrotliBitsEntropy(5f24fb80db41cf8c).(histograms[curr_histo_ix].data_cxx . . $ HistogramLiteral#data_., |
| 428 | self->alphabet_size_cxx . . $ ContextBlockSplitter#alphabet_size_.); |
| 429 | for (j = 0; j < 2; ++j) { |
| 430 | size_t jx = j * num_contexts + i; |
| 431 | size_t last_histogram_ix = self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[j] + i; |
| 432 | combined_histo[jx] = histograms[curr_histo_ix]; |
| 433 | HistogramAddHistogramLiteralcxx . . $ HistogramAddHistogramLiteral(6071725b51d2bb46).(&combined_histo[jx], |
| 434 | &histograms[last_histogram_ix]); |
| 435 | combined_entropy[jx] = BrotliBitsEntropycxx . . $ BrotliBitsEntropy(5f24fb80db41cf8c).( |
| 436 | &combined_histo[jx].data_cxx . . $ HistogramLiteral#data_.[0], self->alphabet_size_cxx . . $ ContextBlockSplitter#alphabet_size_.); |
| 437 | diff[j] += combined_entropy[jx] - entropy[i] - last_entropy[jx]; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | if (split->num_typescxx . . $ BlockSplit#num_types. < self->max_block_types_cxx . . $ ContextBlockSplitter#max_block_types_. && |
| 442 | diff[0] > self->split_threshold_cxx . . $ ContextBlockSplitter#split_threshold_. && |
| 443 | diff[1] > self->split_threshold_cxx . . $ ContextBlockSplitter#split_threshold_.) { |
| 444 | /* Create new block. */ |
| 445 | split->lengthscxx . . $ BlockSplit#lengths.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.] = (uint32_tcxx . . $ uint32_t#)self->block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 446 | split->typescxx . . $ BlockSplit#types.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.] = (uint8_tcxx . . $ uint8_t#)split->num_typescxx . . $ BlockSplit#num_types.; |
| 447 | self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[1] = self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[0]; |
| 448 | self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[0] = split->num_typescxx . . $ BlockSplit#num_types. * num_contexts; |
| 449 | for (i = 0; i < num_contexts; ++i) { |
| 450 | last_entropy[num_contexts + i] = last_entropy[i]; |
| 451 | last_entropy[i] = entropy[i]; |
| 452 | } |
| 453 | ++self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.; |
| 454 | ++split->num_typescxx . . $ BlockSplit#num_types.; |
| 455 | self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. += num_contexts; |
| 456 | if (self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. < *self->histograms_size_cxx . . $ ContextBlockSplitter#histograms_size_.) { |
| 457 | ClearHistogramsLiteralcxx . . $ ClearHistogramsLiteral(9ae2b9a392f850a1).( |
| 458 | &self->histograms_cxx . . $ ContextBlockSplitter#histograms_.[self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_.], self->num_contexts_cxx . . $ ContextBlockSplitter#num_contexts_.); |
| 459 | } |
| 460 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = 0; |
| 461 | self->merge_last_count_cxx . . $ ContextBlockSplitter#merge_last_count_. = 0; |
| 462 | self->target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_. = self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.; |
| 463 | } else if (diff[1] < diff[0] - 20.0) { |
| 464 | /* Combine this block with second last block. */ |
| 465 | split->lengthscxx . . $ BlockSplit#lengths.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.] = (uint32_tcxx . . $ uint32_t#)self->block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 466 | split->typescxx . . $ BlockSplit#types.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.] = split->typescxx . . $ BlockSplit#types.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_. - 2]; |
| 467 | BROTLI_SWAPcxx . . $ `c/common/platform.h:525:9`!(size_t, self->last_histogram_ix_, 0, 1); |
| 468 | for (i = 0; i < num_contexts; ++i) { |
| 469 | histograms[self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[0] + i] = |
| 470 | combined_histo[num_contexts + i]; |
| 471 | last_entropy[num_contexts + i] = last_entropy[i]; |
| 472 | last_entropy[i] = combined_entropy[num_contexts + i]; |
| 473 | HistogramClearLiteralcxx . . $ HistogramClearLiteral(7cf5d84e8e4faf7b).(&histograms[self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. + i]); |
| 474 | } |
| 475 | ++self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.; |
| 476 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = 0; |
| 477 | self->merge_last_count_cxx . . $ ContextBlockSplitter#merge_last_count_. = 0; |
| 478 | self->target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_. = self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.; |
| 479 | } else { |
| 480 | /* Combine this block with last block. */ |
| 481 | split->lengthscxx . . $ BlockSplit#lengths.[self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_. - 1] += (uint32_tcxx . . $ uint32_t#)self->block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 482 | for (i = 0; i < num_contexts; ++i) { |
| 483 | histograms[self->last_histogram_ix_cxx . . $ ContextBlockSplitter#last_histogram_ix_.[0] + i] = combined_histo[i]; |
| 484 | last_entropy[i] = combined_entropy[i]; |
| 485 | if (split->num_typescxx . . $ BlockSplit#num_types. == 1) { |
| 486 | last_entropy[num_contexts + i] = last_entropy[i]; |
| 487 | } |
| 488 | HistogramClearLiteralcxx . . $ HistogramClearLiteral(7cf5d84e8e4faf7b).(&histograms[self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. + i]); |
| 489 | } |
| 490 | self->block_size_cxx . . $ ContextBlockSplitter#block_size_. = 0; |
| 491 | if (++self->merge_last_count_cxx . . $ ContextBlockSplitter#merge_last_count_. > 1) { |
| 492 | self->target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_. += self->min_block_size_cxx . . $ ContextBlockSplitter#min_block_size_.; |
| 493 | } |
| 494 | } |
| 495 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, combined_histo); |
| 496 | } |
| 497 | if (is_final) { |
| 498 | *self->histograms_size_cxx . . $ ContextBlockSplitter#histograms_size_. = split->num_typescxx . . $ BlockSplit#num_types. * num_contexts; |
| 499 | split->num_blockscxx . . $ BlockSplit#num_blocks. = self->num_blocks_cxx . . $ ContextBlockSplitter#num_blocks_.; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /* Adds the next symbol to the current block type and context. When the |
| 504 | current block reaches the target size, decides on merging the block. */ |
| 505 | static void ContextBlockSplitterAddSymbolcxx . . $ ContextBlockSplitterAddSymbol(fc0743bde127d499).( |
| 506 | ContextBlockSplittercxx . . $ ContextBlockSplitter#* self, MemoryManagercxx . . $ MemoryManager#* m, |
| 507 | size_t symbol, size_t context) { |
| 508 | HistogramAddLiteralcxx . . $ HistogramAddLiteral(9ae2b9a392f850a1).(&self->histograms_cxx . . $ ContextBlockSplitter#histograms_.[self->curr_histogram_ix_cxx . . $ ContextBlockSplitter#curr_histogram_ix_. + context], |
| 509 | symbol); |
| 510 | ++self->block_size_cxx . . $ ContextBlockSplitter#block_size_.; |
| 511 | if (self->block_size_cxx . . $ ContextBlockSplitter#block_size_. == self->target_block_size_cxx . . $ ContextBlockSplitter#target_block_size_.) { |
| 512 | ContextBlockSplitterFinishBlockcxx . . $ ContextBlockSplitterFinishBlock(bd152ba8e878c5a1).(self, m, /* is_final = */ BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!); |
| 513 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | static void MapStaticContextscxx . . $ MapStaticContexts(fa4cd0bcb9446687).(MemoryManagercxx . . $ MemoryManager#* m, |
| 518 | size_t num_contexts, |
| 519 | const uint32_tcxx . . $ uint32_t#* static_context_map, |
| 520 | MetaBlockSplitcxx . . $ MetaBlockSplit#* mb) { |
| 521 | size_t i; |
| 522 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(mb->literal_context_map == 0); |
| 523 | mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size. = |
| 524 | mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types. << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!; |
| 525 | mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map. = |
| 526 | BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, uint32_t, mb->literal_context_map_size); |
| 527 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(mb->literal_context_map)) return; |
| 528 | |
| 529 | for (i = 0; i < mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types.; ++i) { |
| 530 | uint32_tcxx . . $ uint32_t# offset = (uint32_tcxx . . $ uint32_t#)(i * num_contexts); |
| 531 | size_t j; |
| 532 | for (j = 0; j < (1u << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!); ++j) { |
| 533 | mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map.[(i << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!) + j] = |
| 534 | offset + static_context_map[j]; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | typedef struct GreedyMetablockArenacxx . . $ GreedyMetablockArena# { |
| 540 | unioncxx . . $ GreedyMetablockArena#$anonymous_type_0# { |
| 541 | BlockSplitterLiteralcxx . . $ BlockSplitterLiteral# plaincxx . . $ GreedyMetablockArena#$anonymous_type_0#plain.; |
| 542 | ContextBlockSplittercxx . . $ ContextBlockSplitter# ctxcxx . . $ GreedyMetablockArena#$anonymous_type_0#ctx.; |
| 543 | } lit_blockscxx . . $ GreedyMetablockArena#lit_blocks.; |
| 544 | BlockSplitterCommand cmd_blockscxx . . $ GreedyMetablockArena#cmd_blocks.; |
| 545 | BlockSplitterDistance dist_blockscxx . . $ GreedyMetablockArena#dist_blocks.; |
| 546 | } GreedyMetablockArenacxx . . $ GreedyMetablockArena#; |
| 547 | |
| 548 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBuildMetaBlockGreedyInternalcxx . . $ BrotliBuildMetaBlockGreedyInternal(6c31574493efcee0).( |
| 549 | MemoryManagercxx . . $ MemoryManager#* m, GreedyMetablockArenacxx . . $ GreedyMetablockArena#* arena, const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 550 | size_t pos, size_t mask, uint8_tcxx . . $ uint8_t# prev_byte, uint8_tcxx . . $ uint8_t# prev_byte2, |
| 551 | ContextLutcxx . . $ ContextLut# literal_context_lut, const size_t num_contexts, |
| 552 | const uint32_tcxx . . $ uint32_t#* static_context_map, const Commandcxx . . $ Command#* commands, |
| 553 | size_t n_commands, MetaBlockSplitcxx . . $ MetaBlockSplit#* mb) { |
| 554 | size_t num_literals = 0; |
| 555 | size_t i; |
| 556 | for (i = 0; i < n_commands; ++i) { |
| 557 | num_literals += commands[i].insert_len_cxx . . $ Command#insert_len_.; |
| 558 | } |
| 559 | |
| 560 | if (num_contexts == 1) { |
| 561 | InitBlockSplitterLiteralcxx . . $ InitBlockSplitterLiteral(decaa44dc4f5d84d).(m, &arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..plaincxx . . $ GreedyMetablockArena#$anonymous_type_0#plain., 256, 512, 400.0, |
| 562 | num_literals, &mb->literal_splitcxx . . $ MetaBlockSplit#literal_split., &mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms., |
| 563 | &mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size.); |
| 564 | } else { |
| 565 | InitContextBlockSplittercxx . . $ InitContextBlockSplitter(4961d4319cf619b).(m, &arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..ctxcxx . . $ GreedyMetablockArena#$anonymous_type_0#ctx., 256, num_contexts, 512, |
| 566 | 400.0, num_literals, &mb->literal_splitcxx . . $ MetaBlockSplit#literal_split., &mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms., |
| 567 | &mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size.); |
| 568 | } |
| 569 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 570 | InitBlockSplitterCommand(m, &arena->cmd_blockscxx . . $ GreedyMetablockArena#cmd_blocks., BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, |
| 571 | 1024, 500.0, n_commands, &mb->command_splitcxx . . $ MetaBlockSplit#command_split., &mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms., |
| 572 | &mb->command_histograms_sizecxx . . $ MetaBlockSplit#command_histograms_size.); |
| 573 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 574 | InitBlockSplitterDistance(m, &arena->dist_blockscxx . . $ GreedyMetablockArena#dist_blocks., 64, 512, 100.0, n_commands, |
| 575 | &mb->distance_splitcxx . . $ MetaBlockSplit#distance_split., &mb->distance_histogramscxx . . $ MetaBlockSplit#distance_histograms., |
| 576 | &mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size.); |
| 577 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 578 | |
| 579 | for (i = 0; i < n_commands; ++i) { |
| 580 | const Commandcxx . . $ Command# cmd = commands[i]; |
| 581 | size_t j; |
| 582 | BlockSplitterAddSymbolCommand(&arena->cmd_blockscxx . . $ GreedyMetablockArena#cmd_blocks., cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_.); |
| 583 | for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) { |
| 584 | uint8_tcxx . . $ uint8_t# literal = ringbuffer[pos & mask]; |
| 585 | if (num_contexts == 1) { |
| 586 | BlockSplitterAddSymbolLiteralcxx . . $ BlockSplitterAddSymbolLiteral(c9002bf8e9b91f35).(&arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..plaincxx . . $ GreedyMetablockArena#$anonymous_type_0#plain., literal); |
| 587 | } else { |
| 588 | size_t context = |
| 589 | BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(prev_byte, prev_byte2, literal_context_lut); |
| 590 | ContextBlockSplitterAddSymbolcxx . . $ ContextBlockSplitterAddSymbol(fc0743bde127d499).(&arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..ctxcxx . . $ GreedyMetablockArena#$anonymous_type_0#ctx., m, literal, |
| 591 | static_context_map[context]); |
| 592 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 593 | } |
| 594 | prev_byte2 = prev_byte; |
| 595 | prev_byte = literal; |
| 596 | ++pos; |
| 597 | } |
| 598 | pos += CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd); |
| 599 | if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd)) { |
| 600 | prev_byte2 = ringbuffer[(pos - 2) & mask]; |
| 601 | prev_byte = ringbuffer[(pos - 1) & mask]; |
| 602 | if (cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) { |
| 603 | BlockSplitterAddSymbolDistance( |
| 604 | &arena->dist_blockscxx . . $ GreedyMetablockArena#dist_blocks., cmd.dist_prefix_cxx . . $ Command#dist_prefix_. & 0x3FF); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | if (num_contexts == 1) { |
| 610 | BlockSplitterFinishBlockLiteralcxx . . $ BlockSplitterFinishBlockLiteral(75f0e2daceeee70).( |
| 611 | &arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..plaincxx . . $ GreedyMetablockArena#$anonymous_type_0#plain., /* is_final = */ BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!); |
| 612 | } else { |
| 613 | ContextBlockSplitterFinishBlockcxx . . $ ContextBlockSplitterFinishBlock(bd152ba8e878c5a1).( |
| 614 | &arena->lit_blockscxx . . $ GreedyMetablockArena#lit_blocks..ctxcxx . . $ GreedyMetablockArena#$anonymous_type_0#ctx., m, /* is_final = */ BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!); |
| 615 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return; |
| 616 | } |
| 617 | BlockSplitterFinishBlockCommand( |
| 618 | &arena->cmd_blockscxx . . $ GreedyMetablockArena#cmd_blocks., /* is_final = */ BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!); |
| 619 | BlockSplitterFinishBlockDistance( |
| 620 | &arena->dist_blockscxx . . $ GreedyMetablockArena#dist_blocks., /* is_final = */ BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!); |
| 621 | |
| 622 | if (num_contexts > 1) { |
| 623 | MapStaticContextscxx . . $ MapStaticContexts(fa4cd0bcb9446687).(m, num_contexts, static_context_map, mb); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void BrotliBuildMetaBlockGreedycxx . . $ BrotliBuildMetaBlockGreedy(40a55c7bbd6fada1).(MemoryManagercxx . . $ MemoryManager#* m, |
| 628 | const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 629 | size_t pos, |
| 630 | size_t mask, |
| 631 | uint8_tcxx . . $ uint8_t# prev_byte, |
| 632 | uint8_tcxx . . $ uint8_t# prev_byte2, |
| 633 | ContextLutcxx . . $ ContextLut# literal_context_lut, |
| 634 | size_t num_contexts, |
| 635 | const uint32_tcxx . . $ uint32_t#* static_context_map, |
| 636 | const Commandcxx . . $ Command#* commands, |
| 637 | size_t n_commands, |
| 638 | MetaBlockSplitcxx . . $ MetaBlockSplit#* mb) { |
| 639 | GreedyMetablockArenacxx . . $ GreedyMetablockArena#* arena = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, GreedyMetablockArena, 1); |
| 640 | if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(arena)) return; |
| 641 | if (num_contexts == 1) { |
| 642 | BrotliBuildMetaBlockGreedyInternalcxx . . $ BrotliBuildMetaBlockGreedyInternal(6c31574493efcee0).(m, arena, ringbuffer, pos, mask, |
| 643 | prev_byte, prev_byte2, literal_context_lut, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, commands, |
| 644 | n_commands, mb); |
| 645 | } else { |
| 646 | BrotliBuildMetaBlockGreedyInternalcxx . . $ BrotliBuildMetaBlockGreedyInternal(6c31574493efcee0).(m, arena, ringbuffer, pos, mask, |
| 647 | prev_byte, prev_byte2, literal_context_lut, num_contexts, |
| 648 | static_context_map, commands, n_commands, mb); |
| 649 | } |
| 650 | BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, arena); |
| 651 | } |
| 652 | |
| 653 | void BrotliOptimizeHistogramscxx . . $ BrotliOptimizeHistograms(609b02cab55438a9).(uint32_tcxx . . $ uint32_t# num_distance_codes, |
| 654 | MetaBlockSplitcxx . . $ MetaBlockSplit#* mb) { |
| 655 | uint8_tcxx . . $ uint8_t# good_for_rle[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!]; |
| 656 | size_t i; |
| 657 | for (i = 0; i < mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size.; ++i) { |
| 658 | BrotliOptimizeHuffmanCountsForRlecxx . . $ BrotliOptimizeHuffmanCountsForRle(c1200953a35bc128).(256, mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms.[i].data_cxx . . $ HistogramLiteral#data_., |
| 659 | good_for_rle); |
| 660 | } |
| 661 | for (i = 0; i < mb->command_histograms_sizecxx . . $ MetaBlockSplit#command_histograms_size.; ++i) { |
| 662 | BrotliOptimizeHuffmanCountsForRlecxx . . $ BrotliOptimizeHuffmanCountsForRle(c1200953a35bc128).(BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, |
| 663 | mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms.[i].data_, |
| 664 | good_for_rle); |
| 665 | } |
| 666 | for (i = 0; i < mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size.; ++i) { |
| 667 | BrotliOptimizeHuffmanCountsForRlecxx . . $ BrotliOptimizeHuffmanCountsForRle(c1200953a35bc128).(num_distance_codes, |
| 668 | mb->distance_histogramscxx . . $ MetaBlockSplit#distance_histograms.[i].data_, |
| 669 | good_for_rle); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | #if defined(__cplusplus) || defined(c_plusplus) |
| 674 | } /* extern "C" */ |
| 675 | #endif |