# HG changeset patch # User Sam Lantinga # Date 1077514372 0 # Node ID 85af65457959f83f293d304bf883eefb4b34d39c # Parent 0afe0e38e02cf2048e93582f01c52fbb91d3c7bb Avoid using kernel internal headers diff -r 0afe0e38e02c -r 85af65457959 include/SDL_endian.h --- a/include/SDL_endian.h Sat Feb 21 00:21:06 2004 +0000 +++ b/include/SDL_endian.h Mon Feb 23 05:32:52 2004 +0000 @@ -54,32 +54,35 @@ extern "C" { #endif -/* The macros used to swap values */ -/* Try to use superfast macros on systems that support them */ -#ifdef linux -#include -#ifdef __arch__swab16 -#define SDL_Swap16 __arch__swab16 -#endif -#ifdef __arch__swab32 -#define SDL_Swap32 __arch__swab32 -#endif -#endif /* linux */ /* Use inline functions for compilers that support them, and static functions for those that do not. Because these functions become static for compilers that do not support inline functions, this header should only be included in files that actually use them. */ -#ifndef SDL_Swap16 +#if defined(__GNUC__) && defined(i386) +static __inline__ Uint16 SDL_Swap16(Uint16 D) +{ + __asm__("xchgb %b0,%h0" : "=q" (D) : "0" (D)); + return D; +} +#else static __inline__ Uint16 SDL_Swap16(Uint16 D) { return((D<<8)|(D>>8)); } #endif -#ifndef SDL_Swap32 + +#if defined(__GNUC__) && defined(i386) +static __inline__ Uint32 SDL_Swap32(Uint32 D) +{ + __asm__("bswap %0" : "=r" (D) : "0" (D)); + return D; +} +#else static __inline__ Uint32 SDL_Swap32(Uint32 D) { return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); } #endif + #ifdef SDL_HAS_64BIT_TYPE #ifndef SDL_Swap64 static __inline__ Uint64 SDL_Swap64(Uint64 val) {