00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #ifndef _SDL_endian_h
00030 #define _SDL_endian_h
00031
00032 #include "SDL_stdinc.h"
00033
00034
00035 #define SDL_LIL_ENDIAN 1234
00036 #define SDL_BIG_ENDIAN 4321
00037
00038 #ifndef SDL_BYTEORDER
00039 #if defined(__hppa__) || \
00040 defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
00041 (defined(__MIPS__) && defined(__MISPEB__)) || \
00042 defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
00043 defined(__sparc__)
00044 #define SDL_BYTEORDER SDL_BIG_ENDIAN
00045 #else
00046 #define SDL_BYTEORDER SDL_LIL_ENDIAN
00047 #endif
00048 #endif
00049
00050
00051 #include "begin_code.h"
00052
00053 #ifdef __cplusplus
00054
00055 extern "C" {
00056
00057 #endif
00058
00059
00060
00061
00062
00063
00064 #if defined(__GNUC__) && defined(__i386__) && \
00065 !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 )
00066 static __inline__ Uint16
00067 SDL_Swap16(Uint16 x)
00068 {
00069 __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
00070 return x;
00071 }
00072 #elif defined(__GNUC__) && defined(__x86_64__)
00073 static __inline__ Uint16
00074 SDL_Swap16(Uint16 x)
00075 {
00076 __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
00077 return x;
00078 }
00079 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
00080 static __inline__ Uint16
00081 SDL_Swap16(Uint16 x)
00082 {
00083 Uint16 result;
00084
00085 __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
00086 return result;
00087 }
00088 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
00089 static __inline__ Uint16
00090 SDL_Swap16(Uint16 x)
00091 {
00092 __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
00093 return x;
00094 }
00095 #else
00096 static __inline__ Uint16
00097 SDL_Swap16(Uint16 x)
00098 {
00099 return ((x << 8) | (x >> 8));
00100 }
00101 #endif
00102
00103 #if defined(__GNUC__) && defined(__i386__)
00104 static __inline__ Uint32
00105 SDL_Swap32(Uint32 x)
00106 {
00107 __asm__("bswap %0": "=r"(x):"0"(x));
00108 return x;
00109 }
00110 #elif defined(__GNUC__) && defined(__x86_64__)
00111 static __inline__ Uint32
00112 SDL_Swap32(Uint32 x)
00113 {
00114 __asm__("bswapl %0": "=r"(x):"0"(x));
00115 return x;
00116 }
00117 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
00118 static __inline__ Uint32
00119 SDL_Swap32(Uint32 x)
00120 {
00121 Uint32 result;
00122
00123 __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
00124 __asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
00125 __asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
00126 return result;
00127 }
00128 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
00129 static __inline__ Uint32
00130 SDL_Swap32(Uint32 x)
00131 {
00132 __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
00133 return x;
00134 }
00135 #else
00136 static __inline__ Uint32
00137 SDL_Swap32(Uint32 x)
00138 {
00139 return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
00140 (x >> 24));
00141 }
00142 #endif
00143
00144 #ifdef SDL_HAS_64BIT_TYPE
00145 #if defined(__GNUC__) && defined(__i386__)
00146 static __inline__ Uint64
00147 SDL_Swap64(Uint64 x)
00148 {
00149 union
00150 {
00151 struct
00152 {
00153 Uint32 a, b;
00154 } s;
00155 Uint64 u;
00156 } v;
00157 v.u = x;
00158 __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
00159 "1"(v.s.
00160 b));
00161 return v.u;
00162 }
00163 #elif defined(__GNUC__) && defined(__x86_64__)
00164 static __inline__ Uint64
00165 SDL_Swap64(Uint64 x)
00166 {
00167 __asm__("bswapq %0": "=r"(x):"0"(x));
00168 return x;
00169 }
00170 #else
00171 static __inline__ Uint64
00172 SDL_Swap64(Uint64 x)
00173 {
00174 Uint32 hi, lo;
00175
00176
00177 lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
00178 x >>= 32;
00179 hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
00180 x = SDL_Swap32(lo);
00181 x <<= 32;
00182 x |= SDL_Swap32(hi);
00183 return (x);
00184 }
00185 #endif
00186 #else
00187
00188
00189
00190
00191 #define SDL_Swap64(X) (X)
00192 #endif
00193
00194
00195 static __inline__ float
00196 SDL_SwapFloat(float x)
00197 {
00198 union
00199 {
00200 float f;
00201 Uint32 ui32;
00202 } swapper;
00203 swapper.f = x;
00204 swapper.ui32 = SDL_Swap32(swapper.ui32);
00205 return swapper.f;
00206 }
00207
00208
00209
00210 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
00211 #define SDL_SwapLE16(X) (X)
00212 #define SDL_SwapLE32(X) (X)
00213 #define SDL_SwapLE64(X) (X)
00214 #define SDL_SwapFloatLE(X) (X)
00215 #define SDL_SwapBE16(X) SDL_Swap16(X)
00216 #define SDL_SwapBE32(X) SDL_Swap32(X)
00217 #define SDL_SwapBE64(X) SDL_Swap64(X)
00218 #define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
00219 #else
00220 #define SDL_SwapLE16(X) SDL_Swap16(X)
00221 #define SDL_SwapLE32(X) SDL_Swap32(X)
00222 #define SDL_SwapLE64(X) SDL_Swap64(X)
00223 #define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
00224 #define SDL_SwapBE16(X) (X)
00225 #define SDL_SwapBE32(X) (X)
00226 #define SDL_SwapBE64(X) (X)
00227 #define SDL_SwapFloatBE(X) (X)
00228 #endif
00229
00230
00231 #ifdef __cplusplus
00232
00233 }
00234
00235 #endif
00236 #include "close_code.h"
00237
00238 #endif
00239
00240