Revert "Using ARMv8 CRC32 specific instruction"

This reverts commit 35988c821c051a57e30c76f9fcd87b7b677bd9bd.

Reason for revert: broke build ('cpu-features.h' not found)
https://uberchromegw.corp.google.com/i/internal.client.clank/builders/x64-builder/builds/13697

Original change's description:
> Using ARMv8 CRC32 specific instruction
> 
> CRC32 affects performance for both image decompression (PNG)
> as also in general browsing while accessing websites that serve
> content using compression (i.e. Content-Encoding: gzip).
> 
> This patch implements an optimized CRC32 function using the
> dedicated instruction available in ARMv8. This instruction is available
> in new Android devices featuring an ARMv8 SoC, like Nexus 5x and
> Google Pixel.
> 
> It should be between 6x (A53: 116ms X 22ms for a 4Kx4Kx4 buffer) to
> 10x faster (A72: 91ms x 9ms) than the C implementation currently used
> by zlib.
> 
> PNG decoding performance gains should be around 5-9%.
> 
> Finally it also introduces code to perform the ARM CPU features detection
> using getauxval()@Linux/CrOS or android_getCpuFeatures(). We pre-built
> and link the CRC32 instruction dependent code but will decide if to
> use it at run time.
> 
> If the feature is not supported, we fallback to the C implementation.
> 
> This approach allows to use the instruction in both 32bits and 64bits
> builds and works fine either in ARMv7 or ARMv8 processor. I tested the
> generated Chromium apk in both a ARMv7 (Nexus 4 and 6) and ARMv8 (Nexus 5x and
> Google Pixel).
> 
> Change-Id: I069408ebc06c49a3c2be4ba3253319e025ee09d7
> Bug: 709716
> Reviewed-on: https://chromium-review.googlesource.com/612629
> Reviewed-by: Chris Blume <cblume@chromium.org>
> Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#520377}

TBR=agl@chromium.org,noel@chromium.org,cavalcantii@chromium.org,cblume@chromium.org,mtklein@chromium.org,adenilson.cavalcanti@arm.com

Change-Id: Ief2c32df5c8a37635f937cd6a671f5574f5a53a3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 709716
Reviewed-on: https://chromium-review.googlesource.com/799930
Reviewed-by: Chris Blume <cblume@chromium.org>
Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#520497}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e7d9a4649bde6f047105d29f0026dd8c3d54143a
diff --git a/BUILD.gn b/BUILD.gn
index 4b3694f..2f19a8f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -6,9 +6,6 @@
 
 if (current_cpu == "arm" || current_cpu == "arm64") {
   import("//build/config/arm.gni")
-  if (!is_ios) {
-    import("//build/config/android/config.gni")
-  }
 }
 
 config("zlib_config") {
@@ -32,21 +29,6 @@
   }
 }
 
-config("zlib_arm_crc32_config") {
-  defines = []
-  if (current_cpu == "arm" || current_cpu == "arm64") {
-    if (!is_ios && !is_chromeos) {
-      defines += [ "USE_ARMV8_CRC32" ]
-    }
-  }
-
-  if (is_android) {
-    defines += [ "ARMV8_OS_ANDROID" ]
-  } else if (is_linux || is_chromeos) {
-    defines += [ "ARMV8_OS_LINUX" ]
-  }
-}
-
 source_set("zlib_adler32_simd") {
   visibility = [ ":*" ]
 
@@ -104,43 +86,6 @@
   configs += [ "//build/config/compiler:no_chromium_code" ]
 }
 
