/src/ghostpdl/brotli/c/enc/backward_references.c
Line | Count | Source |
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.h" |
10 | | |
11 | | #include "../common/constants.h" |
12 | | #include "../common/context.h" |
13 | | #include "../common/platform.h" |
14 | | #include "command.h" |
15 | | #include "compound_dictionary.h" |
16 | | #include "encoder_dict.h" |
17 | | #include "hash.h" |
18 | | #include "params.h" |
19 | | #include "quality.h" /* IWYU pragma: keep for inc */ |
20 | | |
21 | | #if defined(__cplusplus) || defined(c_plusplus) |
22 | | extern "C" { |
23 | | #endif |
24 | | |
25 | | static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance, |
26 | | size_t max_distance, |
27 | 0 | const int* dist_cache) { |
28 | 0 | if (distance <= max_distance) { |
29 | 0 | size_t distance_plus_3 = distance + 3; |
30 | 0 | size_t offset0 = distance_plus_3 - (size_t)dist_cache[0]; |
31 | 0 | size_t offset1 = distance_plus_3 - (size_t)dist_cache[1]; |
32 | 0 | if (distance == (size_t)dist_cache[0]) { |
33 | 0 | return 0; |
34 | 0 | } else if (distance == (size_t)dist_cache[1]) { |
35 | 0 | return 1; |
36 | 0 | } else if (offset0 < 7) { |
37 | 0 | return (0x9750468 >> (4 * offset0)) & 0xF; |
38 | 0 | } else if (offset1 < 7) { |
39 | 0 | return (0xFDB1ACE >> (4 * offset1)) & 0xF; |
40 | 0 | } else if (distance == (size_t)dist_cache[2]) { |
41 | 0 | return 2; |
42 | 0 | } else if (distance == (size_t)dist_cache[3]) { |
43 | 0 | return 3; |
44 | 0 | } |
45 | 0 | } |
46 | 0 | return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1; |
47 | 0 | } |
48 | | |
49 | 0 | #define EXPAND_CAT(a, b) CAT(a, b) |
50 | 0 | #define CAT(a, b) a ## b |
51 | 0 | #define FN(X) EXPAND_CAT(X, HASHER()) |
52 | | #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER())) |
53 | | |
54 | | #define PREFIX() N |
55 | 0 | #define ENABLE_COMPOUND_DICTIONARY 0 |
56 | | |
57 | 0 | #define HASHER() H2 |
58 | | /* NOLINTNEXTLINE(build/include) */ |
59 | | #include "backward_references_inc.h" |
60 | | #undef HASHER |
61 | | |
62 | 0 | #define HASHER() H3 |
63 | | /* NOLINTNEXTLINE(build/include) */ |
64 | | #include "backward_references_inc.h" |
65 | | #undef HASHER |
66 | | |
67 | 0 | #define HASHER() H4 |
68 | | /* NOLINTNEXTLINE(build/include) */ |
69 | | #include "backward_references_inc.h" |
70 | | #undef HASHER |
71 | | |
72 | 0 | #define HASHER() H5 |
73 | | /* NOLINTNEXTLINE(build/include) */ |
74 | | #include "backward_references_inc.h" |
75 | | #undef HASHER |
76 | | |
77 | 0 | #define HASHER() H6 |
78 | | /* NOLINTNEXTLINE(build/include) */ |
79 | | #include "backward_references_inc.h" |
80 | | #undef HASHER |
81 | | |
82 | 0 | #define HASHER() H40 |
83 | | /* NOLINTNEXTLINE(build/include) */ |
84 | | #include "backward_references_inc.h" |
85 | | #undef HASHER |
86 | | |
87 | 0 | #define HASHER() H41 |
88 | | /* NOLINTNEXTLINE(build/include) */ |
89 | | #include "backward_references_inc.h" |
90 | | #undef HASHER |
91 | | |
92 | 0 | #define HASHER() H42 |
93 | | /* NOLINTNEXTLINE(build/include) */ |
94 | | #include "backward_references_inc.h" |
95 | | #undef HASHER |
96 | | |
97 | 0 | #define HASHER() H54 |
98 | | /* NOLINTNEXTLINE(build/include) */ |
99 | | #include "backward_references_inc.h" |
100 | | #undef HASHER |
101 | | |
102 | 0 | #define HASHER() H35 |
103 | | /* NOLINTNEXTLINE(build/include) */ |
104 | | #include "backward_references_inc.h" |
105 | | #undef HASHER |
106 | | |
107 | 0 | #define HASHER() H55 |
108 | | /* NOLINTNEXTLINE(build/include) */ |
109 | | #include "backward_references_inc.h" |
110 | | #undef HASHER |
111 | | |
112 | 0 | #define HASHER() H65 |
113 | | /* NOLINTNEXTLINE(build/include) */ |
114 | | #include "backward_references_inc.h" |
115 | | #undef HASHER |
116 | | |
117 | | #if defined(BROTLI_MAX_SIMD_QUALITY) |
118 | 0 | #define HASHER() H58 |
119 | | /* NOLINTNEXTLINE(build/include) */ |
120 | | #include "backward_references_inc.h" |
121 | | #undef HASHER |
122 | | |
123 | 0 | #define HASHER() H68 |
124 | | /* NOLINTNEXTLINE(build/include) */ |
125 | | #include "backward_references_inc.h" |
126 | | #undef HASHER |
127 | | #endif |
128 | | |
129 | | #undef ENABLE_COMPOUND_DICTIONARY |
130 | | #undef PREFIX |
131 | | #define PREFIX() D |
132 | 0 | #define ENABLE_COMPOUND_DICTIONARY 1 |
133 | | |
134 | 0 | #define HASHER() H3 |
135 | | /* NOLINTNEXTLINE(build/include) */ |
136 | | #include "backward_references_inc.h" |
137 | | #undef HASHER |
138 | 0 | #define HASHER() H4 |
139 | | /* NOLINTNEXTLINE(build/include) */ |
140 | | #include "backward_references_inc.h" |
141 | | #undef HASHER |
142 | 0 | #define HASHER() H5 |
143 | | /* NOLINTNEXTLINE(build/include) */ |
144 | | #include "backward_references_inc.h" |
145 | | #undef HASHER |
146 | 0 | #define HASHER() H6 |
147 | | /* NOLINTNEXTLINE(build/include) */ |
148 | | #include "backward_references_inc.h" |
149 | | #undef HASHER |
150 | 0 | #define HASHER() H40 |
151 | | /* NOLINTNEXTLINE(build/include) */ |
152 | | #include "backward_references_inc.h" |
153 | | #undef HASHER |
154 | 0 | #define HASHER() H41 |
155 | | /* NOLINTNEXTLINE(build/include) */ |
156 | | #include "backward_references_inc.h" |
157 | | #undef HASHER |
158 | 0 | #define HASHER() H42 |
159 | | /* NOLINTNEXTLINE(build/include) */ |
160 | | #include "backward_references_inc.h" |
161 | | #undef HASHER |
162 | 0 | #define HASHER() H55 |
163 | | /* NOLINTNEXTLINE(build/include) */ |
164 | | #include "backward_references_inc.h" |
165 | | #undef HASHER |
166 | 0 | #define HASHER() H65 |
167 | | /* NOLINTNEXTLINE(build/include) */ |
168 | | #include "backward_references_inc.h" |
169 | | #undef HASHER |
170 | | #if defined(BROTLI_MAX_SIMD_QUALITY) |
171 | 0 | #define HASHER() H58 |
172 | | /* NOLINTNEXTLINE(build/include) */ |
173 | | #include "backward_references_inc.h" |
174 | | #undef HASHER |
175 | 0 | #define HASHER() H68 |
176 | | /* NOLINTNEXTLINE(build/include) */ |
177 | | #include "backward_references_inc.h" |
178 | | #undef HASHER |
179 | | #endif |
180 | | |
181 | | #undef ENABLE_COMPOUND_DICTIONARY |
182 | | #undef PREFIX |
183 | | |
184 | | #undef EXPORT_FN |
185 | | #undef FN |
186 | | #undef CAT |
187 | | #undef EXPAND_CAT |
188 | | |
189 | | void BrotliCreateBackwardReferences(size_t num_bytes, |
190 | | size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask, |
191 | | ContextLut literal_context_lut, const BrotliEncoderParams* params, |
192 | | Hasher* hasher, int* dist_cache, size_t* last_insert_len, |
193 | 0 | Command* commands, size_t* num_commands, size_t* num_literals) { |
194 | 0 | if (params->dictionary.compound.num_chunks != 0) { |
195 | 0 | switch (params->hasher.type) { |
196 | 0 | #define CASE_(N) \ |
197 | 0 | case N: \ |
198 | 0 | CreateBackwardReferencesDH ## N(num_bytes, \ |
199 | 0 | position, ringbuffer, ringbuffer_mask, \ |
200 | 0 | literal_context_lut, params, hasher, dist_cache, \ |
201 | 0 | last_insert_len, commands, num_commands, num_literals); \ |
202 | 0 | return; |
203 | 0 | CASE_(3) |
204 | 0 | CASE_(4) |
205 | 0 | CASE_(5) |
206 | 0 | CASE_(6) |
207 | 0 | #if defined(BROTLI_MAX_SIMD_QUALITY) |
208 | 0 | CASE_(58) |
209 | 0 | CASE_(68) |
210 | 0 | #endif |
211 | 0 | CASE_(40) |
212 | 0 | CASE_(41) |
213 | 0 | CASE_(42) |
214 | 0 | CASE_(55) |
215 | 0 | CASE_(65) |
216 | 0 | #undef CASE_ |
217 | 0 | default: |
218 | 0 | BROTLI_DCHECK(BROTLI_FALSE); |
219 | 0 | break; |
220 | 0 | } |
221 | 0 | } |
222 | | |
223 | 0 | switch (params->hasher.type) { |
224 | 0 | #define CASE_(N) \ |
225 | 0 | case N: \ |
226 | 0 | CreateBackwardReferencesNH ## N(num_bytes, \ |
227 | 0 | position, ringbuffer, ringbuffer_mask, \ |
228 | 0 | literal_context_lut, params, hasher, dist_cache, \ |
229 | 0 | last_insert_len, commands, num_commands, num_literals); \ |
230 | 0 | return; |
231 | 0 | FOR_GENERIC_HASHERS(CASE_) |
232 | 0 | #undef CASE_ |
233 | 0 | default: |
234 | 0 | BROTLI_DCHECK(BROTLI_FALSE); |
235 | 0 | break; |
236 | 0 | } |
237 | 0 | } |
238 | | |
239 | | #if defined(__cplusplus) || defined(c_plusplus) |
240 | | } /* extern "C" */ |
241 | | #endif |