Using the same hash function in compression on both x86 and ARM

On Intel the instruction used is CRC-32C (Castagnoli), which uses a
different polynomial than 'traditional' crc32 deployed in zlib.

Fortunately ARM has instructions for both polynomials, so this patch
will ensure that compressed content using Chromium's zlib will match
i.e. checksums should be the same.

Bug: https://issuetracker.google.com/115695768
Change-Id: Ia22bc150e89afa345a6d3149c30332a6c1e7934d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726551
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#683225}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 1fa3786817bbf78bcfee9d8675b588ab9fb0b248
diff --git a/crc32_simd.c b/crc32_simd.c
index 2fef610..988f00b 100644
--- a/crc32_simd.c
+++ b/crc32_simd.c
@@ -168,7 +168,7 @@
  * warn, and Android defaults to armv7-a. This restriction does not apply to
  * function-level `target`s, however.)
  *
- * Since we only need three crc intrinsics, and since clang's implementation of
+ * Since we only need four crc intrinsics, and since clang's implementation of
  * those are just wrappers around compiler builtins, it's simplest to #define
  * those builtins directly. If this #define list grows too much (or we depend on
  * an intrinsic that isn't a trivial wrapper), we may have to find a better way
@@ -181,6 +181,7 @@
 #define __crc32b __builtin_arm_crc32b
 #define __crc32d __builtin_arm_crc32d
 #define __crc32w __builtin_arm_crc32w
+#define __crc32cw __builtin_arm_crc32cw
 
 #if defined(__aarch64__)
 #define TARGET_ARMV8_WITH_CRC __attribute__((target("crc")))
@@ -251,7 +252,14 @@
     if (s->level >= 6)
         val &= 0xFFFFFF;
 
-    h = __crc32w(h, val);
+    /* We use CRC32C (Castagnoli) to ensure that the compressed output
+     * will match between Intel x ARM.
+     * Unlike the case of data integrity checks for GZIP format where the
+     * polynomial used is defined (https://tools.ietf.org/html/rfc1952#page-11),
+     * here it is just a hash function for the hash table used while
+     * performing compression.
+     */
+    h = __crc32cw(h, val);
 
     ret = s->head[h & s->hash_mask];
     s->head[h & s->hash_mask] = str;