comparison include/SDL_endian.h @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
62 header should only be included in files that actually use them. 62 header should only be included in files that actually use them.
63 */ 63 */
64 #if defined(__GNUC__) && defined(__i386__) && \ 64 #if defined(__GNUC__) && defined(__i386__) && \
65 !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */) 65 !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
66 static __inline__ Uint16 66 static __inline__ Uint16
67 SDL_Swap16 (Uint16 x) 67 SDL_Swap16(Uint16 x)
68 { 68 {
69 __asm__ ("xchgb %b0,%h0": "=q" (x):"0" (x)); 69 __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
70 return x; 70 return x;
71 } 71 }
72 #elif defined(__GNUC__) && defined(__x86_64__) 72 #elif defined(__GNUC__) && defined(__x86_64__)
73 static __inline__ Uint16 73 static __inline__ Uint16
74 SDL_Swap16 (Uint16 x) 74 SDL_Swap16(Uint16 x)
75 { 75 {
76 __asm__ ("xchgb %b0,%h0": "=Q" (x):"0" (x)); 76 __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
77 return x; 77 return x;
78 } 78 }
79 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) 79 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
80 static __inline__ Uint16 80 static __inline__ Uint16
81 SDL_Swap16 (Uint16 x) 81 SDL_Swap16(Uint16 x)
82 { 82 {
83 Uint16 result; 83 Uint16 result;
84 84
85 __asm__ ("rlwimi %0,%2,8,16,23": "=&r" (result):"0" (x >> 8), "r" (x)); 85 __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
86 return result; 86 return result;
87 } 87 }
88 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) 88 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
89 static __inline__ Uint16 89 static __inline__ Uint16
90 SDL_Swap16 (Uint16 x) 90 SDL_Swap16(Uint16 x)
91 { 91 {
92 __asm__ ("rorw #8,%0": "=d" (x): "0" (x):"cc"); 92 __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
93 return x; 93 return x;
94 } 94 }
95 #else 95 #else
96 static __inline__ Uint16 96 static __inline__ Uint16
97 SDL_Swap16 (Uint16 x) 97 SDL_Swap16(Uint16 x)
98 { 98 {
99 return ((x << 8) | (x >> 8)); 99 return ((x << 8) | (x >> 8));
100 } 100 }
101 #endif 101 #endif
102 102
103 #if defined(__GNUC__) && defined(__i386__) 103 #if defined(__GNUC__) && defined(__i386__)
104 static __inline__ Uint32 104 static __inline__ Uint32
105 SDL_Swap32 (Uint32 x) 105 SDL_Swap32(Uint32 x)
106 { 106 {
107 __asm__ ("bswap %0": "=r" (x):"0" (x)); 107 __asm__("bswap %0": "=r"(x):"0"(x));
108 return x; 108 return x;
109 } 109 }
110 #elif defined(__GNUC__) && defined(__x86_64__) 110 #elif defined(__GNUC__) && defined(__x86_64__)
111 static __inline__ Uint32 111 static __inline__ Uint32
112 SDL_Swap32 (Uint32 x) 112 SDL_Swap32(Uint32 x)
113 { 113 {
114 __asm__ ("bswapl %0": "=r" (x):"0" (x)); 114 __asm__("bswapl %0": "=r"(x):"0"(x));
115 return x; 115 return x;
116 } 116 }
117 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) 117 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
118 static __inline__ Uint32 118 static __inline__ Uint32
119 SDL_Swap32 (Uint32 x) 119 SDL_Swap32(Uint32 x)
120 { 120 {
121 Uint32 result; 121 Uint32 result;
122 122
123 __asm__ ("rlwimi %0,%2,24,16,23": "=&r" (result):"0" (x >> 24), 123 __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
124 "r" (x)); 124 __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)); 125 __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));
127 return result; 126 return result;
128 } 127 }
129 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) 128 #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
130 static __inline__ Uint32 129 static __inline__ Uint32
131 SDL_Swap32 (Uint32 x) 130 SDL_Swap32(Uint32 x)
132 { 131 {
133 __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");
134 return x; 133 return x;
135 } 134 }
136 #else 135 #else
137 static __inline__ Uint32 136 static __inline__ Uint32
138 SDL_Swap32 (Uint32 x) 137 SDL_Swap32(Uint32 x)
139 { 138 {
140 return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | 139 return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
141 (x >> 24)); 140 (x >> 24));
142 } 141 }
143 #endif 142 #endif
144 143
145 #ifdef SDL_HAS_64BIT_TYPE 144 #ifdef SDL_HAS_64BIT_TYPE
146 #if defined(__GNUC__) && defined(__i386__) 145 #if defined(__GNUC__) && defined(__i386__)
147 static __inline__ Uint64 146 static __inline__ Uint64
148 SDL_Swap64 (Uint64 x) 147 SDL_Swap64(Uint64 x)
149 { 148 {
150 union 149 union
151 { 150 {
152 struct 151 struct
153 { 152 {
154 Uint32 a, b; 153 Uint32 a, b;
155 } s; 154 } s;
156 Uint64 u; 155 Uint64 u;
157 } v; 156 } v;
158 v.u = x; 157 v.u = x;
159 __asm__ ("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r" (v.s.a), "=r" (v.s.b):"0" (v.s.a), 158 __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
160 "1" (v.s. 159 "1"(v.s.
161 b)); 160 b));
162 return v.u; 161 return v.u;
163 } 162 }
164 #elif defined(__GNUC__) && defined(__x86_64__) 163 #elif defined(__GNUC__) && defined(__x86_64__)
165 static __inline__ Uint64 164 static __inline__ Uint64
166 SDL_Swap64 (Uint64 x) 165 SDL_Swap64(Uint64 x)
167 { 166 {
168 __asm__ ("bswapq %0": "=r" (x):"0" (x)); 167 __asm__("bswapq %0": "=r"(x):"0"(x));
169 return x; 168 return x;
170 } 169 }
171 #else 170 #else
172 static __inline__ Uint64 171 static __inline__ Uint64
173 SDL_Swap64 (Uint64 x) 172 SDL_Swap64(Uint64 x)
174 { 173 {
175 Uint32 hi, lo; 174 Uint32 hi, lo;
176 175
177 /* Separate into high and low 32-bit values and swap them */ 176 /* Separate into high and low 32-bit values and swap them */
178 lo = (Uint32) (x & 0xFFFFFFFF); 177 lo = (Uint32) (x & 0xFFFFFFFF);
179 x >>= 32; 178 x >>= 32;
180 hi = (Uint32) (x & 0xFFFFFFFF); 179 hi = (Uint32) (x & 0xFFFFFFFF);
181 x = SDL_Swap32 (lo); 180 x = SDL_Swap32(lo);
182 x <<= 32; 181 x <<= 32;
183 x |= SDL_Swap32 (hi); 182 x |= SDL_Swap32(hi);
184 return (x); 183 return (x);
185 } 184 }
186 #endif 185 #endif
187 #else 186 #else
188 /* This is mainly to keep compilers from complaining in SDL code. 187 /* This is mainly to keep compilers from complaining in SDL code.