summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorNoel Gordon <noel@chromium.org>2020-04-20 08:26:29 +0000
committerCommit Bot <commit-bot@chromium.org>2020-04-20 08:26:29 +0000
commit96b8f5aa7875102b1c72a16e09e028ce9a4a6d69 (patch)
treec5125781604ac9c7d5011c6216e1b1a4f10b1813 /contrib
parent3479ee01ac33fd7cf12e249a8b3cd907431618bf (diff)
downloadzlib-96b8f5aa7875102b1c72a16e09e028ce9a4a6d69.tar.gz
[zlib] Make insert string a little less #ifdef-ie
Remove one level of #ifdef indent to make that part of the code easier to read. Change the accelerated routine name to end in _simd as is our way elsewhere in chromium zlib. Minor: adjust the comments around the performance claims, and move the important comments re CHROMIUM_ZLIB_NO_CASTAGNOLI into that block. Bug: 1032721 Change-Id: Icb4044f3b87277d67f0ff004ac70813af0a91f5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148893 Reviewed-by: Chris Blume <cblume@chromium.org> Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org> Commit-Queue: Noel Gordon <noel@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#760408} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 4520abf183652950cb4b68701f7bd695d127d1f8
Diffstat (limited to 'contrib')
-rw-r--r--contrib/optimizations/insert_string.h59
1 files changed, 30 insertions, 29 deletions
diff --git a/contrib/optimizations/insert_string.h b/contrib/optimizations/insert_string.h
index 1826601..d3bc33c 100644
--- a/contrib/optimizations/insert_string.h
+++ b/contrib/optimizations/insert_string.h
@@ -4,45 +4,47 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the Chromium source repository LICENSE file.
*/
-#ifdef _MSC_VER
+
+#if defined(_MSC_VER)
#define INLINE __inline
#else
#define INLINE inline
#endif
#include "cpu_features.h"
-/* Optimized insert_string block */
-#if defined(CRC32_SIMD_SSE42_PCLMUL) || defined(CRC32_ARMV8_CRC32)
-#define TARGET_CPU_WITH_CRC
+
// clang-format off
#if defined(CRC32_SIMD_SSE42_PCLMUL)
- /* Required to make MSVC bot build pass. */
- #include <smmintrin.h>
- #if defined(__GNUC__) || defined(__clang__)
- #undef TARGET_CPU_WITH_CRC
+ #include <smmintrin.h> /* 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
#define _cpu_crc32_u32 _mm_crc32_u32
#elif defined(CRC32_ARMV8_CRC32)
#if defined(__clang__)
- #undef TARGET_CPU_WITH_CRC
#define __crc32cw __builtin_arm_crc32cw
#endif
- #define _cpu_crc32_u32 __crc32cw
-
#if defined(__aarch64__)
#define TARGET_CPU_WITH_CRC __attribute__((target("crc")))
#else // !defined(__aarch64__)
#define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc")))
#endif // defined(__aarch64__)
+
+ #define _cpu_crc32_u32 __crc32cw
+
#endif
// clang-format on
+
+#if defined(TARGET_CPU_WITH_CRC)
+
TARGET_CPU_WITH_CRC
-local INLINE Pos insert_string_optimized(deflate_state* const s,
- const Pos str) {
+local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
Pos ret;
unsigned *ip, val, h = 0;
@@ -64,7 +66,8 @@ local INLINE Pos insert_string_optimized(deflate_state* const s,
s->prev[str & s->w_mask] = ret;
return ret;
}
-#endif /* Optimized insert_string block */
+
+#endif // TARGET_CPU_WITH_CRC
/* ===========================================================================
* Update a hash value with the given input byte
@@ -99,24 +102,22 @@ 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) {
-/* String dictionary insertion: faster symbol hashing has a positive impact
- * on data compression speeds (around 20% on Intel and 36% on Arm Cortex big
- * cores).
- * A misfeature is that the generated compressed output will differ from
- * vanilla zlib (even though it is still valid 'DEFLATE-d' content).
+/* insert_string_simd string dictionary insertion: this SIMD symbol hashing
+ * significantly improves data compression speed.
*
- * We offer here a way to disable the optimization if there is the expectation
- * that compressed content should match when compared to vanilla zlib.
+ * Note: the generated compressed output is a valid DEFLATE stream but will
+ * differ from vanilla zlib output ...
*/
-#if !defined(CHROMIUM_ZLIB_NO_CASTAGNOLI)
- /* TODO(cavalcantii): unify CPU features code. */
-#if defined(CRC32_ARMV8_CRC32)
- if (arm_cpu_enable_crc32)
- return insert_string_optimized(s, str);
-#elif defined(CRC32_SIMD_SSE42_PCLMUL)
+#if defined(CHROMIUM_ZLIB_NO_CASTAGNOLI)
+/* ... so this build-time option can used to disable the SIMD symbol hasher
+ * if matching vanilla zlib DEFLATE output is required.
+ */ (;) /* FALLTHOUGH */
+#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
if (x86_cpu_enable_simd)
- return insert_string_optimized(s, str);
-#endif
+ 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);
}