# [PATCH] Use faster byte swapping when compiling with MSVC

7 messages from 2009-10-19 to 2009-10-20. Participants: Sebastian Schuberth, Junio C Hamano, Johannes Schindelin, Ludvig Strigeus, Erik Faye-Lund.
Thread: https://gitlist.dev/t/21282

## Sebastian Schuberth, 2009-10-19 16:37

Subject: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <hbi4mt$tjt$1@ger.gmane.org>
URL: https://gitlist.dev/e/hbi4mt%24tjt%241%40ger.gmane.org

```
When compiling with MSVC on x86-compatible, use an intrinsic for byte swapping.
In contrast to the GCC path, we do not prefer inline assembly here as it is not
supported for the x64 platform.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 compat/bswap.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/compat/bswap.h b/compat/bswap.h
index 5cc4acb..279e0b4 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -28,6 +28,16 @@ static inline uint32_t default_swab32(uint32_t val)
 	} \
 	__res; })
 
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
+
+#include <stdlib.h>
+
+#define bswap32(x) _byteswap_ulong(x)
+
+#endif
+
+#ifdef bswap32
+
 #undef ntohl
 #undef htonl
 #define ntohl(x) bswap32(x)
-- 
1.6.5.rc2.13.g1be2

```

## Junio C Hamano, 2009-10-20 07:04

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <7vzl7mr1f5.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzl7mr1f5.fsf%40alter.siamese.dyndns.org
In-Reply-To: <hbi4mt$tjt$1@ger.gmane.org>

```
Sebastian Schuberth <sschuberth@gmail.com> writes:

> When compiling with MSVC on x86-compatible, use an intrinsic for byte swapping.
> In contrast to the GCC path, we do not prefer inline assembly here as it is not
> supported for the x64 platform.
>
> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>

Unlike the other one this is not Acked by Marius, Dscho, or J6t; should I
pick this up myself, or should I wait to be fed by one of msysgit people?


> ---
>  compat/bswap.h |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/compat/bswap.h b/compat/bswap.h
> index 5cc4acb..279e0b4 100644
> --- a/compat/bswap.h
> +++ b/compat/bswap.h
> @@ -28,6 +28,16 @@ static inline uint32_t default_swab32(uint32_t val)
>  	} \
>  	__res; })
>  
> +#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
> +
> +#include <stdlib.h>
> +
> +#define bswap32(x) _byteswap_ulong(x)
> +
> +#endif
> +
> +#ifdef bswap32
> +
>  #undef ntohl
>  #undef htonl
>  #define ntohl(x) bswap32(x)
> -- 
> 1.6.5.rc2.13.g1be2

```

## Sebastian Schuberth, 2009-10-20 08:56

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <bdca99240910200156x48511478w9eaa2239eb8342b4@mail.gmail.com>
URL: https://gitlist.dev/e/bdca99240910200156x48511478w9eaa2239eb8342b4%40mail.gmail.com
In-Reply-To: <7vzl7mr1f5.fsf@alter.siamese.dyndns.org>

```
On Tue, Oct 20, 2009 at 09:04, Junio C Hamano <gitster@pobox.com> wrote:

>> When compiling with MSVC on x86-compatible, use an intrinsic for byte swapping.
>> In contrast to the GCC path, we do not prefer inline assembly here as it is not
>> supported for the x64 platform.
>>
>> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
>
> Unlike the other one this is not Acked by Marius, Dscho, or J6t; should I
> pick this up myself, or should I wait to be fed by one of msysgit people?

Well, in fact I am one of the msysgit poeple, although I mostly worked
on the installer until now. In general, I like my patches to be
reviewed, but this one is rather uncritical, I guess. So it's up to
you, Junio, I'm perfectly OK with waiting for an ACK.

-- 
Sebastian Schuberth

```

## Johannes Schindelin, 2009-10-20 09:53

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <alpine.DEB.1.00.0910201149020.4985@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0910201149020.4985%40pacific.mpi-cbg.de
In-Reply-To: <bdca99240910200156x48511478w9eaa2239eb8342b4@mail.gmail.com>

