From 115d66e756d019c08539147da89990854522235c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 2 Jan 2021 12:50:01 -0600 Subject: [PATCH] Use MSVC _byteswap intrinsics for SDL byteswapping functions This generates bswap on x86/x64 and rev on ARM --- include/SDL_endian.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/SDL_endian.h b/include/SDL_endian.h index 7fd735bcc..1398e05b9 100644 --- a/include/SDL_endian.h +++ b/include/SDL_endian.h @@ -30,6 +30,10 @@ #include "SDL_stdinc.h" +#ifdef _MSC_VER +#include +#endif + /** * \name The two types of endianness */ @@ -109,6 +113,9 @@ SDL_Swap16(Uint16 x) __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc"); return x; } +#elif defined(_MSC_VER) +#pragma intrinsic(_byteswap_ushort) +#define SDL_Swap16(x) _byteswap_ushort(x) #elif defined(__WATCOMC__) && defined(__386__) extern _inline Uint16 SDL_Swap16(Uint16); #pragma aux SDL_Swap16 = \ @@ -178,6 +185,9 @@ extern _inline Uint32 SDL_Swap32(Uint32); parm [eax] \ modify [eax]; #endif +#elif defined(_MSC_VER) +#pragma intrinsic(_byteswap_ulong) +#define SDL_Swap32(x) _byteswap_ulong(x) #else SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) @@ -213,6 +223,9 @@ SDL_Swap64(Uint64 x) __asm__("bswapq %0": "=r"(x):"0"(x)); return x; } +#elif defined(_MSC_VER) +#pragma intrinsic(_byteswap_uint64) +#define SDL_Swap64(x) _byteswap_uint64(x) #else SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x)