Skip to contentSkip to conversation

Use faster byte swapping when compiling with MSVC

PATCH In review Sebastian Schuberth 5 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use faster byte swapping when compiling with MSVC

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.

---
 compat/bswap.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
compat/bswap.h +10 -0
index 5cc4acb..279e0b4 100644
@@ -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)
Signature · 1 line
1.6.5.rc2.13.g1be2
#1 lore raw
Quoted 5 lines · Sebastian Schuberth

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.

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?

Quoted 27 lines
---
 compat/bswap.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
compat/bswap.h +10 -0
index 5cc4acb..279e0b4 100644
@@ -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)
Signature · 1 line
1.6.5.rc2.13.g1be2
#2 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 5 lines

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.

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.

Signature · 1 line
Sebastian Schuberth
#3 lore raw

Hi,

Quoted 8 lines · Sebastian Schuberth
Quoted 6 lines · Junio C Hamano
Quoted 5 lines

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.

Quoted 8 lines
Quoted 3 lines

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

#4 lore raw
Quoted 12 lines · Johannes Schindelin
Quoted 4 lines

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).

Quoted 2 lines

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.

#5 lore raw
In reply to Sebastian Schuberth

compat/bswap.h static inline uint32_t default_swab32(uint32_t val) · line 37

Quoted 13 lines · 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.

compat/bswap.h +7 -0
+#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

#6 lore raw
Quoted 3 lines · Ludvig Strigeus

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

Signature · 1 line
Erik "kusma" Faye-Lund