include/SDL_endian.h
changeset 1895 c121d94672cb
parent 1475 d45aefcac017
child 1984 b910bcabec26
     1.1 --- a/include/SDL_endian.h	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/include/SDL_endian.h	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -20,7 +20,11 @@
     1.4      slouken@libsdl.org
     1.5  */
     1.6  
     1.7 -/* Functions for reading and writing endian-specific values */
     1.8 +/**
     1.9 + * \file SDL_endian.h
    1.10 + *
    1.11 + * Functions for reading and writing endian-specific values
    1.12 + */
    1.13  
    1.14  #ifndef _SDL_endian_h
    1.15  #define _SDL_endian_h
    1.16 @@ -31,7 +35,7 @@
    1.17  #define SDL_LIL_ENDIAN	1234
    1.18  #define SDL_BIG_ENDIAN	4321
    1.19  
    1.20 -#ifndef SDL_BYTEORDER	/* Not defined in SDL_config.h? */
    1.21 +#ifndef SDL_BYTEORDER           /* Not defined in SDL_config.h? */
    1.22  #if defined(__hppa__) || \
    1.23      defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
    1.24      (defined(__MIPS__) && defined(__MISPEB__)) || \
    1.25 @@ -47,7 +51,9 @@
    1.26  #include "begin_code.h"
    1.27  /* Set up for C function definitions, even when using C++ */
    1.28  #ifdef __cplusplus
    1.29 +/* *INDENT-OFF* */
    1.30  extern "C" {
    1.31 +/* *INDENT-ON* */
    1.32  #endif
    1.33  
    1.34  /* Use inline functions for compilers that support them, and static
    1.35 @@ -57,104 +63,124 @@
    1.36  */
    1.37  #if defined(__GNUC__) && defined(__i386__) && \
    1.38     !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
    1.39 -static __inline__ Uint16 SDL_Swap16(Uint16 x)
    1.40 +static __inline__ Uint16
    1.41 +SDL_Swap16(Uint16 x)
    1.42  {
    1.43 -	__asm__("xchgb %b0,%h0" : "=q" (x) :  "0" (x));
    1.44 -	return x;
    1.45 +  __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
    1.46 +    return x;
    1.47  }
    1.48  #elif defined(__GNUC__) && defined(__x86_64__)
    1.49 -static __inline__ Uint16 SDL_Swap16(Uint16 x)
    1.50 +static __inline__ Uint16
    1.51 +SDL_Swap16(Uint16 x)
    1.52  {
    1.53 -	__asm__("xchgb %b0,%h0" : "=Q" (x) :  "0" (x));
    1.54 -	return x;
    1.55 +  __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
    1.56 +    return x;
    1.57  }
    1.58  #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
    1.59 -static __inline__ Uint16 SDL_Swap16(Uint16 x)
    1.60 +static __inline__ Uint16
    1.61 +SDL_Swap16(Uint16 x)
    1.62  {
    1.63 -	Uint16 result;
    1.64 +    Uint16 result;
    1.65  
    1.66 -	__asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x));
    1.67 -	return result;
    1.68 +  __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
    1.69 +    return result;
    1.70  }
    1.71  #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
    1.72 -static __inline__ Uint16 SDL_Swap16(Uint16 x)
    1.73 +static __inline__ Uint16
    1.74 +SDL_Swap16(Uint16 x)
    1.75  {
    1.76 -	__asm__("rorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
    1.77 -	return x;
    1.78 +  __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
    1.79 +    return x;
    1.80  }
    1.81  #else
    1.82 -static __inline__ Uint16 SDL_Swap16(Uint16 x) {
    1.83 -	return((x<<8)|(x>>8));
    1.84 +static __inline__ Uint16
    1.85 +SDL_Swap16(Uint16 x)
    1.86 +{
    1.87 +    return ((x << 8) | (x >> 8));
    1.88  }
    1.89  #endif
    1.90  
    1.91  #if defined(__GNUC__) && defined(__i386__)
    1.92 -static __inline__ Uint32 SDL_Swap32(Uint32 x)
    1.93 +static __inline__ Uint32
    1.94 +SDL_Swap32(Uint32 x)
    1.95  {
    1.96 -	__asm__("bswap %0" : "=r" (x) : "0" (x));
    1.97 -	return x;
    1.98 +  __asm__("bswap %0": "=r"(x):"0"(x));
    1.99 +    return x;
   1.100  }
   1.101  #elif defined(__GNUC__) && defined(__x86_64__)
   1.102 -static __inline__ Uint32 SDL_Swap32(Uint32 x)
   1.103 +static __inline__ Uint32
   1.104 +SDL_Swap32(Uint32 x)
   1.105  {
   1.106 -	__asm__("bswapl %0" : "=r" (x) : "0" (x));
   1.107 -	return x;
   1.108 +  __asm__("bswapl %0": "=r"(x):"0"(x));
   1.109 +    return x;
   1.110  }
   1.111  #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
   1.112 -static __inline__ Uint32 SDL_Swap32(Uint32 x)
   1.113 +static __inline__ Uint32
   1.114 +SDL_Swap32(Uint32 x)
   1.115  {
   1.116 -	Uint32 result;
   1.117 +    Uint32 result;
   1.118  
   1.119 -	__asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
   1.120 -	__asm__("rlwimi %0,%2,8,8,15"   : "=&r" (result) : "0" (result),    "r" (x));
   1.121 -	__asm__("rlwimi %0,%2,24,0,7"   : "=&r" (result) : "0" (result),    "r" (x));
   1.122 -	return result;
   1.123 +  __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
   1.124 +  __asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
   1.125 +  __asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
   1.126 +    return result;
   1.127  }
   1.128  #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
   1.129 -static __inline__ Uint32 SDL_Swap32(Uint32 x)
   1.130 +static __inline__ Uint32
   1.131 +SDL_Swap32(Uint32 x)
   1.132  {
   1.133 -	__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
   1.134 -	return x;
   1.135 +  __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
   1.136 +    return x;
   1.137  }
   1.138  #else
   1.139 -static __inline__ Uint32 SDL_Swap32(Uint32 x) {
   1.140 -	return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24));
   1.141 +static __inline__ Uint32
   1.142 +SDL_Swap32(Uint32 x)
   1.143 +{
   1.144 +    return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
   1.145 +            (x >> 24));
   1.146  }
   1.147  #endif
   1.148  
   1.149  #ifdef SDL_HAS_64BIT_TYPE
   1.150  #if defined(__GNUC__) && defined(__i386__)
   1.151 -static __inline__ Uint64 SDL_Swap64(Uint64 x)
   1.152 +static __inline__ Uint64
   1.153 +SDL_Swap64(Uint64 x)
   1.154  {
   1.155 -	union { 
   1.156 -		struct { Uint32 a,b; } s;
   1.157 -		Uint64 u;
   1.158 -	} v;
   1.159 -	v.u = x;
   1.160 -	__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1" 
   1.161 -	        : "=r" (v.s.a), "=r" (v.s.b) 
   1.162 -	        : "0" (v.s.a), "1" (v.s.b)); 
   1.163 -	return v.u;
   1.164 +    union
   1.165 +    {
   1.166 +        struct
   1.167 +        {
   1.168 +            Uint32 a, b;
   1.169 +        } s;
   1.170 +        Uint64 u;
   1.171 +    } v;
   1.172 +    v.u = x;
   1.173 +  __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
   1.174 +            "1"(v.s.
   1.175 +                b));
   1.176 +    return v.u;
   1.177  }
   1.178  #elif defined(__GNUC__) && defined(__x86_64__)
   1.179 -static __inline__ Uint64 SDL_Swap64(Uint64 x)
   1.180 +static __inline__ Uint64
   1.181 +SDL_Swap64(Uint64 x)
   1.182  {
   1.183 -	__asm__("bswapq %0" : "=r" (x) : "0" (x));
   1.184 -	return x;
   1.185 +  __asm__("bswapq %0": "=r"(x):"0"(x));
   1.186 +    return x;
   1.187  }
   1.188  #else
   1.189 -static __inline__ Uint64 SDL_Swap64(Uint64 x)
   1.190 +static __inline__ Uint64
   1.191 +SDL_Swap64(Uint64 x)
   1.192  {
   1.193 -	Uint32 hi, lo;
   1.194 +    Uint32 hi, lo;
   1.195  
   1.196 -	/* Separate into high and low 32-bit values and swap them */
   1.197 -	lo = (Uint32)(x&0xFFFFFFFF);
   1.198 -	x >>= 32;
   1.199 -	hi = (Uint32)(x&0xFFFFFFFF);
   1.200 -	x = SDL_Swap32(lo);
   1.201 -	x <<= 32;
   1.202 -	x |= SDL_Swap32(hi);
   1.203 -	return(x);
   1.204 +    /* Separate into high and low 32-bit values and swap them */
   1.205 +    lo = (Uint32) (x & 0xFFFFFFFF);
   1.206 +    x >>= 32;
   1.207 +    hi = (Uint32) (x & 0xFFFFFFFF);
   1.208 +    x = SDL_Swap32(lo);
   1.209 +    x <<= 32;
   1.210 +    x |= SDL_Swap32(hi);
   1.211 +    return (x);
   1.212  }
   1.213  #endif
   1.214  #else
   1.215 @@ -185,8 +211,12 @@
   1.216  
   1.217  /* Ends C function definitions when using C++ */
   1.218  #ifdef __cplusplus
   1.219 +/* *INDENT-OFF* */
   1.220  }
   1.221 +/* *INDENT-ON* */
   1.222  #endif
   1.223  #include "close_code.h"
   1.224  
   1.225  #endif /* _SDL_endian_h */
   1.226 +
   1.227 +/* vi: set ts=4 sw=4 expandtab: */