git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Linus' sha1 is much faster!

From
Steven Noonan <steven@uplinklabs.net>
Date
Aug 17, 2009, 21:43 UTC
Message-ID
<f488382f0908171443n7fa92342v1ac12f52a17fd048@mail.gmail.com>
In-Reply-To
<alpine.LFD.2.01.0908170852320.3162@localhost.localdomain>

On Mon, Aug 17, 2009 at 9:22 AM, Linus Torvalds<torvalds@linux-foundation.org> wrote:

Show 13 quoted lines
>
>
> On Mon, 17 Aug 2009, Steven Noonan wrote:
>>
>> Interesting. I compared Linus' implementation to the public domain one
>> by Steve Reid[1]
>
> You _really_ need to talk about what kind of environment you have.
>
> There are three major issues:
>  - Netburst vs non-netburst
>  - 32-bit vs 64-bit
>  - compiler version

Right. I'm running a Core 2 "Merom" 2.33GHz. The code was compiled for x86_64 with GCC 4.2.1. I didn't _expect_ it to compile for x86_64, but apparently the version of GCC that ships with Xcode 3.2 defaults to compiling 64-bit code on machines that are capable of running it.

Show 27 quoted lines
>
> Steve Reid's code looks great, but the way it is coded, gcc makes a mess
> of it, which is exactly what my SHA1 tries to avoid.
>
> [ In contrast, gcc does very well on just about _any_ straightforward
>  unrolled SHA1 C code if the target architecture is something like PPC or
>  ia64 that has enough registers to keep it all in registers.
>
>  I haven't really tested other compilers - a less aggressive compiler
>  would actually do _better_ on SHA1, because the problem with gcc is that
>  it turns the whole temporary 16-entry word array into register accesses,
>  and tries to do register allocation on that _array_.
>
>  That is wonderful for the above-mentioned PPC and IA64, but it makes gcc
>  create totally crazy code when there aren't enough registers, and then
>  gcc starts spilling randomly (ie it starts spilling a-e etc). This is
>  why the compiler and version matters so much. ]
>
>> (average of 5 runs)
>> Linus' sha1: 283MB/s
>> Steve Reid's sha1: 305MB/s
>
> So I get very different results:
>
>        #             TIME[s] SPEED[MB/s]
>        Reid            2.742       222.6
>        linus           1.464         417
Added -m32:
Steve Reid: 156MB/s
Linus: 209MB/s
So on x86, your code really kicks butt.
Show 6 quoted lines
> this is Intel Nehalem, but compiled for 32-bit mode (which is the more
> challenging one because x86-32 only has 7 general-purpose registers), and
> with gcc-4.4.0.
>
>                        Linus
>
Previous: Linus TorvaldsNext: Giuseppe Scrivano
Message 20 of 21 in “Linus' sha1 is much faster!”
  1. Pádraig BradyAug 14, 2009
  2. Bryan DonlanAug 15, 2009
  3. John TapsellAug 15, 2009
  4. Linus TorvaldsAug 15, 2009
  5. Linus TorvaldsAug 15, 2009
  6. Nicolas PitreAug 17, 2009
  7. Pádraig BradyAug 26, 2009
  8. galtApr 20, 2017
  9. galtApr 20, 2017
  10. Andreas EricssonAug 17, 2009
  11. Theodore TsoAug 16, 2009
  12. Giuseppe ScrivanoAug 16, 2009
  13. Linus TorvaldsAug 16, 2009
  14. Giuseppe ScrivanoAug 16, 2009
  15. Linus TorvaldsAug 16, 2009
  16. Pádraig BradyAug 17, 2009
  17. Giuseppe ScrivanoAug 17, 2009
  18. Steven NoonanAug 17, 2009
  19. Linus TorvaldsAug 17, 2009
  20. Steven NoonanAug 17, 2009
  21. Giuseppe ScrivanoAug 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.