# [PATCH] compat/bswap.h: don't assume MSVC is little-endian

3 messages from 2020-11-11 to 2020-11-11. Participants: Daniel Gurney, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/54618

## Daniel Gurney, 2020-11-11 08:32

Subject: [PATCH] compat/bswap.h: don't assume MSVC is little-endian
Message-ID: <20201111083227.605518-1-dgurney99@gmail.com>
URL: https://gitlist.dev/e/20201111083227.605518-1-dgurney99%40gmail.com

```
In 1af265f0 (compat/bswap.h: simplify MSVC endianness
detection, 2020-11-08) we attempted to simplify code by assuming MSVC
builds will be for little-endian machines, since only unusably old
versions of MSVC supported big-endian MIPS and m68k architectures.

However, it's possible that MSVC could be ported to build for a
big-endian architecture again, so the simplification wasn't as
future-proof as hoped.

So let's go back to the old way of detecting MSVC, and then checking
architecture from a list of little-endian architecture macros.

Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat
it as little-endian.

Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
Helped-by: Jeff King <peff@peff.net>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Daniel Gurney <dgurney99@gmail.com>
---
 compat/bswap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/bswap.h b/compat/bswap.h
index 72f225eaa8..512f6f4b99 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -74,7 +74,7 @@ static inline uint64_t git_bswap64(uint64_t x)
 }
 #endif
 
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
 
 #include <stdlib.h>
 
-- 
2.29.2


```

## Johannes Schindelin, 2020-11-11 16:23

Subject: Re: [PATCH] compat/bswap.h: don't assume MSVC is little-endian
Message-ID: <nycvar.QRO.7.76.6.2011111723050.18437@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.2011111723050.18437%40tvgsbejvaqbjf.bet
In-Reply-To: <20201111083227.605518-1-dgurney99@gmail.com>

```
Hi Daniel,

On Wed, 11 Nov 2020, Daniel Gurney wrote:

> In 1af265f0 (compat/bswap.h: simplify MSVC endianness
> detection, 2020-11-08) we attempted to simplify code by assuming MSVC
> builds will be for little-endian machines, since only unusably old
> versions of MSVC supported big-endian MIPS and m68k architectures.
>
> However, it's possible that MSVC could be ported to build for a
> big-endian architecture again, so the simplification wasn't as
> future-proof as hoped.
>
> So let's go back to the old way of detecting MSVC, and then checking
> architecture from a list of little-endian architecture macros.
>
> Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat
> it as little-endian.
>
> Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
> Helped-by: Jeff King <peff@peff.net>
> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Daniel Gurney <dgurney99@gmail.com>

ACK!

Thank you so much,
Dscho

> ---
>  compat/bswap.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/bswap.h b/compat/bswap.h
> index 72f225eaa8..512f6f4b99 100644
> --- a/compat/bswap.h
> +++ b/compat/bswap.h
> @@ -74,7 +74,7 @@ static inline uint64_t git_bswap64(uint64_t x)
>  }
>  #endif
>
> -#elif defined(_MSC_VER)
> +#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
>
>  #include <stdlib.h>
>
> --
> 2.29.2
>
>

```

## Junio C Hamano, 2020-11-11 16:40

Subject: Re: [PATCH] compat/bswap.h: don't assume MSVC is little-endian
Message-ID: <xmqqo8k34zko.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqo8k34zko.fsf%40gitster.c.googlers.com
In-Reply-To: <nycvar.QRO.7.76.6.2011111723050.18437@tvgsbejvaqbjf.bet>

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

>> ...
>> So let's go back to the old way of detecting MSVC, and then checking
>> architecture from a list of little-endian architecture macros.
>>
>> Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat
>> it as little-endian.
>>
>> Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
>> Helped-by: Jeff King <peff@peff.net>
>> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
>> Helped-by: Junio C Hamano <gitster@pobox.com>
>> Signed-off-by: Daniel Gurney <dgurney99@gmail.com>
>
> ACK!
>
> Thank you so much,
> Dscho

Thanks, all.

```
