1616#endif
1717#endif
1818
19- #include "cpu_features.h"
20-
21- // clang-format off
22- #if defined(CRC32_SIMD_SSE42_PCLMUL )
23- #include <smmintrin.h> /* Required to make MSVC bot build pass. */
24-
25- #if defined(__clang__ ) || defined(__GNUC__ )
26- #define TARGET_CPU_WITH_CRC __attribute__((target("sse4.2")))
27- #else
28- #define TARGET_CPU_WITH_CRC
29- #endif
30-
31- /* CRC32C uint32_t */
32- #define _cpu_crc32c_hash_u32 _mm_crc32_u32
33-
34- #elif defined(CRC32_ARMV8_CRC32 )
35- #if defined(__clang__ )
36- #define __crc32cw __builtin_arm_crc32cw
37- #elif defined(__GNUC__ )
38- #define __crc32cw __builtin_aarch64_crc32cw
39- #endif
40-
41- #if defined(__aarch64__ ) && defined(__clang__ )
42- #define TARGET_CPU_WITH_CRC __attribute__((target("crc")))
43- #elif defined(__aarch64__ ) && defined(__GNUC__ )
44- #define TARGET_CPU_WITH_CRC __attribute__((target("+crc")))
45- #elif defined(__clang__ ) // !defined(__aarch64__)
46- #define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc")))
47- #endif // defined(__aarch64__)
48-
49- /* CRC32C uint32_t */
50- #define _cpu_crc32c_hash_u32 __crc32cw
51-
52- #endif
53- // clang-format on
54-
55- #if defined(TARGET_CPU_WITH_CRC )
56-
57- TARGET_CPU_WITH_CRC
58- local INLINE Pos insert_string_simd (deflate_state * const s , const Pos str ) {
59- Pos ret ;
60- unsigned val , h = 0 ;
61-
62- zmemcpy (& val , & s -> window [str ], sizeof (val ));
63-
64- if (s -> level >= 6 )
65- val &= 0xFFFFFF ;
66-
67- /* Compute hash from the CRC32C of |val|. */
68- h = _cpu_crc32c_hash_u32 (h , val );
69-
70- ret = s -> head [h & s -> hash_mask ];
71- s -> head [h & s -> hash_mask ] = str ;
72- s -> prev [str & s -> w_mask ] = ret ;
73- return ret ;
74- }
75-
76- #endif // TARGET_CPU_WITH_CRC
19+ #include <stdint.h>
7720
7821/**
7922 * Some applications need to match zlib DEFLATE output exactly [3]. Use the
@@ -107,10 +50,23 @@ local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
10750 * characters and the first MIN_MATCH bytes of str are valid (except for
10851 * the last MIN_MATCH-1 bytes of the input file).
10952 */
110- local INLINE Pos insert_string_c (deflate_state * const s , const Pos str ) {
53+ local INLINE Pos insert_string (deflate_state * const s , const Pos str ) {
11154 Pos ret ;
112-
55+ /* insert_string dictionary insertion: ANZAC++ hasher
56+ * significantly improves data compression speed.
57+ *
58+ * Note: the generated compressed output is a valid DEFLATE stream, but will
59+ * differ from canonical zlib output.
60+ */
61+ #if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH )
11362 UPDATE_HASH (s , s -> ins_h , s -> window [(str ) + (MIN_MATCH - 1 )]);
63+ #else
64+ uint32_t value ;
65+ // Validated for little endian archs (i.e. x86, Arm). YMMV for big endian.
66+ zmemcpy (& value , & s -> window [str ], sizeof (value ));
67+ s -> ins_h = ((value * 66521 + 66521 ) >> 16 ) & s -> hash_mask ;
68+ #endif
69+
11470#ifdef FASTEST
11571 ret = s -> head [s -> ins_h ];
11672#else
@@ -121,25 +77,4 @@ local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
12177 return ret ;
12278}
12379
124- local INLINE Pos insert_string (deflate_state * const s , const Pos str ) {
125- /* insert_string_simd string dictionary insertion: SIMD crc32c symbol hasher
126- * significantly improves data compression speed.
127- *
128- * Note: the generated compressed output is a valid DEFLATE stream, but will
129- * differ from canonical zlib output.
130- */
131- #if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH )
132- /* So this build-time option can be used to disable the crc32c hash, and use
133- * the Rabin-Karp hash instead.
134- */ /* FALLTHROUGH Rabin-Karp */
135- #elif defined(TARGET_CPU_WITH_CRC ) && defined(CRC32_SIMD_SSE42_PCLMUL )
136- if (x86_cpu_enable_simd )
137- return insert_string_simd (s , str );
138- #elif defined(TARGET_CPU_WITH_CRC ) && defined(CRC32_ARMV8_CRC32 )
139- if (arm_cpu_enable_crc32 )
140- return insert_string_simd (s , str );
141- #endif
142- return insert_string_c (s , str ); /* Rabin-Karp */
143- }
144-
14580#endif /* INSERT_STRING_H */
0 commit comments