-static_library("zlib_arm_crc32") {
-  # It seems that ChromeOS has a wrapper script messing with compiler flags.
-  if (!is_ios && !is_chromeos &&
-      (current_cpu == "arm" || current_cpu == "arm64")) {
-    sources = []
-    include_dirs = [ "." ]
-    deps = []
-    if (is_android) {
-      if (defined(android_ndk_root) && android_ndk_root != "") {
-        deps += [ "//third_party/android_tools:cpu_features" ]
-      }
-    }
-
-    sources += [
-      "contrib/optimizations/arm/arm_features.c",
-      "contrib/optimizations/arm/arm_features.h",
-      "contrib/optimizations/arm/armv8_crc32.c",
-      "contrib/optimizations/arm/armv8_crc32.h",
-    ]
-
-    if (!is_win || is_clang) {
-      cflags_c = [ "-march=armv8-a+crc" ]
-    }
-  } else {
-    # It seems that we still need some code to be build, so
-    # we avoid using a stub.
-    sources = [
-      "contrib/optimizations/arm/arm_features.c",
-      "contrib/optimizations/arm/arm_features.h",
-    ]
-  }
-
-  configs -= [ "//build/config/compiler:chromium_code" ]
-  configs += [ "//build/config/compiler:no_chromium_code" ]
-  public_configs = [ ":zlib_arm_crc32_config" ]
-}
-
 config("zlib_warnings") {
   if (is_clang && !is_ios && (current_cpu == "x86" || current_cpu == "x64")) {
     cflags = [ "-Wno-incompatible-pointer-types" ]
@@ -148,9 +93,6 @@
 }
 
 static_library("zlib") {
-  defines = []
-  deps = []
-
   if (!is_win) {
     # Don't stomp on "libzlib" on other platforms.
     output_name = "chrome_zlib"
@@ -200,6 +142,9 @@
     }
   }
 
+  defines = []
+  deps = []
+
   if (!is_ios && (current_cpu == "x86" || current_cpu == "x64")) {
     sources += [ "x86.c" ]
 
@@ -209,11 +154,6 @@
   if (current_cpu == "arm" || current_cpu == "arm64") {
     if (arm_use_neon) {
       deps += [ ":zlib_adler32_simd" ]
-
-      # Apple devices lack ARMv8 crc32 instruction.
-      if (!is_ios) {
-        deps += [ ":zlib_arm_crc32" ]
-      }
     }
   }
 
diff --git a/README.chromium b/README.chromium
index 5639a86..9cb10fe 100644
--- a/README.chromium
+++ b/README.chromium
@@ -24,4 +24,4 @@
    additions.
  - Plus the changes in 'patches' folder.
  - Code in contrib/ other than contrib/minizip was added to match zlib's
-   contributor layout.
\ No newline at end of file
+   contributor layout.
diff --git a/contrib/optimizations/arm/arm_features.c b/contrib/optimizations/arm/arm_features.c
deleted file mode 100644
index b0131c1..0000000
--- a/contrib/optimizations/arm/arm_features.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/* arm_features.h -- SoC features detection.
- * Copyright (C) 2017 ARM, Inc.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-#include "arm_features.h"
-#include <stdint.h>
-
-#if defined(ARMV8_OS_LINUX)
-#include <sys/auxv.h>
-#elif defined(ARMV8_OS_ANDROID)
-#include <cpu-features.h>
-#endif
-
-/* Keep the information concerning the features. */
-#if defined(USE_ARMV8_CRC32)
-#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
-#else
-#define ZLIB_INTERNAL
-#endif
-static unsigned char ZLIB_INTERNAL arm_cpu_enable_crc32 = 0;
-static unsigned char ZLIB_INTERNAL arm_cpu_enable_pmull = 0;
-
-/* TODO(cavalcantii): Should we handle Windows? Anyway this is gated in
- * the build.
- */
-#ifdef USE_ARMV8_CRC32
-#include <pthread.h>
-/* A read on manpage for pthread_once() suggests this to safely
- * dynamically perform initialization in C libraries.
- */
-static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
-static void init_arm_features(void)
-{
-    uint32_t flag_crc32 = 0, flag_pmull = 0, capabilities = 0;
-#if defined(ARMV8_OS_LINUX)
-    flag_crc32 = (1 << 7);
-    flag_pmull = (1 << 4);
-    capabilities = getauxval(AT_HWCAP);
-#elif defined(ARMV8_OS_ANDROID)
-    flag_crc32 = ANDROID_CPU_ARM_FEATURE_CRC32;
-    flag_pmull = ANDROID_CPU_ARM_FEATURE_PMULL;
-    capabilities = android_getCpuFeatures();
-#endif
-
-    if (capabilities & flag_crc32)
-        arm_cpu_enable_crc32 = 1;
-
-    if (capabilities & flag_pmull)
-        arm_cpu_enable_pmull = 1;
-}
-#endif
-
-void arm_check_features(void)
-{
-#ifdef USE_ARMV8_CRC32
-    pthread_once(&cpu_check_inited_once, init_arm_features);
-#endif
-}
-
-unsigned char arm_supports_crc32()
-{
-    return arm_cpu_enable_crc32;
-}
-
-unsigned char arm_supports_pmull()
-{
-    return arm_cpu_enable_pmull;
-}
diff --git a/contrib/optimizations/arm/arm_features.h b/contrib/optimizations/arm/arm_features.h
deleted file mode 100644
index 00a7e8a..0000000
--- a/contrib/optimizations/arm/arm_features.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* arm_features.h -- SoC features detection.
- * Copyright (C) 2017 ARM, Inc.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-#ifndef __ARM_FEATURES__
-#define __ARM_FEATURES__
-
-void arm_check_features(void);
-
-/* Wished I could use 'bool'. */
-unsigned char arm_supports_crc32();
-
-unsigned char arm_supports_pmull();
-
-#endif
diff --git a/contrib/optimizations/arm/armv8_crc32.c b/contrib/optimizations/arm/armv8_crc32.c
deleted file mode 100644
index 10313a3..0000000
--- a/contrib/optimizations/arm/armv8_crc32.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Copyright (C) 1995-2011, 2016 Mark Adler
- * Copyright (C) 2017 ARM Holdings Inc.
- * Authors: Adenilson Cavalcanti <adenilson.cavalcanti@arm.com>
- *          Yang Zhang <yang.zhang@arm.com>
- * This software is provided 'as-is', without any express or implied
- * warranty.  In no event will the authors be held liable for any damages
- * arising from the use of this software.
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- * 1. The origin of this software must not be misrepresented; you must not
- *  claim that you wrote the original software. If you use this software
- *    in a product, an acknowledgment in the product documentation would be
- *    appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-#include "armv8_crc32.h"
-#include <arm_acle.h>
-
-uint32_t armv8_crc32_little(uint32_t crc,
-                            const unsigned char *buf,
-                            size_t len)
-{
-    /* Same behavior as crc32_z(). */
-    if (!buf)
-        return 0UL;
-
-    uint32_t c;
-    const uint32_t *buf4;
-
-    c = crc;
-    c = ~c;
-    while (len && ((ptrdiff_t)buf & 3)) {
-        c = __crc32b(c, *buf++);
-        len--;
-    }
-
-    buf4 = (const uint32_t *)(const void *)buf;
-
-    while (len >= 32) {
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-        c = __crc32w(c, *buf4++);
-        len -= 32;
-    }
-
-    while (len >= 4) {
-        c = __crc32w(c, *buf4++);
-        len -= 4;
-    }
-
-    buf = (const unsigned char *)buf4;
-    if (len) {
-        do {
-            c = __crc32b(c, *buf++);
-        } while (--len);
-    }
-
-    c = ~c;
-    return c;
-}
diff --git a/contrib/optimizations/arm/armv8_crc32.h b/contrib/optimizations/arm/armv8_crc32.h
deleted file mode 100644
index 6e329e3..0000000
--- a/contrib/optimizations/arm/armv8_crc32.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* armv8_crc32.h -- CRC32 checksums using ARMv8 instructions.
- * Copyright (C) 2017 ARM, Inc.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-#ifndef __ARMV8_CRC__
-#define __ARMV8_CRC__
-
-// Depending on the compiler flavor, size_t may be defined in
-// one or the other header. See:
-// http://stackoverflow.com/questions/26410466
-#include <stddef.h>
-#include <stdint.h>
-
-uint32_t armv8_crc32_little(uint32_t crc, const unsigned char* buf, size_t len);
-#endif
diff --git a/contrib/optimizations/inflate.c b/contrib/optimizations/inflate.c
index dfb88f2..152f174 100644
--- a/contrib/optimizations/inflate.c
+++ b/contrib/optimizations/inflate.c
@@ -85,9 +85,6 @@
 #include "inflate.h"
 #include "contrib/optimizations/inffast_chunky.h"
 #include "contrib/optimizations/chunkcopy.h"
-#if defined(USE_ARMV8_CRC32)
-#include "contrib/optimizations/arm/arm_features.h"
-#endif
 
 #ifdef MAKEFIXED
 #  ifndef BUILDFIXED
@@ -205,10 +202,6 @@
     int ret;
     struct inflate_state FAR *state;
 
-#if defined(USE_ARMV8_CRC32)
-    arm_check_features();
-#endif
-
     if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
         stream_size != (int)(sizeof(z_stream)))
         return Z_VERSION_ERROR;
diff --git a/crc32.c b/crc32.c
index dbbd040..9162429 100644
--- a/crc32.c
+++ b/crc32.c
@@ -32,11 +32,6 @@
 #include "x86.h"
 #include "zutil.h"      /* for STDC and FAR definitions */
 
-#if defined(USE_ARMV8_CRC32)
-#include "arm_features.h"
-#include "armv8_crc32.h"
-#endif
-
 /* Definitions for doing the crc four data bytes at a time. */
 #if !defined(NOBYFOUR) && defined(Z_U4)
 #  define BYFOUR
@@ -246,10 +241,6 @@
     const unsigned char FAR *buf;
     uInt len;
 {
-#if defined(USE_ARMV8_CRC32)
-    if (arm_supports_crc32())
-        return armv8_crc32_little(crc, buf, len);
-#endif
     return crc32_z(crc, buf, len);
 }
 
diff --git a/deflate.c b/deflate.c
index 8b575fe..aa0c9c6 100644
--- a/deflate.c
+++ b/deflate.c
@@ -51,9 +51,6 @@
 #include <assert.h>
 #include "deflate.h"
 #include "x86.h"
-#if defined(USE_ARMV8_CRC32)
-#include "contrib/optimizations/arm/arm_features.h"
-#endif
 
 const char deflate_copyright[] =
    " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler ";
@@ -286,11 +283,7 @@
      * output size for (length,distance) codes is <= 24 bits.
      */
 
-#if defined(ADLER32_SIMD_SSE3)
     x86_check_features();
-#elif defined(USE_ARMV8_CRC32)
-    arm_check_features();
-#endif
 
     if (version == Z_NULL || version[0] != my_version[0] ||
         stream_size != sizeof(z_stream)) {
diff --git a/inflate.c b/inflate.c
index 71d07dd..e84be46 100644
--- a/inflate.c
+++ b/inflate.c
@@ -85,9 +85,6 @@
 #include "inflate.h"
 #include "inffast.h"
 #include "x86.h"
-#if defined(USE_ARMV8_CRC32)
-#include "contrib/optimizations/arm/arm_features.h"
-#endif
 
 #ifdef MAKEFIXED
 #  ifndef BUILDFIXED
@@ -204,11 +201,8 @@
 {
     int ret;
     struct inflate_state FAR *state;
-#if defined(ADLER32_SIMD_SSE3)
+
     x86_check_features();
-#elif defined(USE_ARMV8_CRC32)
-    arm_check_features();
-#endif
 
     if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
         stream_size != (int)(sizeof(z_stream)))