Line | Count | Source |
1 | | /* functable.c -- Choose relevant optimized functions at runtime |
2 | | * Copyright (C) 2017 Hans Kristian Rosbach |
3 | | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | | */ |
5 | | #ifndef DISABLE_RUNTIME_CPU_DETECTION |
6 | | |
7 | | #include "zbuild.h" |
8 | | |
9 | | #if defined(_MSC_VER) |
10 | | # include <intrin.h> |
11 | | #endif |
12 | | |
13 | | #include "functable.h" |
14 | | #include "cpu_features.h" |
15 | | #include "arch_functions.h" |
16 | | |
17 | | /* Platform has pointer size atomic store */ |
18 | | #if defined(__GNUC__) || defined(__clang__) |
19 | | # define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \ |
20 | 22 | __atomic_store(&(functable.FUNC_NAME), &(VAR.FUNC_NAME), __ATOMIC_SEQ_CST) |
21 | 2 | # define FUNCTABLE_BARRIER() __atomic_thread_fence(__ATOMIC_SEQ_CST) |
22 | | #elif defined(_MSC_VER) |
23 | | # define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \ |
24 | | _InterlockedExchangePointer((void * volatile *)&(functable.FUNC_NAME), (void *)(VAR.FUNC_NAME)) |
25 | | # ifdef ARCH_ARM |
26 | | # define FUNCTABLE_BARRIER() do { \ |
27 | | _ReadWriteBarrier(); \ |
28 | | __dmb(0xB); /* _ARM_BARRIER_ISH */ \ |
29 | | _ReadWriteBarrier(); \ |
30 | | } while (0) |
31 | | # else |
32 | | # define FUNCTABLE_BARRIER() _ReadWriteBarrier() |
33 | | # endif |
34 | | #else |
35 | | # warning Unable to detect atomic intrinsic support. |
36 | | # define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \ |
37 | | *((void * volatile *)&(functable.FUNC_NAME)) = (void *)(VAR.FUNC_NAME) |
38 | | # define FUNCTABLE_BARRIER() do { /* Empty */ } while (0) |
39 | | #endif |
40 | | |
41 | | /* Verify all pointers are valid before assigning, return 1 on failure |
42 | | * This allows inflateinit/deflateinit functions to gracefully return Z_VERSION_ERROR |
43 | | * if functable initialization fails. |
44 | | */ |
45 | | #define FUNCTABLE_VERIFY_ASSIGN(VAR, FUNC_NAME) \ |
46 | 20 | if (!VAR.FUNC_NAME) { \ |
47 | 0 | fprintf(stderr, "Zlib-ng functable failed initialization!\n"); \ |
48 | 0 | return 1; \ |
49 | 0 | } \ |
50 | 20 | FUNCTABLE_ASSIGN(VAR, FUNC_NAME); |
51 | | |
52 | | /* Functable init & abort on failure. |
53 | | * Abort is needed because some stub functions are reachable without first |
54 | | * calling any inflateinit/deflateinit functions, and have no error propagation. |
55 | | */ |
56 | | #define FUNCTABLE_INIT_ABORT \ |
57 | 2 | if (init_functable()) { \ |
58 | 0 | fprintf(stderr, "Zlib-ng functable failed initialization!\n"); \ |
59 | 0 | abort(); \ |
60 | 2 | }; |
61 | | |
62 | | // Empty stub, used when functable has already been initialized |
63 | 21.1k | static int force_init_empty(void) { |
64 | 21.1k | return 0; |
65 | 21.1k | } |
66 | | |
67 | | /* Functable initialization. |
68 | | * Selects the best available optimized functions appropriate for the runtime cpu. |
69 | | */ |
70 | 2 | static int init_functable(void) { |
71 | 2 | struct functable_s ft; |
72 | 2 | struct cpu_features cf; |
73 | | |
74 | 2 | memset(&ft, 0, sizeof(struct functable_s)); |
75 | 2 | cpu_check_features(&cf); |
76 | 2 | ft.force_init = &force_init_empty; |
77 | | |
78 | | // Only use necessary generic functions when no suitable simd versions are available. |
79 | 2 | #ifdef ADLER32_FALLBACK |
80 | 2 | ft.adler32 = &adler32_c; |
81 | 2 | ft.adler32_copy = &adler32_copy_c; |
82 | 2 | #endif |
83 | | #ifdef CHUNKSET_FALLBACK |
84 | | ft.chunkmemset_safe = &chunkmemset_safe_c; |
85 | | ft.inflate_fast = &inflate_fast_c; |
86 | | #endif |
87 | | #ifdef COMPARE256_FALLBACK |
88 | | ft.compare256 = &compare256_c; |
89 | | ft.longest_match = &longest_match_c; |
90 | | ft.longest_match_roll = &longest_match_roll_c; |
91 | | #endif |
92 | 2 | #ifdef CRC32_BRAID_FALLBACK |
93 | 2 | ft.crc32 = &crc32_braid; |
94 | 2 | ft.crc32_copy = &crc32_copy_braid; |
95 | 2 | #endif |
96 | | #ifdef SLIDE_HASH_FALLBACK |
97 | | ft.slide_hash = &slide_hash_c; |
98 | | #endif |
99 | | |
100 | | // Select arch-optimized functions |
101 | 2 | #ifdef WITH_OPTIM |
102 | | |
103 | | // Chorba generic C fallback |
104 | 2 | #ifdef CRC32_CHORBA_FALLBACK |
105 | 2 | ft.crc32 = &crc32_chorba; |
106 | 2 | ft.crc32_copy = &crc32_copy_chorba; |
107 | 2 | #endif |
108 | | |
109 | | // X86 - SSE2 |
110 | 2 | #ifdef X86_SSE2 |
111 | | # ifndef X86_SSE2_NATIVE |
112 | | if (cf.x86.has_sse2) |
113 | | # endif |
114 | 2 | { |
115 | 2 | # ifndef X86_AVX2_NATIVE |
116 | 2 | ft.chunkmemset_safe = &chunkmemset_safe_sse2; |
117 | 2 | ft.compare256 = &compare256_sse2; |
118 | 2 | ft.inflate_fast = &inflate_fast_sse2; |
119 | 2 | ft.longest_match = &longest_match_sse2; |
120 | 2 | ft.longest_match_roll = &longest_match_roll_sse2; |
121 | 2 | ft.slide_hash = &slide_hash_sse2; |
122 | 2 | # endif |
123 | 2 | # if defined(CRC32_CHORBA_SSE_FALLBACK) && !defined(X86_SSE41_NATIVE) && !defined(X86_PCLMULQDQ_NATIVE) |
124 | 2 | ft.crc32 = &crc32_chorba_sse2; |
125 | 2 | ft.crc32_copy = &crc32_copy_chorba_sse2; |
126 | 2 | # endif |
127 | 2 | } |
128 | 2 | #endif |
129 | | // X86 - SSSE3 |
130 | 2 | #ifdef X86_SSSE3 |
131 | 2 | # ifndef X86_SSSE3_NATIVE |
132 | 2 | if (cf.x86.has_ssse3) |
133 | 2 | # endif |
134 | 2 | { |
135 | 2 | ft.adler32 = &adler32_ssse3; |
136 | 2 | ft.adler32_copy = &adler32_copy_ssse3; |
137 | 2 | # ifndef X86_AVX2_NATIVE |
138 | 2 | ft.chunkmemset_safe = &chunkmemset_safe_ssse3; |
139 | 2 | ft.inflate_fast = &inflate_fast_ssse3; |
140 | 2 | # endif |
141 | 2 | } |
142 | 2 | #endif |
143 | | |
144 | | // X86 - SSE4.1 |
145 | 2 | #if defined(X86_SSE41) && !defined(X86_PCLMULQDQ_NATIVE) |
146 | 2 | # ifndef X86_SSE41_NATIVE |
147 | 2 | if (cf.x86.has_sse41) |
148 | 2 | # endif |
149 | 2 | { |
150 | 2 | # ifdef CRC32_CHORBA_SSE_FALLBACK |
151 | 2 | ft.crc32 = &crc32_chorba_sse41; |
152 | 2 | ft.crc32_copy = &crc32_copy_chorba_sse41; |
153 | 2 | # endif |
154 | 2 | } |
155 | 2 | #endif |
156 | | |
157 | | // X86 - SSE4.2 |
158 | 2 | #if defined(X86_SSE42) && !defined(X86_AVX512_NATIVE) |
159 | 2 | # ifndef X86_SSE42_NATIVE |
160 | 2 | if (cf.x86.has_sse42) |
161 | 2 | # endif |
162 | 2 | { |
163 | 2 | ft.adler32_copy = &adler32_copy_sse42; |
164 | 2 | } |
165 | 2 | #endif |
166 | | // X86 - PCLMUL |
167 | 2 | #if defined(X86_PCLMULQDQ_CRC) && !defined(X86_VPCLMULQDQ_NATIVE) |
168 | 2 | # ifndef X86_PCLMULQDQ_NATIVE |
169 | 2 | if (cf.x86.has_pclmulqdq) |
170 | 2 | # endif |
171 | 2 | { |
172 | 2 | ft.crc32 = &crc32_pclmulqdq; |
173 | 2 | ft.crc32_copy = &crc32_copy_pclmulqdq; |
174 | 2 | } |
175 | 2 | #endif |
176 | | // X86 - AVX2 |
177 | 2 | #ifdef X86_AVX2 |
178 | | /* BMI2 support is all but implicit with AVX2 but let's sanity check this just in case. Enabling BMI2 allows for |
179 | | * flagless shifts, resulting in fewer flag stalls for the pipeline, and allows us to set destination registers |
180 | | * for the shift results as an operand, eliminating several register-register moves when the original value needs |
181 | | * to remain intact. They also allow for a count operand that isn't the CL register, avoiding contention there */ |
182 | 2 | # ifndef X86_AVX2_NATIVE |
183 | 2 | if (cf.x86.has_avx2 && cf.x86.has_bmi2) |
184 | 2 | # endif |
185 | 2 | { |
186 | 2 | # ifndef X86_AVX512_NATIVE |
187 | 2 | ft.adler32 = &adler32_avx2; |
188 | 2 | ft.adler32_copy = &adler32_copy_avx2; |
189 | 2 | ft.chunkmemset_safe = &chunkmemset_safe_avx2; |
190 | 2 | ft.compare256 = &compare256_avx2; |
191 | 2 | ft.inflate_fast = &inflate_fast_avx2; |
192 | 2 | ft.longest_match = &longest_match_avx2; |
193 | 2 | ft.longest_match_roll = &longest_match_roll_avx2; |
194 | 2 | # endif |
195 | 2 | ft.slide_hash = &slide_hash_avx2; |
196 | 2 | } |
197 | 2 | #endif |
198 | 2 | #ifdef X86_AVX2VNNI |
199 | 2 | if (cf.x86.has_avx2vnni) { |
200 | 0 | ft.adler32 = &adler32_avx2_vnni; |
201 | | //ft.adler32_copy = &adler32_copy_avx2_vnni; |
202 | 0 | } |
203 | 2 | #endif |
204 | | // X86 - AVX512 (F,DQ,BW,Vl) |
205 | 2 | #ifdef X86_AVX512 |
206 | 2 | # ifndef X86_AVX512_NATIVE |
207 | 2 | if (cf.x86.has_avx512_common) |
208 | 0 | # endif |
209 | 0 | { |
210 | 0 | # ifndef X86_AVX512VNNI_NATIVE |
211 | 0 | ft.adler32 = &adler32_avx512; |
212 | 0 | ft.adler32_copy = &adler32_copy_avx512; |
213 | 0 | # endif |
214 | 0 | ft.chunkmemset_safe = &chunkmemset_safe_avx512; |
215 | 0 | ft.compare256 = &compare256_avx512; |
216 | 0 | ft.inflate_fast = &inflate_fast_avx512; |
217 | 0 | ft.longest_match = &longest_match_avx512; |
218 | 0 | ft.longest_match_roll = &longest_match_roll_avx512; |
219 | 0 | } |
220 | 2 | #endif |
221 | 2 | #ifdef X86_AVX512VNNI |
222 | 2 | # ifndef X86_AVX512VNNI_NATIVE |
223 | 2 | if (cf.x86.has_avx512vnni) |
224 | 0 | # endif |
225 | 0 | { |
226 | 0 | ft.adler32 = &adler32_avx512_vnni; |
227 | 0 | ft.adler32_copy = &adler32_copy_avx512_vnni; |
228 | 0 | } |
229 | 2 | #endif |
230 | | // X86 - VPCLMULQDQ (AVX2) |
231 | 2 | #ifdef X86_VPCLMULQDQ_AVX2 |
232 | 2 | # ifndef X86_VPCLMULQDQ_AVX2_NATIVE |
233 | 2 | if (cf.x86.has_pclmulqdq && cf.x86.has_avx2 && cf.x86.has_vpclmulqdq) |
234 | 0 | # endif |
235 | 0 | { |
236 | 0 | ft.crc32 = &crc32_vpclmulqdq_avx2; |
237 | 0 | ft.crc32_copy = &crc32_copy_vpclmulqdq_avx2; |
238 | 0 | } |
239 | 2 | #endif |
240 | | // X86 - VPCLMULQDQ (AVX-512) |
241 | 2 | #ifdef X86_VPCLMULQDQ_AVX512 |
242 | 2 | # ifndef X86_VPCLMULQDQ_AVX512_NATIVE |
243 | 2 | if (cf.x86.has_pclmulqdq && cf.x86.has_avx512_common && cf.x86.has_vpclmulqdq) |
244 | 0 | # endif |
245 | 0 | { |
246 | 0 | ft.crc32 = &crc32_vpclmulqdq_avx512; |
247 | 0 | ft.crc32_copy = &crc32_copy_vpclmulqdq_avx512; |
248 | 0 | } |
249 | 2 | #endif |
250 | | |
251 | | |
252 | | // ARM - SIMD |
253 | | #if defined(ARM_SIMD) && !defined(ARM_NEON_NATIVE) |
254 | | # ifndef ARM_SIMD_NATIVE |
255 | | if (cf.arm.has_simd) |
256 | | # endif |
257 | | { |
258 | | ft.slide_hash = &slide_hash_armv6; |
259 | | } |
260 | | #endif |
261 | | // ARM - NEON |
262 | | #ifdef ARM_NEON |
263 | | # ifndef ARM_NEON_NATIVE |
264 | | if (cf.arm.has_neon) |
265 | | # endif |
266 | | { |
267 | | ft.adler32 = &adler32_neon; |
268 | | ft.adler32_copy = &adler32_copy_neon; |
269 | | ft.chunkmemset_safe = &chunkmemset_safe_neon; |
270 | | ft.compare256 = &compare256_neon; |
271 | | ft.inflate_fast = &inflate_fast_neon; |
272 | | ft.longest_match = &longest_match_neon; |
273 | | ft.longest_match_roll = &longest_match_roll_neon; |
274 | | ft.slide_hash = &slide_hash_neon; |
275 | | } |
276 | | #endif |
277 | | // ARM - NEON DotProd |
278 | | #ifdef ARM_NEON_DOTPROD |
279 | | # ifndef ARM_NEON_DOTPROD_NATIVE |
280 | | if (cf.arm.has_neon && cf.arm.has_dotprod) |
281 | | # endif |
282 | | { |
283 | | ft.adler32 = &adler32_neon_dotprod; |
284 | | ft.adler32_copy = &adler32_copy_neon_dotprod; |
285 | | } |
286 | | #endif |
287 | | // ARM - CRC32 |
288 | | #if defined(ARM_CRC32) && !defined(ARM_PMULL_EOR3_NATIVE) |
289 | | # ifndef ARM_CRC32_NATIVE |
290 | | if (cf.arm.has_crc32) |
291 | | # endif |
292 | | { |
293 | | ft.crc32 = &crc32_armv8; |
294 | | ft.crc32_copy = &crc32_copy_armv8; |
295 | | } |
296 | | #endif |
297 | | // ARM - PMULL EOR3 |
298 | | #ifdef ARM_PMULL_EOR3 |
299 | | # ifndef ARM_PMULL_EOR3_NATIVE |
300 | | if (cf.arm.has_crc32 && cf.arm.has_pmull && cf.arm.has_eor3 && cf.arm.has_fast_pmull) |
301 | | # endif |
302 | | { |
303 | | ft.crc32 = &crc32_armv8_pmull_eor3; |
304 | | ft.crc32_copy = &crc32_copy_armv8_pmull_eor3; |
305 | | } |
306 | | #endif |
307 | | |
308 | | // Power - VMX |
309 | | #ifdef PPC_VMX |
310 | | # ifndef PPC_VMX_NATIVE |
311 | | if (cf.power.has_altivec) |
312 | | # endif |
313 | | { |
314 | | ft.adler32 = &adler32_vmx; |
315 | | ft.adler32_copy = &adler32_copy_vmx; |
316 | | ft.slide_hash = &slide_hash_vmx; |
317 | | } |
318 | | #endif |
319 | | // Power8 - VSX |
320 | | #ifdef POWER8_VSX |
321 | | # ifndef POWER8_VSX_NATIVE |
322 | | if (cf.power.has_arch_2_07) |
323 | | # endif |
324 | | { |
325 | | ft.adler32 = &adler32_power8; |
326 | | ft.adler32_copy = &adler32_copy_power8; |
327 | | ft.chunkmemset_safe = &chunkmemset_safe_power8; |
328 | | ft.inflate_fast = &inflate_fast_power8; |
329 | | ft.slide_hash = &slide_hash_power8; |
330 | | } |
331 | | #endif |
332 | | #ifdef POWER8_VSX_CRC32 |
333 | | # ifndef POWER8_VSX_CRC32_NATIVE |
334 | | if (cf.power.has_arch_2_07) |
335 | | # endif |
336 | | { |
337 | | ft.crc32 = &crc32_power8; |
338 | | ft.crc32_copy = &crc32_copy_power8; |
339 | | } |
340 | | #endif |
341 | | // Power9 |
342 | | #ifdef POWER9 |
343 | | # ifndef POWER9_NATIVE |
344 | | if (cf.power.has_arch_3_00) |
345 | | # endif |
346 | | { |
347 | | ft.compare256 = &compare256_power9; |
348 | | ft.longest_match = &longest_match_power9; |
349 | | ft.longest_match_roll = &longest_match_roll_power9; |
350 | | } |
351 | | #endif |
352 | | |
353 | | |
354 | | // RISCV - RVV |
355 | | #ifdef RISCV_RVV |
356 | | # ifndef RISCV_RVV_NATIVE |
357 | | if (cf.riscv.has_rvv) |
358 | | # endif |
359 | | { |
360 | | ft.adler32 = &adler32_rvv; |
361 | | ft.adler32_copy = &adler32_copy_rvv; |
362 | | ft.chunkmemset_safe = &chunkmemset_safe_rvv; |
363 | | ft.compare256 = &compare256_rvv; |
364 | | ft.inflate_fast = &inflate_fast_rvv; |
365 | | ft.longest_match = &longest_match_rvv; |
366 | | ft.longest_match_roll = &longest_match_roll_rvv; |
367 | | ft.slide_hash = &slide_hash_rvv; |
368 | | } |
369 | | #endif |
370 | | |
371 | | // RISCV - ZBC |
372 | | #ifdef RISCV_CRC32_ZBC |
373 | | # ifndef RISCV_ZBC_NATIVE |
374 | | if (cf.riscv.has_zbc) |
375 | | # endif |
376 | | { |
377 | | ft.crc32 = &crc32_riscv64_zbc; |
378 | | ft.crc32_copy = &crc32_copy_riscv64_zbc; |
379 | | } |
380 | | #endif |
381 | | |
382 | | // S390 |
383 | | #ifdef S390_VX |
384 | | # ifndef S390_VX_NATIVE |
385 | | if (cf.s390.has_vx) |
386 | | # endif |
387 | | { |
388 | | ft.crc32 = &crc32_s390_vx; |
389 | | ft.crc32_copy = &crc32_copy_s390_vx; |
390 | | ft.slide_hash = &slide_hash_vx; |
391 | | } |
392 | | #endif |
393 | | |
394 | | // LOONGARCH |
395 | | #ifdef LOONGARCH_CRC |
396 | | # ifndef LOONGARCH_CRC_NATIVE |
397 | | if (cf.loongarch.has_crc) |
398 | | # endif |
399 | | { |
400 | | ft.crc32 = &crc32_loongarch64; |
401 | | ft.crc32_copy = &crc32_copy_loongarch64; |
402 | | } |
403 | | #endif |
404 | | #if defined(LOONGARCH_LSX) && !defined(LOONGARCH_LASX_NATIVE) |
405 | | # ifndef LOONGARCH_LSX_NATIVE |
406 | | if (cf.loongarch.has_lsx) |
407 | | # endif |
408 | | { |
409 | | ft.adler32 = &adler32_lsx; |
410 | | ft.adler32_copy = &adler32_copy_lsx; |
411 | | ft.chunkmemset_safe = &chunkmemset_safe_lsx; |
412 | | ft.compare256 = &compare256_lsx; |
413 | | ft.inflate_fast = &inflate_fast_lsx; |
414 | | ft.longest_match = &longest_match_lsx; |
415 | | ft.longest_match_roll = &longest_match_roll_lsx; |
416 | | ft.slide_hash = &slide_hash_lsx; |
417 | | } |
418 | | #endif |
419 | | #ifdef LOONGARCH_LASX |
420 | | # ifndef LOONGARCH_LASX_NATIVE |
421 | | if (cf.loongarch.has_lasx) |
422 | | # endif |
423 | | { |
424 | | ft.adler32 = &adler32_lasx; |
425 | | ft.adler32_copy = &adler32_copy_lasx; |
426 | | ft.chunkmemset_safe = &chunkmemset_safe_lasx; |
427 | | ft.compare256 = &compare256_lasx; |
428 | | ft.inflate_fast = &inflate_fast_lasx; |
429 | | ft.longest_match = &longest_match_lasx; |
430 | | ft.longest_match_roll = &longest_match_roll_lasx; |
431 | | ft.slide_hash = &slide_hash_lasx; |
432 | | } |
433 | | #endif |
434 | | |
435 | 2 | #endif // WITH_OPTIM |
436 | | |
437 | | // Assign function pointers individually for atomic operation |
438 | 2 | FUNCTABLE_ASSIGN(ft, force_init); |
439 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, adler32); |
440 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, adler32_copy); |
441 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, chunkmemset_safe); |
442 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, compare256); |
443 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, crc32); |
444 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, crc32_copy); |
445 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, inflate_fast); |
446 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, longest_match); |
447 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, longest_match_roll); |
448 | 2 | FUNCTABLE_VERIFY_ASSIGN(ft, slide_hash); |
449 | | |
450 | | // Memory barrier for weak memory order CPUs |
451 | 2 | FUNCTABLE_BARRIER(); |
452 | | |
453 | 2 | return Z_OK; |
454 | 2 | } |
455 | | |
456 | | #if !defined(_WIN32) && (defined(__GNUC__) || defined(__clang__)) |
457 | 2 | static void __attribute__((constructor)) functable_constructor(void) { |
458 | 2 | FUNCTABLE_INIT_ABORT; |
459 | 2 | } |
460 | | #endif |
461 | | |
462 | | /* stub functions */ |
463 | 0 | static int force_init_stub(void) { |
464 | 0 | return init_functable(); |
465 | 0 | } |
466 | | |
467 | 0 | static uint32_t adler32_stub(uint32_t adler, const uint8_t* buf, size_t len) { |
468 | 0 | FUNCTABLE_INIT_ABORT; |
469 | 0 | return functable.adler32(adler, buf, len); |
470 | 0 | } |
471 | | |
472 | 0 | static uint32_t adler32_copy_stub(uint32_t adler, uint8_t* dst, const uint8_t* src, size_t len) { |
473 | 0 | FUNCTABLE_INIT_ABORT; |
474 | 0 | return functable.adler32_copy(adler, dst, src, len); |
475 | 0 | } |
476 | | |
477 | 0 | static uint8_t* chunkmemset_safe_stub(uint8_t* out, uint8_t *from, size_t len, size_t left) { |
478 | 0 | FUNCTABLE_INIT_ABORT; |
479 | 0 | return functable.chunkmemset_safe(out, from, len, left); |
480 | 0 | } |
481 | | |
482 | 0 | static uint32_t compare256_stub(const uint8_t* src0, const uint8_t* src1) { |
483 | 0 | FUNCTABLE_INIT_ABORT; |
484 | 0 | return functable.compare256(src0, src1); |
485 | 0 | } |
486 | | |
487 | 0 | static uint32_t crc32_stub(uint32_t crc, const uint8_t* buf, size_t len) { |
488 | 0 | FUNCTABLE_INIT_ABORT; |
489 | 0 | return functable.crc32(crc, buf, len); |
490 | 0 | } |
491 | | |
492 | 0 | static uint32_t crc32_copy_stub(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { |
493 | 0 | FUNCTABLE_INIT_ABORT; |
494 | 0 | return functable.crc32_copy(crc, dst, src, len); |
495 | 0 | } |
496 | | |
497 | 0 | static void inflate_fast_stub(PREFIX3(stream) *strm, uint32_t start, int safe_mode) { |
498 | 0 | FUNCTABLE_INIT_ABORT; |
499 | 0 | functable.inflate_fast(strm, start, safe_mode); |
500 | 0 | } |
501 | | |
502 | 0 | static uint32_t longest_match_stub(deflate_state* const s, uint32_t cur_match) { |
503 | 0 | FUNCTABLE_INIT_ABORT; |
504 | 0 | return functable.longest_match(s, cur_match); |
505 | 0 | } |
506 | | |
507 | 0 | static uint32_t longest_match_roll_stub(deflate_state* const s, uint32_t cur_match) { |
508 | 0 | FUNCTABLE_INIT_ABORT; |
509 | 0 | return functable.longest_match_roll(s, cur_match); |
510 | 0 | } |
511 | | |
512 | 0 | static void slide_hash_stub(deflate_state* s) { |
513 | 0 | FUNCTABLE_INIT_ABORT; |
514 | 0 | functable.slide_hash(s); |
515 | 0 | } |
516 | | |
517 | | /* functable init */ |
518 | | Z_INTERNAL struct functable_s functable = { |
519 | | force_init_stub, |
520 | | adler32_stub, |
521 | | adler32_copy_stub, |
522 | | chunkmemset_safe_stub, |
523 | | compare256_stub, |
524 | | crc32_stub, |
525 | | crc32_copy_stub, |
526 | | inflate_fast_stub, |
527 | | longest_match_stub, |
528 | | longest_match_roll_stub, |
529 | | slide_hash_stub, |
530 | | }; |
531 | | |
532 | | #endif |