From c1aecf6e399febf2febf86503ae80a33b13e31e3 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Wed, 3 Sep 2008 15:28:24 +0200 Subject: -Codechange: Use builtins with MSVC for bitmath functions. --- src/core/bitmath_func.hpp | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index 27168e8..02e7a09 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -273,6 +273,16 @@ static FORCEINLINE T ROL(const T x, const uint8 n) return (T)(x << n | x >> (sizeof(x) * 8 - n)); } +#if defined(_MSC_VER) && _MSC_VER >= 1300 +#pragma intrinsic(_rotl) +/* Use the MSVC intrinsic to speed up the code. */ +template <> +static FORCEINLINE uint32 ROL(const uint32 x, const uint8 n) +{ + return _rotl(x, n); +} +#endif + /** * ROtate x Right by n * @@ -287,6 +297,16 @@ static FORCEINLINE T ROR(const T x, const uint8 n) return (T)(x >> n | x << (sizeof(x) * 8 - n)); } +#if defined(_MSC_VER) && _MSC_VER >= 1300 +#pragma intrinsic(_rotr) +/* Use the MSVC intrinsic to speed up the code. */ +template <> +static FORCEINLINE uint32 ROR(const uint32 x, const uint8 n) +{ + return _rotr(x, n); +} +#endif + /** * Do an operation for each set set bit in a value. * @@ -310,6 +330,12 @@ static FORCEINLINE T ROR(const T x, const uint8 n) * warnings if we don't cast those (why?) */ #define BSWAP32(x) ((uint32)Endian32_Swap(x)) #define BSWAP16(x) ((uint16)Endian16_Swap(x)) +#elif defined(_MSC_VER) && _MSC_VER >= 1300 + #pragma intrinsic(_byteswap_ulong) + #pragma intrinsic(_byteswap_ushort) + /* Use the MSVC intrinsics to speed up the code. */ + #define BSWAP32(x) ((uint32)_byteswap_ulong(x)) + #define BSWAP16(x) ((uint16)_byteswap_ushort(x)) #else /** * Perform a 32 bits endianness bitswap on x. @@ -335,6 +361,6 @@ static FORCEINLINE T ROR(const T x, const uint8 n) { return (x >> 8) | (x << 8); } -#endif /* __APPLE__ */ +#endif #endif /* BITMATH_FUNC_HPP */ -- 1.5.6.4