1 /* |
1 /* |
2 SDL - Simple DirectMedia Layer |
2 SDL - Simple DirectMedia Layer |
3 Copyright (C) 1997-2009 Sam Lantinga |
3 Copyright (C) 1997-2012 Sam Lantinga |
4 |
4 |
5 This library is free software; you can redistribute it and/or |
5 This library is free software; you can redistribute it and/or |
6 modify it under the terms of the GNU Lesser General Public |
6 modify it under the terms of the GNU Lesser General Public |
7 License as published by the Free Software Foundation; either |
7 License as published by the Free Software Foundation; either |
8 version 2.1 of the License, or (at your option) any later version. |
8 version 2.1 of the License, or (at your option) any later version. |
37 #define SDL_LIL_ENDIAN 1234 |
37 #define SDL_LIL_ENDIAN 1234 |
38 #define SDL_BIG_ENDIAN 4321 |
38 #define SDL_BIG_ENDIAN 4321 |
39 /*@}*/ |
39 /*@}*/ |
40 |
40 |
41 #ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */ |
41 #ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */ |
|
42 #ifdef __linux__ |
|
43 #include <endian.h> |
|
44 #define SDL_BYTEORDER __BYTE_ORDER |
|
45 #else /* __linux __ */ |
42 #if defined(__hppa__) || \ |
46 #if defined(__hppa__) || \ |
43 defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ |
47 defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ |
44 (defined(__MIPS__) && defined(__MISPEB__)) || \ |
48 (defined(__MIPS__) && defined(__MISPEB__)) || \ |
45 defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ |
49 defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ |
46 defined(__sparc__) |
50 defined(__sparc__) |
47 #define SDL_BYTEORDER SDL_BIG_ENDIAN |
51 #define SDL_BYTEORDER SDL_BIG_ENDIAN |
48 #else |
52 #else |
49 #define SDL_BYTEORDER SDL_LIL_ENDIAN |
53 #define SDL_BYTEORDER SDL_LIL_ENDIAN |
50 #endif |
54 #endif |
|
55 #endif /* __linux __ */ |
51 #endif /* !SDL_BYTEORDER */ |
56 #endif /* !SDL_BYTEORDER */ |
52 |
57 |
53 |
58 |
54 #include "begin_code.h" |
59 #include "begin_code.h" |
55 /* Set up for C function definitions, even when using C++ */ |
60 /* Set up for C function definitions, even when using C++ */ |
84 Uint16 result; |
89 Uint16 result; |
85 |
90 |
86 __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x)); |
91 __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x)); |
87 return result; |
92 return result; |
88 } |
93 } |
89 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) |
94 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) |
90 static __inline__ Uint16 SDL_Swap16(Uint16 x) |
95 static __inline__ Uint16 SDL_Swap16(Uint16 x) |
91 { |
96 { |
92 __asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc"); |
97 __asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc"); |
93 return x; |
98 return x; |
94 } |
99 } |
95 #else |
100 #else |
96 static __inline__ Uint16 SDL_Swap16(Uint16 x) { |
101 static __inline__ Uint16 SDL_Swap16(Uint16 x) { |
97 return((x<<8)|(x>>8)); |
102 return SDL_static_cast(Uint16, ((x<<8)|(x>>8))); |
98 } |
103 } |
99 #endif |
104 #endif |
100 |
105 |
101 #if defined(__GNUC__) && defined(__i386__) && \ |
106 #if defined(__GNUC__) && defined(__i386__) && \ |
102 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */) |
107 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */) |
119 __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x)); |
124 __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x)); |
120 __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x)); |
125 __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x)); |
121 __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x)); |
126 __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x)); |
122 return result; |
127 return result; |
123 } |
128 } |
124 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) |
129 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) |
125 static __inline__ Uint32 SDL_Swap32(Uint32 x) |
130 static __inline__ Uint32 SDL_Swap32(Uint32 x) |
126 { |
131 { |
127 __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc"); |
132 __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc"); |
128 return x; |
133 return x; |
129 } |
134 } |
130 #else |
135 #else |
131 static __inline__ Uint32 SDL_Swap32(Uint32 x) { |
136 static __inline__ Uint32 SDL_Swap32(Uint32 x) { |
132 return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)); |
137 return SDL_static_cast(Uint32, ((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24))); |
133 } |
138 } |
134 #endif |
139 #endif |
135 |
140 |
136 #ifdef SDL_HAS_64BIT_TYPE |
141 #ifdef SDL_HAS_64BIT_TYPE |
137 #if defined(__GNUC__) && defined(__i386__) && \ |
142 #if defined(__GNUC__) && defined(__i386__) && \ |