[Mesa-dev] [PATCH] util: import sha1 implementation from OpenBSD

Vladislav Egorov vegorov180 at gmail.com
Fri Jan 13 19:22:55 UTC 2017


13.01.2017 19:51, Emil Velikov пишет:
> From: Emil Velikov <emil.velikov at collabora.com>
>
> At the moment we support 5+ different implementations each with varying
> amount of bugs - from thread safely problems [1], to outright broken
> implementation(s) [2]
>
> In order to accommodate these we have 150+ lines of configure script and
> extra two configure toggles. Whist an actual implementation being
> ~200loc and our current compat wrapping ~250.
>
> Let's not forget that different people use different code paths, thus
> effectively makes it harder to test and debug since the default
> implementation is automatically detected.
>
> To minimise all these lovely experiences, import the "100% Public
> Domain" OpenBSD sha1 implementation. Clearly document any changes needed
> to get building correctly, since many/most of those can be upstreamed
> making future syncs easier.

It can hurt performance. OpenSSL implementation is optimized for all 
thinkable architectures and it will use hardware SHA-1 instructions on 
newer CPUs. From 
https://github.com/openssl/openssl/blob/master/crypto/sha/asm/sha1-x86_64.pl 
:

 > Current performance is summarized in following table. Numbers are
 > CPU clock cycles spent to process single byte (less is better).
 >
 >        x86_64        SSSE3        AVX[2]
 > P4        9.05        -
 > Opteron    6.26        -
 > Core2        6.55        6.05/+8%    -
 > Westmere    6.73        5.30/+27%    -
 > Sandy Bridge    7.70        6.10/+26%    4.99/+54%
 > Ivy Bridge    6.06        4.67/+30%    4.60/+32%
 > Haswell    5.45        4.15/+31%    3.57/+53%
 > Skylake    5.18        4.06/+28%    3.54/+46%
 > Bulldozer    9.11        5.95/+53%
 > VIA Nano    9.32        7.15/+30%
 > Atom        10.3        9.17/+12%
 > Silvermont    13.1(*)        9.37/+40%
 > Goldmont    8.13        6.42/+27%    1.70/+380%(**)

Quick benchmark on my Haswell of the OpenBSD implementation compiled 
with GCC5 -O2: ~8 cycles per byte on 32-bit, ~7 cycles per byte on 
64-bit. But Haswell is a very powerful CPU, on weaker CPUs the 
difference would be probably larger, especially on new CPUs that have 
SHA instruction set.



More information about the mesa-dev mailing list