Patchwork util.h: backout 06badf7d10dc and 2c9645c0a582 for big-endian breakage

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 30, 2013, 7:43 p.m.
Message ID <bda823f990a263cf4a99.1380570201@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2681/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 30, 2013, 7:43 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1380569786 25200
#      Mon Sep 30 12:36:26 2013 -0700
# Node ID bda823f990a263cf4a99ecc598a325ffe38f592c
# Parent  2e537dd98304625dd6250c600aedce1ddb1cdf56
util.h: backout 06badf7d10dc and 2c9645c0a582 for big-endian breakage

getbe32 and putbe32 need to behave differently on big-endian and little-endian
systems. On big-endian ones, they should be roughly equivalent to the identity
function with a cast, but on little-endian ones they should reverse the order
of the bytes. That is achieved by the original definition, but
__builtin_bswap32 and _byteswap_ulong, as the names suggest, swap bytes around
unconditionally.

There was no measurable performance improvement, so there's no point adding
extra complexity with even more ifdefs for endianncess.
Matt Mackall - Sept. 30, 2013, 7:46 p.m.
On Mon, 2013-09-30 at 12:43 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1380569786 25200
> #      Mon Sep 30 12:36:26 2013 -0700
> # Node ID bda823f990a263cf4a99ecc598a325ffe38f592c
> # Parent  2e537dd98304625dd6250c600aedce1ddb1cdf56
> util.h: backout 06badf7d10dc and 2c9645c0a582 for big-endian breakage

Queued for default, thanks.

Patch

diff --git a/mercurial/util.h b/mercurial/util.h
--- a/mercurial/util.h
+++ b/mercurial/util.h
@@ -151,17 +151,6 @@ 
 #define inline __inline
 #endif
 
-#if defined(_MSC_VER) && (_MSC_VER >= 1300)
-static inline uint32_t getbe32(const char *c)
-{
-	return _byteswap_ulong(*(uint32_t *)c);
-}
-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-static inline uint32_t getbe32(const char *c)
-{
-	return __builtin_bswap32(*(uint32_t *)c);
-}
-#else
 static inline uint32_t getbe32(const char *c)
 {
 	const unsigned char *d = (const unsigned char *)c;
@@ -171,21 +160,7 @@ 
 		(d[2] << 8) |
 		(d[3]));
 }
-#endif
 
-#if defined(_MSC_VER) && (_MSC_VER >= 1300)
-static inline void putbe32(uint32_t x, char *c)
-{
-	x = _byteswap_ulong(x);
-	*(uint32_t *)c = x;
-}
-#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-static inline void putbe32(uint32_t x, char *c)
-{
-	x = __builtin_bswap32(x);
-	*(uint32_t *)c = x;
-}
-#else
 static inline void putbe32(uint32_t x, char *c)
 {
 	c[0] = (x >> 24) & 0xff;
@@ -193,6 +168,5 @@ 
 	c[2] = (x >> 8) & 0xff;
 	c[3] = (x) & 0xff;
 }
-#endif
 
 #endif /* _HG_UTIL_H_ */