From 961ebc47c5e1620d7940a02b259fd8b56d31361c Mon Sep 17 00:00:00 2001 From: Force Charlie Date: Sat, 14 Oct 2023 00:59:27 +0800 Subject: [PATCH] zlib sync --- lib/archive/version.lock | 2 +- .../contrib/optimizations/insert_string.h | 99 ++++--------------- lib/archive/zlib/deflate.c | 10 +- 3 files changed, 20 insertions(+), 91 deletions(-) diff --git a/lib/archive/version.lock b/lib/archive/version.lock index 69a74b99..dc53dafd 100644 --- a/lib/archive/version.lock +++ b/lib/archive/version.lock @@ -1,4 +1,4 @@ brotli 1.1.0 liblzma: https://tukaani.org/xz/ 5.4.4 zstd: https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz#lib -zlib: https://github.com/chromium/chromium/tree/2a07f84b20d878592fc1262cc5bc5e73210a9f39/third_party/zlib \ No newline at end of file +zlib: https://github.com/chromium/chromium/tree/9b7c86ec068b130bca8a6ceb324980ba8059be7b/third_party/zlib \ No newline at end of file diff --git a/lib/archive/zlib/contrib/optimizations/insert_string.h b/lib/archive/zlib/contrib/optimizations/insert_string.h index c6a296ae..3272b741 100644 --- a/lib/archive/zlib/contrib/optimizations/insert_string.h +++ b/lib/archive/zlib/contrib/optimizations/insert_string.h @@ -16,64 +16,7 @@ #endif #endif -#include "cpu_features.h" - -// clang-format off -#if defined(CRC32_SIMD_SSE42_PCLMUL) - #include /* Required to make MSVC bot build pass. */ - - #if defined(__clang__) || defined(__GNUC__) - #define TARGET_CPU_WITH_CRC __attribute__((target("sse4.2"))) - #else - #define TARGET_CPU_WITH_CRC - #endif - - /* CRC32C uint32_t */ - #define _cpu_crc32c_hash_u32 _mm_crc32_u32 - -#elif defined(CRC32_ARMV8_CRC32) - #if defined(__clang__) - #define __crc32cw __builtin_arm_crc32cw - #elif defined(__GNUC__) - #define __crc32cw __builtin_aarch64_crc32cw - #endif - - #if defined(__aarch64__) && defined(__clang__) - #define TARGET_CPU_WITH_CRC __attribute__((target("crc"))) - #elif defined(__aarch64__) && defined(__GNUC__) - #define TARGET_CPU_WITH_CRC __attribute__((target("+crc"))) - #elif defined(__clang__) // !defined(__aarch64__) - #define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc"))) - #endif // defined(__aarch64__) - - /* CRC32C uint32_t */ - #define _cpu_crc32c_hash_u32 __crc32cw - -#endif -// clang-format on - -#if defined(TARGET_CPU_WITH_CRC) - -TARGET_CPU_WITH_CRC -local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) { - Pos ret; - unsigned val, h = 0; - - zmemcpy(&val, &s->window[str], sizeof(val)); - - if (s->level >= 6) - val &= 0xFFFFFF; - - /* Compute hash from the CRC32C of |val|. */ - h = _cpu_crc32c_hash_u32(h, val); - - ret = s->head[h & s->hash_mask]; - s->head[h & s->hash_mask] = str; - s->prev[str & s->w_mask] = ret; - return ret; -} - -#endif // TARGET_CPU_WITH_CRC +#include /** * 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) { * characters and the first MIN_MATCH bytes of str are valid (except for * the last MIN_MATCH-1 bytes of the input file). */ -local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) { +local INLINE Pos insert_string(deflate_state* const s, const Pos str) { Pos ret; - +/* insert_string dictionary insertion: ANZAC++ hasher + * significantly improves data compression speed. + * + * Note: the generated compressed output is a valid DEFLATE stream, but will + * differ from canonical zlib output. + */ +#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH) UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH - 1)]); +#else + uint32_t value; + // Validated for little endian archs (i.e. x86, Arm). YMMV for big endian. + zmemcpy(&value, &s->window[str], sizeof(value)); + s->ins_h = ((value * 66521 + 66521) >> 16) & s->hash_mask; +#endif + #ifdef FASTEST ret = s->head[s->ins_h]; #else @@ -121,25 +77,4 @@ local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) { return ret; } -local INLINE Pos insert_string(deflate_state* const s, const Pos str) { -/* insert_string_simd string dictionary insertion: SIMD crc32c symbol hasher - * significantly improves data compression speed. - * - * Note: the generated compressed output is a valid DEFLATE stream, but will - * differ from canonical zlib output. - */ -#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH) -/* So this build-time option can be used to disable the crc32c hash, and use - * the Rabin-Karp hash instead. - */ /* FALLTHROUGH Rabin-Karp */ -#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL) - if (x86_cpu_enable_simd) - return insert_string_simd(s, str); -#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32) - if (arm_cpu_enable_crc32) - return insert_string_simd(s, str); -#endif - return insert_string_c(s, str); /* Rabin-Karp */ -} - -#endif /* INSERT_STRING_H */ +#endif /* INSERT_STRING_H */ \ No newline at end of file diff --git a/lib/archive/zlib/deflate.c b/lib/archive/zlib/deflate.c index 1fa55e5d..173ce596 100644 --- a/lib/archive/zlib/deflate.c +++ b/lib/archive/zlib/deflate.c @@ -457,15 +457,9 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, s->w_size = 1 << s->w_bits; s->w_mask = s->w_size - 1; + s->chromium_zlib_hash = 1; +#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH) s->chromium_zlib_hash = 0; -#if !defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH) - #if defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL) - if (x86_cpu_enable_simd) - s->chromium_zlib_hash = 1; - #elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32) - if (arm_cpu_enable_crc32) - s->chromium_zlib_hash = 1; - #endif #endif s->hash_bits = memLevel + 7;