SDL_net: Assume that unaligned access is not allowed unless we know otherwise

From e08356dc3b40b2b92e5b72538ef3dc99d91e99a6 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Fri, 29 Oct 2021 13:13:34 +0100
Subject: [PATCH] Assume that unaligned access is not allowed unless we know
 otherwise

x86 architecturally allows unaligned access, but this is unusual:
other CPU architectures generally do not. The safe assumption is that
unaligned access on an unknown CPU architecture will either be very
slow, or not work at all.

Instead of assuming that unknown architectures are like x86, let's
assume they are like ARM. This is true for riscv64, for example[1].

x86 is the outlier here, and is the most likely to be extensively tested
by SDL_net maintainers, so specifically detect x86 (using the predefined
macros from gcc, clang and MSVC) and continue to use unaligned accesses
there.

[1] https://wiki.debian.org/ArchitectureSpecificsMemo#Alignment

Signed-off-by: Simon McVittie <smcv@debian.org>
---
 SDL_net.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/SDL_net.h b/SDL_net.h
index fd1860c..4ffc7cf 100644
--- a/SDL_net.h
+++ b/SDL_net.h
@@ -374,12 +374,12 @@ extern DECLSPEC const char * SDLCALL SDLNet_GetError(void);
 /* Inline functions to read/write network data                         */
 /***********************************************************************/
 
-/* Warning, some systems have data access alignment restrictions */
-#if defined(sparc) || defined(mips) || defined(__arm__)
-#define SDL_DATA_ALIGNED    1
+/* Warning, most systems have data access alignment restrictions */
+#if defined(__i386__) || defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86) || defined(_M_AMD64)
+#define SDL_DATA_ALIGNED    0
 #endif
 #ifndef SDL_DATA_ALIGNED
-#define SDL_DATA_ALIGNED    0
+#define SDL_DATA_ALIGNED    1
 #endif
 
 /* Write a 16/32-bit value to network packet buffer */