```
Hi,

On Tue, 20 Oct 2009, Sebastian Schuberth wrote:

> On Tue, Oct 20, 2009 at 09:04, Junio C Hamano <gitster@pobox.com> wrote:
> 
> >> When compiling with MSVC on x86-compatible, use an intrinsic for byte 
> >> swapping. In contrast to the GCC path, we do not prefer inline 
> >> assembly here as it is not supported for the x64 platform.
> >>
> >> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
> >
> > Unlike the other one this is not Acked by Marius, Dscho, or J6t; 
> > should I pick this up myself, or should I wait to be fed by one of 
> > msysgit people?
> 
> Well, in fact I am one of the msysgit poeple, although I mostly worked 
> on the installer until now. In general, I like my patches to be 
> reviewed, but this one is rather uncritical, I guess. So it's up to you, 
> Junio, I'm perfectly OK with waiting for an ACK.

Apart from the fact that I do not have MSVC (and I don't want it, either), 
there is another strong reason why I think Sebastian does not need ACKs or 
SOBs on MSVC patches: he has plenty of experience as a maintainer of a 
rather big (commercial) software that has to compile on Windows, MacOSX 
and several Unix-type OSes (and it is known that Sebastian is a Windows 
guy).

So I would trust Sebastian's patches (at least when it comes to MSVC) 
without even reviewing them.

Ciao,
Dscho

```

## Ludvig Strigeus, 2009-10-20 12:20

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <loom.20091020T141138-782@post.gmane.org>
URL: https://gitlist.dev/e/loom.20091020T141138-782%40post.gmane.org
In-Reply-To: <hbi4mt$tjt$1@ger.gmane.org>

```
Sebastian Schuberth <sschuberth <at> gmail.com> writes:
> 
> When compiling with MSVC on x86-compatible, use an intrinsic for byte swapping.
> In contrast to the GCC path, we do not prefer inline assembly here as it is not
> supported for the x64 platform.
> 
>  
> +#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
> +
> +#include <stdlib.h>
> +
> +#define bswap32(x) _byteswap_ulong(x)
> +
> +#endif

unsigned long (as used by _byteswap_ulong) is 64 bits on x64, right? Then it
doesn't make sense to use _byteswap_ulong to swap 32-bit quantities (assuming
that's what bswap32 does) would it?

/Ludde

```

## Erik Faye-Lund, 2009-10-20 12:44

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <40aa078e0910200544i3d8aadc1ud62cf62a6964dd5@mail.gmail.com>
URL: https://gitlist.dev/e/40aa078e0910200544i3d8aadc1ud62cf62a6964dd5%40mail.gmail.com
In-Reply-To: <loom.20091020T141138-782@post.gmane.org>

```
On Tue, Oct 20, 2009 at 2:20 PM, Ludvig Strigeus <ludde@spotify.com> wrote:
> unsigned long (as used by _byteswap_ulong) is 64 bits on x64, right? Then it
> doesn't make sense to use _byteswap_ulong to swap 32-bit quantities (assuming
> that's what bswap32 does) would it?

No, unsigned long is 32bit on x64 on Windows.

--->8---
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  printf("sizeof(void *) = %d\n", sizeof(void *));
  printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
  return 0;
}
--->8---
sizeof(void *) = 8
sizeof(unsigned long) = 4

-- 
Erik "kusma" Faye-Lund

```

## Junio C Hamano, 2009-10-20 16:55

Subject: Re: [PATCH] Use faster byte swapping when compiling with MSVC
Message-ID: <7v4opuovhu.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4opuovhu.fsf%40alter.siamese.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0910201149020.4985@pacific.mpi-cbg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> Well, in fact I am one of the msysgit poeple, although I mostly worked 
>> on the installer until now. In general, I like my patches to be 
>> reviewed, but this one is rather uncritical, I guess. So it's up to you, 
>> Junio, I'm perfectly OK with waiting for an ACK.
>
> Apart from the fact that I do not have MSVC (and I don't want it, either), 
> there is another strong reason why I think Sebastian does not need ACKs or 
> SOBs on MSVC patches: he has plenty of experience as a maintainer of a 
> rather big (commercial) software that has to compile on Windows, MacOSX 
> and several Unix-type OSes (and it is known that Sebastian is a Windows 
> guy).
>
> So I would trust Sebastian's patches (at least when it comes to MSVC) 
> without even reviewing them.

I very appreciate a strong Ack in a specific area like this.  I do skim
msysgit list from time to time, and in retrospect I realize I _could_ have
recognized Sebastian's name but somehow it didn't click.

I guess I should apply both patches to 'master', then.  Thanks.

```
