From: Jack Pappas Date: Sun, 14 Sep 2014 21:57:16 +0000 (-0400) Subject: Use compiler intrinsics for the ZSWAP32 macro to take advantage of hardware support... X-Git-Tag: 1.9.9-b1~931^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71992cb562c7432a2a836982cbc7764fa062af63;p=thirdparty%2Fzlib-ng.git Use compiler intrinsics for the ZSWAP32 macro to take advantage of hardware support when available. --- diff --git a/zutil.h b/zutil.h index 24ab06b1c..d6a06dc6b 100644 --- a/zutil.h +++ b/zutil.h @@ -246,8 +246,31 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} -/* Reverse the bytes in a 32-bit value */ +/* Reverse the bytes in a 32-bit value. Use compiler intrinsics when + possible to take advantage of hardware implementations. */ +#if defined(_WIN32) && (_MSC_VER >= 1300) +# include +# pragma intrinsic(_byteswap_ulong) +# define ZSWAP32(q) _byteswap_ulong(q) + +#elif defined(__Clang__) || (defined(__GNUC__) && + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))) +# define ZSWAP32(q) __builtin_bswap32(q) + +#elif defined(__GNUC__) && (__GNUC__ >= 2) && defined(__linux__) +# include +# define ZSWAP32(q) bswap_32(q) + +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +# include +# define ZSWAP32(q) bswap32(q) + +#elif defined(__INTEL_COMPILER) +# define ZSWAP32(q) _bswap(q) + +#else #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) +#endif /* ZSWAP32 */ #endif /* ZUTIL_H */