diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-12-11 04:06:43 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-12-11 04:06:43 +0000 |
commit | 245b4ee9935c9fe7fb4fb6742fb690450104602d (patch) | |
tree | b130b98d5569448cd9c897bf909d042a5590e520 | |
parent | 30a749fe910ca0d41c306fe0f61c79648d77344d (diff) | |
parent | a997168d0959d3d8531c1e6240b35043085b1e98 (diff) | |
download | zlib-245b4ee9935c9fe7fb4fb6742fb690450104602d.tar.gz |
Snap for 6063671 from a997168d0959d3d8531c1e6240b35043085b1e98 to rvc-release
Change-Id: If61c1663c07303eb0e560150ce35e6ba261a94f7
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | OWNERS.android | 1 | ||||
-rw-r--r-- | deflate.c | 76 | ||||
-rw-r--r-- | google/compression_utils_portable.cc | 12 | ||||
-rw-r--r-- | google/compression_utils_portable.h | 1 |
5 files changed, 54 insertions, 42 deletions
@@ -5,11 +5,11 @@ third_party { type: GIT value: "https://chromium.googlesource.com/chromium/src/third_party/zlib/" } - version: "f4f46747bd5c68320126fea54d6993ae0b5c3edd" + version: "f262c1b3c4196a2fee98c113142faff525b8d884" license_type: NOTICE last_upgrade_date { year: 2019 - month: 11 - day: 8 + month: 12 + day: 9 } } diff --git a/OWNERS.android b/OWNERS.android new file mode 100644 index 0000000..7529cb9 --- /dev/null +++ b/OWNERS.android @@ -0,0 +1 @@ +include platform/system/core:/janitors/OWNERS @@ -52,6 +52,10 @@ #include "deflate.h" #include "x86.h" +#if defined(CRC32_SIMD_SSE42_PCLMUL) +#include <smmintrin.h> +#endif + #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) #include "contrib/optimizations/slide_hash_neon.h" #endif @@ -123,8 +127,31 @@ extern void ZLIB_INTERNAL copy_with_crc(z_streamp strm, Bytef *dst, long size); #define INLINE inline #endif -/* Inline optimisation */ -local INLINE Pos insert_string_sse(deflate_state *const s, const Pos str); +/* Intel optimized insert_string. */ +#if defined(CRC32_SIMD_SSE42_PCLMUL) + +#if defined(__GNUC__) || defined(__clang__) +__attribute__((target("sse4.2"))) +#endif +local INLINE Pos insert_string_sse(deflate_state *const s, const Pos str) +{ + Pos ret; + unsigned *ip, val, h = 0; + + ip = (unsigned *)&s->window[str]; + val = *ip; + + if (s->level >= 6) + val &= 0xFFFFFF; + + h = _mm_crc32_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 /* =========================================================================== * Local data @@ -228,10 +255,11 @@ local INLINE Pos insert_string(deflate_state *const s, const Pos str) #if defined(CRC32_ARMV8_CRC32) if (arm_cpu_enable_crc32) return insert_string_arm(s, str); -#endif +#elif defined(CRC32_SIMD_SSE42_PCLMUL) if (x86_cpu_enable_simd) return insert_string_sse(s, str); #endif +#endif return insert_string_c(s, str); } @@ -307,7 +335,15 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, int wrap = 1; static const char my_version[] = ZLIB_VERSION; + // Needed to activate optimized insert_string() that helps compression + // for all wrapper formats (e.g. RAW, ZLIB, GZIP). + // Feature detection is not triggered while using RAW mode (i.e. we never + // call crc32() with a NULL buffer). +#if defined(CRC32_ARMV8_CRC32) + arm_check_features(); +#elif defined(CRC32_SIMD_SSE42_PCLMUL) x86_check_features(); +#endif if (version == Z_NULL || version[0] != my_version[0] || stream_size != sizeof(z_stream)) { @@ -2268,37 +2304,3 @@ local block_state deflate_huff(s, flush) FLUSH_BLOCK(s, 0); return block_done; } - -/* Safe to inline this as GCC/clang will use inline asm and Visual Studio will - * use intrinsic without extra params - */ -local INLINE Pos insert_string_sse(deflate_state *const s, const Pos str) -{ - Pos ret; - unsigned *ip, val, h = 0; - - ip = (unsigned *)&s->window[str]; - val = *ip; - - if (s->level >= 6) - val &= 0xFFFFFF; - -/* Windows clang should use inline asm */ -#if defined(_MSC_VER) && !defined(__clang__) && (defined(_M_IX86) || defined(_M_X64)) - h = _mm_crc32_u32(h, val); -#elif defined(__i386__) || defined(__amd64__) - __asm__ __volatile__ ( - "crc32 %1,%0\n\t" - : "+r" (h) - : "r" (val) - ); -#else - /* This should never happen */ - assert(0); -#endif - - ret = s->head[h & s->hash_mask]; - s->head[h & s->hash_mask] = str; - s->prev[str & s->w_mask] = ret; - return ret; -} diff --git a/google/compression_utils_portable.cc b/google/compression_utils_portable.cc index 21338b5..191e349 100644 --- a/google/compression_utils_portable.cc +++ b/google/compression_utils_portable.cc @@ -66,20 +66,28 @@ int GzipCompressHelper(Bytef* dest, void* (*malloc_fn)(size_t), void (*free_fn)(void*)) { return CompressHelper(GZIP, dest, dest_length, source, source_length, - malloc_fn, free_fn); + Z_DEFAULT_COMPRESSION, malloc_fn, free_fn); } // This code is taken almost verbatim from third_party/zlib/compress.c. The only // difference is deflateInit2() is called which allows different window bits to // be set. > 16 causes a gzip header to be emitted rather than a zlib header, // and negative causes no header to emitted. +// +// Compression level can be a number from 1-9, with 1 being the fastest, 9 being +// the best compression. The default, which the GZIP helper uses, is 6. int CompressHelper(WrapperType wrapper_type, Bytef* dest, uLongf* dest_length, const Bytef* source, uLong source_length, + int compression_level, void* (*malloc_fn)(size_t), void (*free_fn)(void*)) { + if (compression_level < 1 || compression_level > 9) { + compression_level = Z_DEFAULT_COMPRESSION; + } + z_stream stream; // FIXME(cavalcantii): z_const is not defined as 'const'. @@ -118,7 +126,7 @@ int CompressHelper(WrapperType wrapper_type, stream.opaque = static_cast<voidpf>(0); } - int err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, + int err = deflateInit2(&stream, compression_level, Z_DEFLATED, ZlibStreamWrapperType(wrapper_type), kZlibMemoryLevel, Z_DEFAULT_STRATEGY); if (err != Z_OK) diff --git a/google/compression_utils_portable.h b/google/compression_utils_portable.h index 7c3753b..cd004e8 100644 --- a/google/compression_utils_portable.h +++ b/google/compression_utils_portable.h @@ -39,6 +39,7 @@ int CompressHelper(WrapperType wrapper_type, uLongf* dest_length, const Bytef* source, uLong source_length, + int compression_level, void* (*malloc_fn)(size_t), void (*free_fn)(void*)); |