Mercurial > hg-stable
changeset 19744:06badf7d10dc
util.h: getbe32() and putbe32() use intrinsic function to improve performance
Refer to https://bugzilla.mozilla.org/show_bug.cgi?id=351557. It can improve
byte-swapping performance by intrinsic function.
author | Wei, Elson <elson.wei@gmail.com> |
---|---|
date | Sat, 14 Sep 2013 11:22:34 +0800 |
parents | fdd41257def8 |
children | 22a70f31e3e9 |
files | mercurial/util.h |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.h Fri Sep 06 13:30:58 2013 +0400 +++ b/mercurial/util.h Sat Sep 14 11:22:34 2013 +0800 @@ -151,6 +151,17 @@ #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 GCC_VERSION >= 403 +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; @@ -160,7 +171,21 @@ (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 GCC_VERSION >= 403 +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; @@ -168,5 +193,6 @@ c[2] = (x >> 8) & 0xff; c[3] = (x) & 0xff; } +#endif #endif /* _HG_UTIL_H_ */