git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: linux@horizon.com
To: git@vger.kernel.org, junkio@cox.net
Cc: linux@horizon.com
Subject: Re: x86 asm SHA1 (draft)
Date: 24 Jun 2006 05:20:26 -0400	[thread overview]
Message-ID: <20060624092026.31029.qmail@science.horizon.com> (raw)
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.)

  parent reply	other threads:[~2006-06-24 13:02 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-23 17:18 x86 asm SHA1 (draft) linux
2006-06-24  0:18 ` Junio C Hamano
2006-06-24  1:22   ` linux
2006-06-24  7:03     ` Junio C Hamano
2006-06-24  7:59       ` From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001, [PATCH] Makefile: add framework to verify and bench sha1 implementations Junio C Hamano, Junio C Hamano
2006-06-24  9:29         ` From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001 " linux
2006-06-24 19:47           ` Junio C Hamano
2006-06-24  9:20       ` linux [this message]
2006-06-24 10:03       ` PPC SHA-1 Updates in "pu" Junio C Hamano
2006-06-24 18:55         ` Linus Torvalds
2006-06-24 20:21           ` Junio C Hamano
2006-06-24 20:42             ` Linus Torvalds
2006-06-24 23:59               ` Junio C Hamano
2006-06-25  1:02                 ` Petr Baudis
2006-06-25  1:40                   ` [PATCH] Git.pm build: Fix quoting and missing GIT-CFLAGS dependency Petr Baudis
2006-06-25  3:03                     ` Junio C Hamano
2006-06-25 15:21                       ` Petr Baudis
2006-06-26  6:48                         ` Junio C Hamano
2006-07-01 23:59                           ` [POOL] Who likes running Git without make install? Petr Baudis
2006-07-02  0:05                             ` Junio C Hamano
2006-07-02  0:08                             ` Junio C Hamano
2006-07-02 11:30                               ` Petr Baudis
2006-07-02 17:19                                 ` Junio C Hamano
2006-07-03  6:54                             ` [POLL] " Junio C Hamano
2006-07-03  7:58                               ` Petr Baudis
2006-07-03  8:08                                 ` Junio C Hamano
2006-07-03  8:17                                   ` Petr Baudis
2006-07-03  8:37                                     ` Johannes Schindelin
2006-06-25  1:24             ` PPC SHA-1 Updates in "pu" Petr Baudis
2006-06-25  3:57               ` Junio C Hamano
2006-06-25  9:34                 ` Petr Baudis
2006-06-25 10:07                   ` Johannes Schindelin
2006-06-25 10:20                     ` Petr Baudis
2006-06-25 10:48                       ` Junio C Hamano
2006-06-25 13:44                         ` Johannes Schindelin
2006-06-25 18:46                           ` Randal L. Schwartz
2006-06-25 23:23                             ` Johannes Schindelin
2006-06-26  1:51                               ` perl profiling (was: PPC SHA-1 Updates in "pu") Jeff King
2006-06-26  6:49                           ` PPC SHA-1 Updates in "pu" Junio C Hamano
2006-06-30  1:28             ` GIt.xs merge status Junio C Hamano
2006-06-30  5:08               ` Pavel Roskin
2006-06-30  7:18                 ` Git.xs " Junio C Hamano
2006-06-30  7:28                   ` Pavel Roskin
2006-06-30  9:53               ` GIt.xs " Johannes Schindelin
2006-06-30 10:26                 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060624092026.31029.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).