summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
authorAdenilson Cavalcanti <adenilson.cavalcanti@arm.com>2019-11-21 23:04:38 +0000
committerCommit Bot <commit-bot@chromium.org>2019-11-21 23:04:38 +0000
commit7c4128a124a812d086478e5c5f9f2f5893ab8871 (patch)
tree9c903a3e86fec47ca8aebcd7741fe2aa29bc2d71 /deflate.c
parente5c4d8c45ed18f84ea68f5029c9bceb1f67268b8 (diff)
downloadzlib-7c4128a124a812d086478e5c5f9f2f5893ab8871.tar.gz
Fix performance issue in RAW mode
While investigating the use of RAW mode, I noticed that it was *slower* for compression than GZIP or ZLIB wrapper formats, which didn't make sense (i.e. we don't calculate a data integrity check using RAW mode). It turns out that the code was falling back to the portable implementation of insert_string(), instead of using the optimized version that rely on 'crc32w' as a hash function. The reason is that CPU features detection is not triggered while using RAW mode (i.e. we never call crc32() with a NULL buffer). This patch fixes this issue ensuring that RAW mode is going to be faster for both compression/decompression than either ZLIB or GZIP formats. Bug: 833361 Change-Id: I285297f67ffc0114700ed03c2186ad21aab8b40e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929634 Reviewed-by: Chris Blume <cblume@chromium.org> Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org> Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#717877} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 171a0a69eb5d70f8a9f44000e26bc7dc65f1fd97
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/deflate.c b/deflate.c
index c950d6f..1f0bc0e 100644
--- a/deflate.c
+++ b/deflate.c
@@ -307,7 +307,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)) {