summaryrefslogtreecommitdiff
path: root/include/SDL_endian.h
diff options
context:
space:
mode:
authorCameron Gutman <aicommander@gmail.com>2021-01-02 12:50:01 -0600
committerCameron Gutman <aicommander@gmail.com>2021-01-02 12:50:01 -0600
commitd0e62e09083117b73e006dd73b331b7358b35e94 (patch)
tree75656edbf157f221e8502f75f0dda04b285807b3 /include/SDL_endian.h
parentcf00a8221a216dd8fd7ffcabbb759693676d766f (diff)
downloadsdl-d0e62e09083117b73e006dd73b331b7358b35e94.tar.gz
Use MSVC _byteswap intrinsics for SDL byteswapping functions
This generates bswap on x86/x64 and rev on ARM
Diffstat (limited to 'include/SDL_endian.h')
-rw-r--r--include/SDL_endian.h13
1 files changed, 13 insertions, 0 deletions
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 <intrin.h>
+#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)