Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sebastian Schuberth <sschuberth@gmail.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	msysGit <msysgit@googlegroups.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Nicolas Pitre <nico@cam.org>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] block-sha1: Windows declares ntohl() in winsock2.h
Date: Tue, 18 Aug 2009 04:07:31 -0700	[thread overview]
Message-ID: <7vtz05idn0.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <4A8A8661.5060908@gmail.com> (Sebastian Schuberth's message of "Tue\, 18 Aug 2009 12\:45\:53 +0200")

Sebastian Schuberth <sschuberth@gmail.com> writes:

> As ntohl()/htonl() are function calls (that internally do shifts), I
> doubt they're faster than the shift macros, though I haven't measured
> it. However, I do not suggest to go for the macros on Windows/Intel,
> but to apply the following patch on top of your patch:

Your proposed commit log message makes it sound as if this change is
limited to Windows, but it is not protected with "#ifdef WIN32"; the
change should be applicable to non-windows but the message is misleading.

It should help any i386/amd64 platform whose ntohl()/htonl() is crappy, as
long as __builtin_bswap32() is supported by the compiler.  And it should
not harm other platforms, nor i386/amd64 whose ntohl()/htonl() are sane.
As i386/amd64 part of block-sha1/sha1.c has gcc dependency already, I
think it would be safe to assume __builtin_bswap32() is available.

But I'd want an Ack/Nack from the original authors (Cc'ed).

It seems that your patch is linewrapped, so please be careful _if_ it
needs to be modified and resent (if this version gets trivially acked I
can fix it up when applying and in such a case there is no need to
resend).

> From: Sebastian Schuberth <sschuberth@gmail.com>
> Date: Tue, 18 Aug 2009 12:33:35 +0200
> Subject: [PATCH] block-sha1: On Intel, use bswap built-in in favor of
> ntohl()/htonl()
>
> On Windows/Intel, ntohl()/htonl() are function calls that do shifts to
> swap the
> byte order. Using the native bswap instruction boths gets rid of the
> shifts and
> the function call overhead to gain some performance.
>
> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
> ---
>  block-sha1/sha1.c |   15 ++++++++++-----
>  1 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
> index f2830c0..07f2937 100644
> --- a/block-sha1/sha1.c
> +++ b/block-sha1/sha1.c
> @@ -66,15 +66,20 @@
>
>  /*
>   * Performance might be improved if the CPU architecture is OK with
> - * unaligned 32-bit loads and a fast ntohl() is available.
> + * unaligned 32-bit loads and a fast ntohl() is available. On Intel,
> + * use the bswap built-in to get rid of the function call overhead.
>   * Otherwise fall back to byte loads and shifts which is portable,
>   * and is faster on architectures with memory alignment issues.
>   */
>
> -#if defined(__i386__) || defined(__x86_64__) || \
> -    defined(__ppc__) || defined(__ppc64__) || \
> -    defined(__powerpc__) || defined(__powerpc64__) || \
> -    defined(__s390__) || defined(__s390x__)
> +#if defined(__i386__) || defined(__x86_64__)
> +
> +#define get_be32(p)	__builtin_bswap32(*(unsigned int *)(p))
> +#define put_be32(p, v)	do { *(unsigned int *)(p) =
> __builtin_bswap32(v); } while (0)
> +
> +#elif defined(__ppc__) || defined(__ppc64__) || \
> +      defined(__powerpc__) || defined(__powerpc64__) || \
> +      defined(__s390__) || defined(__s390x__)
>
>  #define get_be32(p)	ntohl(*(unsigned int *)(p))
>  #define put_be32(p, v)	do { *(unsigned int *)(p) = htonl(v); } while (0)
> -- 
> 1.6.4.169.g64d5.dirty

  reply	other threads:[~2009-08-18 11:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-18  7:15 [PATCH] block-sha1: Windows declares ntohl() in winsock2.h Johannes Sixt
2009-08-18 10:45 ` Sebastian Schuberth
2009-08-18 11:07   ` Junio C Hamano [this message]
2009-08-18 11:28     ` Sebastian Schuberth
2009-08-18 12:56   ` Artur Skawina
2009-08-18 13:17     ` Sebastian Schuberth
2009-08-18 13:39       ` Junio C Hamano
2009-08-18 15:40         ` Linus Torvalds
2009-08-18 16:08           ` Linus Torvalds
2009-08-18 16:23             ` Sebastian Schuberth
2009-08-18 16:43               ` Junio C Hamano
2009-08-18 16:30         ` Nicolas Pitre
2009-08-18 16:43           ` Nicolas Pitre
2009-08-18 16:50             ` Junio C Hamano
2009-08-18 18:01               ` Nicolas Pitre
2009-08-18 19:00                 ` Junio C Hamano
2009-08-18 19:22                   ` Nicolas Pitre
2009-08-18 19:26                     ` [PATCH] make sure byte swapping is optimal for git Nicolas Pitre
2009-08-18 19:37                     ` [PATCH] block-sha1: guard gcc extensions with __GNUC__ Nicolas Pitre
2009-08-18 19:40                   ` [PATCH] block-sha1: Windows declares ntohl() in winsock2.h Junio C Hamano
2009-08-18 19:56                   ` Brandon Casey
2009-08-18 20:10                     ` Nicolas Pitre
2009-08-18 20:25                       ` Linus Torvalds
2009-08-18 20:29                       ` Brandon Casey
2009-08-20  2:26                     ` Nicolas Pitre
2009-08-20  2:30                       ` Linus Torvalds
2009-08-20  2:45                       ` Brandon Casey
2009-08-18 16:59             ` Sebastian Schuberth
2009-08-18 17:05               ` Junio C Hamano
2009-08-18 18:16                 ` Nicolas Pitre
2009-08-18 20:17                   ` Junio C Hamano
2009-08-18 20:30                     ` Junio C Hamano
2009-08-18 20:49                       ` Nicolas Pitre
2009-08-18 18:10               ` Nicolas Pitre

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

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

  git send-email \
    --in-reply-to=7vtz05idn0.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=msysgit@googlegroups.com \
    --cc=nico@cam.org \
    --cc=sschuberth@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox