include/SDL_endian.h
changeset 848 85af65457959
parent 769 b8d311d90021
child 849 bab227101de4
     1.1 --- a/include/SDL_endian.h	Sat Feb 21 00:21:06 2004 +0000
     1.2 +++ b/include/SDL_endian.h	Mon Feb 23 05:32:52 2004 +0000
     1.3 @@ -54,32 +54,35 @@
     1.4  extern "C" {
     1.5  #endif
     1.6  
     1.7 -/* The macros used to swap values */
     1.8 -/* Try to use superfast macros on systems that support them */
     1.9 -#ifdef linux
    1.10 -#include <asm/byteorder.h>
    1.11 -#ifdef __arch__swab16
    1.12 -#define SDL_Swap16  __arch__swab16
    1.13 -#endif
    1.14 -#ifdef __arch__swab32
    1.15 -#define SDL_Swap32  __arch__swab32
    1.16 -#endif
    1.17 -#endif /* linux */
    1.18  /* Use inline functions for compilers that support them, and static
    1.19     functions for those that do not.  Because these functions become
    1.20     static for compilers that do not support inline functions, this
    1.21     header should only be included in files that actually use them.
    1.22  */
    1.23 -#ifndef SDL_Swap16
    1.24 +#if defined(__GNUC__) && defined(i386)
    1.25 +static __inline__ Uint16 SDL_Swap16(Uint16 D)
    1.26 +{
    1.27 +	__asm__("xchgb %b0,%h0" : "=q" (D) :  "0" (D));
    1.28 +	return D;
    1.29 +}
    1.30 +#else
    1.31  static __inline__ Uint16 SDL_Swap16(Uint16 D) {
    1.32  	return((D<<8)|(D>>8));
    1.33  }
    1.34  #endif
    1.35 -#ifndef SDL_Swap32
    1.36 +
    1.37 +#if defined(__GNUC__) && defined(i386)
    1.38 +static __inline__ Uint32 SDL_Swap32(Uint32 D)
    1.39 +{
    1.40 +	__asm__("bswap %0" : "=r" (D) : "0" (D));
    1.41 +	return D;
    1.42 +}
    1.43 +#else
    1.44  static __inline__ Uint32 SDL_Swap32(Uint32 D) {
    1.45  	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
    1.46  }
    1.47  #endif
    1.48 +
    1.49  #ifdef SDL_HAS_64BIT_TYPE
    1.50  #ifndef SDL_Swap64
    1.51  static __inline__ Uint64 SDL_Swap64(Uint64 val) {