include/SDL_endian.h
changeset 848 85af65457959
parent 769 b8d311d90021
child 849 bab227101de4
equal deleted inserted replaced
847:0afe0e38e02c 848:85af65457959
    52 /* Set up for C function definitions, even when using C++ */
    52 /* Set up for C function definitions, even when using C++ */
    53 #ifdef __cplusplus
    53 #ifdef __cplusplus
    54 extern "C" {
    54 extern "C" {
    55 #endif
    55 #endif
    56 
    56 
    57 /* The macros used to swap values */
       
    58 /* Try to use superfast macros on systems that support them */
       
    59 #ifdef linux
       
    60 #include <asm/byteorder.h>
       
    61 #ifdef __arch__swab16
       
    62 #define SDL_Swap16  __arch__swab16
       
    63 #endif
       
    64 #ifdef __arch__swab32
       
    65 #define SDL_Swap32  __arch__swab32
       
    66 #endif
       
    67 #endif /* linux */
       
    68 /* Use inline functions for compilers that support them, and static
    57 /* Use inline functions for compilers that support them, and static
    69    functions for those that do not.  Because these functions become
    58    functions for those that do not.  Because these functions become
    70    static for compilers that do not support inline functions, this
    59    static for compilers that do not support inline functions, this
    71    header should only be included in files that actually use them.
    60    header should only be included in files that actually use them.
    72 */
    61 */
    73 #ifndef SDL_Swap16
    62 #if defined(__GNUC__) && defined(i386)
       
    63 static __inline__ Uint16 SDL_Swap16(Uint16 D)
       
    64 {
       
    65 	__asm__("xchgb %b0,%h0" : "=q" (D) :  "0" (D));
       
    66 	return D;
       
    67 }
       
    68 #else
    74 static __inline__ Uint16 SDL_Swap16(Uint16 D) {
    69 static __inline__ Uint16 SDL_Swap16(Uint16 D) {
    75 	return((D<<8)|(D>>8));
    70 	return((D<<8)|(D>>8));
    76 }
    71 }
    77 #endif
    72 #endif
    78 #ifndef SDL_Swap32
    73 
       
    74 #if defined(__GNUC__) && defined(i386)
       
    75 static __inline__ Uint32 SDL_Swap32(Uint32 D)
       
    76 {
       
    77 	__asm__("bswap %0" : "=r" (D) : "0" (D));
       
    78 	return D;
       
    79 }
       
    80 #else
    79 static __inline__ Uint32 SDL_Swap32(Uint32 D) {
    81 static __inline__ Uint32 SDL_Swap32(Uint32 D) {
    80 	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
    82 	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
    81 }
    83 }
    82 #endif
    84 #endif
       
    85 
    83 #ifdef SDL_HAS_64BIT_TYPE
    86 #ifdef SDL_HAS_64BIT_TYPE
    84 #ifndef SDL_Swap64
    87 #ifndef SDL_Swap64
    85 static __inline__ Uint64 SDL_Swap64(Uint64 val) {
    88 static __inline__ Uint64 SDL_Swap64(Uint64 val) {
    86 	Uint32 hi, lo;
    89 	Uint32 hi, lo;
    87 
    90