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

Re: x86 asm SHA1 (draft)

From
Llinux@horizon.com <linux@horizon.com>
Date
Jun 24, 2006, 09:20 UTC
Message-ID
<20060624092026.31029.qmail@science.horizon.com>
In-Reply-To
<7vfyhv11ej.fsf@assigned-by-dhcp.cox.net>
> OK.  I somehow got an impression that your two versions had
> quite different performance characteristics on G4 and G5 and
> there was a real choice.  If they are between a few per-cent,
> then I agree it is not worth doing at all.
My apologies for being unclear.

The place where a noticeable (if not disastrous) difference can appear is x86, which has a lot more models with "interesting" performance characteristics. In particular, Intel is fond of building CPUs with a very small "sweet spot".

The openssl SHA1 code had to be reworked to not suck on a P4, with the resultant performance change:

# compared with original compared with Intel cc # assembler impl. generated code # Pentium -16% +48% # PIII/AMD +8% +16% # P4 +85%(!) +45%

The original code had the most popular round (what I call ROUND_MIX(F2,...))) implemented as follows, with single-uop instructions (no load+op) scheduled for the Pentium pipeline: (A..E are working variables, S and T are temps)

	movl    16(%esp),S	U  \
        movl    24(%esp),T	 V  \
        xorl    S,T		U    \
        movl    48(%esp),S	 V    > "MIX", pentium-optimized
        xorl    S,T		U    /
        movl    4(%esp),S	 V  /
        xorl    S,T		U  /
        movl	B,S		 V
	roll	$1,T		U	Rotate of mix (SHA0 -> SHA1 fix)
	xor	C,S		 V
	mov	T,16(%esp)	U	Store back W[i]
	xor	D,S		 V	Finish computing F(B,C,D) = B^C^D
	lea	K(T,E),E	U	Add K and W[i] to E
	mov	A,T		 V
	roll	$5,T		UV
	rorl	$1,B		U
	add	S,E		 V
	rorl	$1,B		U
	add	T,E		 V
While the P4-optimized version goes:
	movl	B,S
	movl	16(%esp),T
	rorl	$2,B
	xorl	24(%esp),T
	xorl	C,S
	xorl	48(%esp),T
	xorl	D,S		This is F(B,C,D) = B^C^D
	xorl	4(%esp),T
	roll	$1,T		Rotate of mix (SHA0 -> SHA1 fix)
	addl	S,E
	movl	T,16(%esp)
	movl	A,S
	roll	$5,S
	lea	K(E,T),E
	add	S,E

(The original code actually rotates the working variables around 6 registers, not 5, but I've rearranged the last couple of instructions to rotate around 5.)

Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 45 in “x86 asm SHA1 (draft)”
  1. linux@horizon.comJun 23, 2006
  2. Junio C HamanoJun 24, 2006
  3. linux@horizon.comJun 24, 2006
  4. Junio C HamanoJun 24, 2006
  5. From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001Junio C Hamano, Jun 24, 2006
  6. linux@horizon.comJun 24, 2006
  7. Junio C HamanoJun 24, 2006
  8. linux@horizon.comJun 24, 2006
  9. PPC SHA-1 Updates in "pu"Junio C Hamano, Jun 24, 2006
  10. Linus TorvaldsJun 24, 2006
  11. Junio C HamanoJun 24, 2006
  12. Linus TorvaldsJun 24, 2006
  13. Junio C HamanoJun 24, 2006
  14. Petr BaudisJun 25, 2006
  15. Git.pm build: Fix quoting and missing GIT-CFLAGS dependencyPetr Baudis, Jun 25, 2006
  16. Junio C HamanoJun 25, 2006
  17. Petr BaudisJun 25, 2006
  18. Junio C HamanoJun 26, 2006
  19. [POOL] Who likes running Git without make install?Petr Baudis, Jul 1, 2006
  20. Junio C HamanoJul 2, 2006
  21. Junio C HamanoJul 2, 2006
  22. Petr BaudisJul 2, 2006
  23. Junio C HamanoJul 2, 2006
  24. Junio C HamanoJul 3, 2006
  25. Petr BaudisJul 3, 2006
  26. Junio C HamanoJul 3, 2006
  27. Petr BaudisJul 3, 2006
  28. Johannes SchindelinJul 3, 2006
  29. Petr BaudisJun 25, 2006
  30. Junio C HamanoJun 25, 2006
  31. Petr BaudisJun 25, 2006
  32. Johannes SchindelinJun 25, 2006
  33. Petr BaudisJun 25, 2006
  34. Junio C HamanoJun 25, 2006
  35. Johannes SchindelinJun 25, 2006
  36. Randal L. SchwartzJun 25, 2006
  37. Johannes SchindelinJun 25, 2006
  38. perl profiling (was: PPC SHA-1 Updates in "pu")Jeff King, Jun 26, 2006
  39. Junio C HamanoJun 26, 2006
  40. GIt.xs merge statusJunio C Hamano, Jun 30, 2006
  41. Pavel RoskinJun 30, 2006
  42. Junio C HamanoJun 30, 2006
  43. Pavel RoskinJun 30, 2006
  44. Johannes SchindelinJun 30, 2006
  45. Junio C HamanoJun 30, 2006

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.