• Radu Berinde's avatar
    hash/crc32: improve the processing of the last bytes in the SSE4.2 code for AMD64 · 0c819b65
    Radu Berinde authored
    This commit improves the processing of the final few bytes in
    castagnoliSSE42: instead of processing one byte at a time, we use all
    versions of the CRC32 instruction to process 4 bytes, then 2, then 1.
    The difference is only noticeable for small "odd" sized buffers.
    
    We do the similar improvement for processing the first few bytes in
    the case of unaligned buffer.
    
    Fixing the test which was not actually verifying the results for
    misaligned buffers (WriteString was creating an internal copy which
    was aligned).
    
    Adding benchmarks for length 15 (aligned and misaligned), results
    below.
    
    name                          old time/op    new time/op    delta
    CastagnoliCrc15B-4              25.1ns ± 0%    22.1ns ± 1%  -12.14%
    CastagnoliCrc15BMisaligned-4    25.2ns ± 0%    22.9ns ± 1%   -9.03%
    CastagnoliCrc40B-4              23.1ns ± 0%    23.4ns ± 0%   +1.08%
    CastagnoliCrc1KB-4               127ns ± 0%     128ns ± 0%   +1.18%
    CastagnoliCrc4KB-4               462ns ± 0%     464ns ± 0%     ~
    CastagnoliCrc32KB-4             3.58µs ± 0%    3.60µs ± 0%   +0.58%
    
    name                          old speed      new speed      delta
    CastagnoliCrc15B-4             597MB/s ± 0%   679MB/s ± 1%  +13.77%
    CastagnoliCrc15BMisaligned-4   596MB/s ± 0%   655MB/s ± 1%   +9.94%
    CastagnoliCrc40B-4            1.73GB/s ± 0%  1.71GB/s ± 0%   -1.14%
    CastagnoliCrc1KB-4            8.01GB/s ± 0%  7.93GB/s ± 1%   -1.06%
    CastagnoliCrc4KB-4            8.86GB/s ± 0%  8.83GB/s ± 0%     ~
    CastagnoliCrc32KB-4           9.14GB/s ± 0%  9.09GB/s ± 0%   -0.58%
    
    Change-Id: I499e37af2241d28e3e5d522bbab836c1a718430a
    Reviewed-on: https://go-review.googlesource.com/24470Reviewed-by: default avatarKeith Randall <khr@golang.org>
    0c819b65
crc32_test.go 4.61 KB