fix: allow builtins for all archs (#4756)

* fix: allow builtins for all archs

* fix: typo
This commit is contained in:
Alex R 2021-09-17 02:34:49 +02:00 committed by GitHub
parent ebdfd0e175
commit eb8f332c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 20 deletions

View File

@ -91,25 +91,36 @@ extern "C" {
/** /**
* \file SDL_endian.h * \file SDL_endian.h
*/ */
#if (_SDL_HAS_BUILTIN(__builtin_bswap16)) || \
/* various modern compilers may have builtin swap */
#define HAS_BUILTIN_BSWAP16 (_SDL_HAS_BUILTIN(__builtin_bswap16)) || \
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
#define HAS_BUILTIN_BSWAP32 (_SDL_HAS_BUILTIN(__builtin_bswap32)) || \
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
#define HAS_BUILTIN_BSWAP64 (_SDL_HAS_BUILTIN(__builtin_bswap64)) || \
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
/* this one is broken */
#define HAS_BROKEN_BSWAP (defined(__GNUC__) && \
(__GNUC__ == 2 && __GNUC_MINOR__ <= 95))
#if HAS_BUILTIN_BSWAP16
#define SDL_Swap16(x) __builtin_bswap16(x) #define SDL_Swap16(x) __builtin_bswap16(x)
#elif defined(__GNUC__) && defined(__i386__) && \ #elif defined(__i386__) && !HAS_BROKEN_BSWAP
!(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
SDL_FORCE_INLINE Uint16 SDL_FORCE_INLINE Uint16
SDL_Swap16(Uint16 x) SDL_Swap16(Uint16 x)
{ {
__asm__("xchgb %b0,%h0": "=q"(x):"0"(x)); __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
return x; return x;
} }
#elif defined(__GNUC__) && defined(__x86_64__) #elif defined(__x86_64__)
SDL_FORCE_INLINE Uint16 SDL_FORCE_INLINE Uint16
SDL_Swap16(Uint16 x) SDL_Swap16(Uint16 x)
{ {
__asm__("xchgb %b0,%h0": "=Q"(x):"0"(x)); __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
return x; return x;
} }
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) #elif (defined(__powerpc__) || defined(__ppc__))
SDL_FORCE_INLINE Uint16 SDL_FORCE_INLINE Uint16
SDL_Swap16(Uint16 x) SDL_Swap16(Uint16 x)
{ {
@ -118,14 +129,14 @@ SDL_Swap16(Uint16 x)
__asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x)); __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
return (Uint16)result; return (Uint16)result;
} }
#elif defined(__GNUC__) && defined(__aarch64__) #elif defined(__aarch64__)
SDL_FORCE_INLINE Uint16 SDL_FORCE_INLINE Uint16
SDL_Swap16(Uint16 x) SDL_Swap16(Uint16 x)
{ {
__asm__("rev16 %w1, %w0" : "=r"(x) : "r"(x)); __asm__("rev16 %w1, %w0" : "=r"(x) : "r"(x));
return x; return x;
} }
#elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) #elif (defined(__m68k__) && !defined(__mcoldfire__))
SDL_FORCE_INLINE Uint16 SDL_FORCE_INLINE Uint16
SDL_Swap16(Uint16 x) SDL_Swap16(Uint16 x)
{ {
@ -149,25 +160,23 @@ SDL_Swap16(Uint16 x)
} }
#endif #endif
#if (_SDL_HAS_BUILTIN(__builtin_bswap32)) || \ #if HAS_BUILTIN_BSWAP32
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
#define SDL_Swap32(x) __builtin_bswap32(x) #define SDL_Swap32(x) __builtin_bswap32(x)
#elif defined(__GNUC__) && defined(__i386__) && \ #elif defined(__i386__) && !HAS_BROKEN_BSWAP
!(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
SDL_FORCE_INLINE Uint32 SDL_FORCE_INLINE Uint32
SDL_Swap32(Uint32 x) SDL_Swap32(Uint32 x)
{ {
__asm__("bswap %0": "=r"(x):"0"(x)); __asm__("bswap %0": "=r"(x):"0"(x));
return x; return x;
} }
#elif defined(__GNUC__) && defined(__x86_64__) #elif defined(__x86_64__)
SDL_FORCE_INLINE Uint32 SDL_FORCE_INLINE Uint32
SDL_Swap32(Uint32 x) SDL_Swap32(Uint32 x)
{ {
__asm__("bswapl %0": "=r"(x):"0"(x)); __asm__("bswapl %0": "=r"(x):"0"(x));
return x; return x;
} }
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) #elif (defined(__powerpc__) || defined(__ppc__))
SDL_FORCE_INLINE Uint32 SDL_FORCE_INLINE Uint32
SDL_Swap32(Uint32 x) SDL_Swap32(Uint32 x)
{ {
@ -178,14 +187,14 @@ SDL_Swap32(Uint32 x)
__asm__("rlwimi %0,%2,24,0,7" : "=&r"(result): "0" (result), "r"(x)); __asm__("rlwimi %0,%2,24,0,7" : "=&r"(result): "0" (result), "r"(x));
return result; return result;
} }
#elif defined(__GNUC__) && defined(__aarch64__) #elif defined(__aarch64__)
SDL_FORCE_INLINE Uint32 SDL_FORCE_INLINE Uint32
SDL_Swap32(Uint32 x) SDL_Swap32(Uint32 x)
{ {
__asm__("rev %w1, %w0": "=r"(x):"r"(x)); __asm__("rev %w1, %w0": "=r"(x):"r"(x));
return x; return x;
} }
#elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) #elif (defined(__m68k__) && !defined(__mcoldfire__))
SDL_FORCE_INLINE Uint32 SDL_FORCE_INLINE Uint32
SDL_Swap32(Uint32 x) SDL_Swap32(Uint32 x)
{ {
@ -210,11 +219,9 @@ SDL_Swap32(Uint32 x)
} }
#endif #endif
#if (_SDL_HAS_BUILTIN(__builtin_bswap64)) || \ #if HAS_BUILTIN_BSWAP64
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
#define SDL_Swap64(x) __builtin_bswap64(x) #define SDL_Swap64(x) __builtin_bswap64(x)
#elif defined(__GNUC__) && defined(__i386__) && \ #elif defined(__i386__) && !HAS_BROKEN_BSWAP
!(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
SDL_FORCE_INLINE Uint64 SDL_FORCE_INLINE Uint64
SDL_Swap64(Uint64 x) SDL_Swap64(Uint64 x)
{ {
@ -230,7 +237,7 @@ SDL_Swap64(Uint64 x)
: "0" (v.s.a), "1"(v.s.b)); : "0" (v.s.a), "1"(v.s.b));
return v.u; return v.u;
} }
#elif defined(__GNUC__) && defined(__x86_64__) #elif defined(__x86_64__)
SDL_FORCE_INLINE Uint64 SDL_FORCE_INLINE Uint64
SDL_Swap64(Uint64 x) SDL_Swap64(Uint64 x)
{ {
@ -278,6 +285,11 @@ SDL_SwapFloat(float x)
return swapper.f; return swapper.f;
} }
/* remove extra macros */
#undef HAS_BROKEN_BSWAP
#undef HAS_BUILTIN_BSWAP16
#undef HAS_BUILTIN_BSWAP32
#undef HAS_BUILTIN_BSWAP64
/** /**
* \name Swap to native * \name Swap to native