Skip to content
Snippets Groups Projects
  • Adenilson Cavalcanti's avatar
    Compute crc32 using ARMv8 specific instruction · 72356729
    Adenilson Cavalcanti authored
    CRC32 affects performance for both image decoding (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 ARMv8a. We only support
    ARM Little-Endian (LE).
    
    This instruction is available in new Android devices featuring an
    ARMv8 SoC, like Nexus 5x and Google Pixel. It should be between
    3x (A72) to 7x faster (A53) than the C implementation currently used
    by zlib for 8KB vectors.
    
    This is performance critical code and can be called with both large (8KB)
    or small vectors, therefore we must avoid extraneous function calls or
    branching (otherwise the performance benefits are negated). So the use
    of 'public' variables to read the CPU features status flags
    (i.e. arm_cpu_enable_crc32 | pmull).
    
    Finally it also introduces code to perform run-time ARM CPU feature
    detection on the supported platforms: Android and Linux/CrOS. We build
    and link the CRC32 instruction dependent code, but will decide to use it
    at run-time if the ARM CPU supports the CRC32 instruction. Otherwise,
    we fallback to using zlib's default C implementation.
    
    This approach allows to use the instruction in both 32bits and 64bits and
    works fine either in ARMv7 or ARMv8 processor. I tested the generated
    Chrome apk in both a Nexus 6 (ARMv7) and a Google Pixel (ARMv8).
    
    The crc32 function benefited from input from Yang Zang and Mike Klein,
    while the arm_features benefited from input from Noel Gordon.
    
    Bug: 709716
    Change-Id: I315c1216f8b3a8d88607630a28737c41f52a2f5d
    Reviewed-on: https://chromium-review.googlesource.com/801108
    
    
    Reviewed-by: default avatarChris Blume <cblume@chromium.org>
    Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
    Commit-Queue: Noel Gordon <noel@chromium.org>
    Cr-Original-Commit-Position: refs/heads/master@{#537179}
    Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
    Cr-Mirrored-Commit: 28c9623083688b3a354c33bf77746f4c51f58826
    72356729