38
|
1 /*
|
|
2 SDL - Simple DirectMedia Layer
|
|
3 Copyright (C) 1997-2009 Sam Lantinga
|
|
4
|
|
5 This library is free software; you can redistribute it and/or
|
|
6 modify it under the terms of the GNU Lesser General Public
|
|
7 License as published by the Free Software Foundation; either
|
|
8 version 2.1 of the License, or (at your option) any later version.
|
|
9
|
|
10 This library is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 Lesser General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Lesser General Public
|
|
16 License along with this library; if not, write to the Free Software
|
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
|
|
19 Sam Lantinga
|
|
20 slouken@libsdl.org
|
|
21 */
|
|
22
|
|
23 /*
|
|
24 Attention: This is a stripped down file of SDL_endian for our purposes.
|
|
25 This code is licensed under the LGPL.
|
|
26 This means we must not compile this code into anything that we are not willing to
|
|
27 publicly release source code.
|
|
28 You should compile this into a separate dynamic library that is isolated from proprietary code.
|
|
29 */
|
|
30
|
|
31
|
|
32 #ifndef SDL_endian_minimal_h
|
|
33 #define SDL_endian_minimal_h
|
|
34
|
|
35 #ifdef ANDROID_NDK
|
|
36 #include <endian.h>
|
|
37
|
|
38 #define SDL_BYTEORDER _BYTE_ORDER
|
|
39 #define SDL_BIG_ENDIAN _BIG_ENDIAN
|
|
40 #define SDL_LITTLE_ENDIAN _LITTLE_ENDIAN
|
|
41 #endif
|
|
42
|
|
43 #include <stdint.h>
|
|
44
|
|
45
|
|
46 #if defined(__GNUC__) && defined(__i386__) && \
|
|
47 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
|
|
48 static __inline__ uint32_t SDL_Swap32(uint32_t x)
|
|
49 {
|
|
50 __asm__("bswap %0" : "=r" (x) : "0" (x));
|
|
51 return x;
|
|
52 }
|
|
53 #elif defined(__GNUC__) && defined(__x86_64__)
|
|
54 static __inline__ uint32_t SDL_Swap32(uint32_t x)
|
|
55 {
|
|
56 __asm__("bswapl %0" : "=r" (x) : "0" (x));
|
|
57 return x;
|
|
58 }
|
|
59 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
|
60 static __inline__ uint32_t SDL_Swap32(uint32_t x)
|
|
61 {
|
|
62 uint32_t result;
|
|
63
|
|
64 __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
|
|
65 __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x));
|
|
66 __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x));
|
|
67 return result;
|
|
68 }
|
|
69 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
|
|
70 static __inline__ uint32_t SDL_Swap32(uint32_t x)
|
|
71 {
|
|
72 __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc");
|
|
73 return x;
|
|
74 }
|
|
75 #else
|
|
76 static __inline__ uint32_t SDL_Swap32(uint32_t x) {
|
|
77 return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24));
|
|
78 }
|
|
79 #endif
|
|
80
|
|
81
|
|
82 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
83 #define SDL_SwapLE16(X) SDL_Swap16(X)
|
|
84 #define SDL_SwapLE32(X) SDL_Swap32(X)
|
|
85 #define SDL_SwapLE64(X) SDL_Swap64(X)
|
|
86 #define SDL_SwapBE16(X) (X)
|
|
87 #define SDL_SwapBE32(X) (X)
|
|
88 #define SDL_SwapBE64(X) (X)
|
|
89 #else
|
|
90 #define SDL_SwapLE16(X) (X)
|
|
91 #define SDL_SwapLE32(X) (X)
|
|
92 #define SDL_SwapLE64(X) (X)
|
|
93 #define SDL_SwapBE16(X) SDL_Swap16(X)
|
|
94 #define SDL_SwapBE32(X) SDL_Swap32(X)
|
|
95 #define SDL_SwapBE64(X) SDL_Swap64(X)
|
|
96 #endif
|
|
97
|
|
98
|
|
99 #endif // SDL_endian_minimal_h
|