summaryrefslogtreecommitdiff
path: root/src/common/swap.h
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
committerGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
commitdc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch)
tree569a7f13128450bbab973236615587ff00bced5f /src/common/swap.h
parentTravis: Import Dolphin’s clang-format hook. (diff)
downloadyuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip
Sources: Run clang-format on everything.
Diffstat (limited to 'src/common/swap.h')
-rw-r--r--src/common/swap.h331
1 files changed, 191 insertions, 140 deletions
diff --git a/src/common/swap.h b/src/common/swap.h
index 1749bd7a4..1794144fb 100644
--- a/src/common/swap.h
+++ b/src/common/swap.h
@@ -18,11 +18,11 @@
18#pragma once 18#pragma once
19 19
20#if defined(_MSC_VER) 20#if defined(_MSC_VER)
21 #include <cstdlib> 21#include <cstdlib>
22#elif defined(__linux__) 22#elif defined(__linux__)
23 #include <byteswap.h> 23#include <byteswap.h>
24#elif defined(__FreeBSD__) 24#elif defined(__FreeBSD__)
25 #include <sys/endian.h> 25#include <sys/endian.h>
26#endif 26#endif
27 27
28#include <cstring> 28#include <cstring>
@@ -61,38 +61,73 @@
61namespace Common { 61namespace Common {
62 62
63#ifdef _MSC_VER 63#ifdef _MSC_VER
64inline u16 swap16(u16 _data) {return _byteswap_ushort(_data);} 64inline u16 swap16(u16 _data) {
65inline u32 swap32(u32 _data) {return _byteswap_ulong (_data);} 65 return _byteswap_ushort(_data);
66inline u64 swap64(u64 _data) {return _byteswap_uint64(_data);} 66}
67inline u32 swap32(u32 _data) {
68 return _byteswap_ulong(_data);
69}
70inline u64 swap64(u64 _data) {
71 return _byteswap_uint64(_data);
72}
67#elif _M_ARM 73#elif _M_ARM
68inline u16 swap16 (u16 _data) { u32 data = _data; __asm__ ("rev16 %0, %1\n" : "=l" (data) : "l" (data)); return (u16)data;} 74inline u16 swap16(u16 _data) {
69inline u32 swap32 (u32 _data) {__asm__ ("rev %0, %1\n" : "=l" (_data) : "l" (_data)); return _data;} 75 u32 data = _data;
70inline u64 swap64(u64 _data) {return ((u64)swap32(_data) << 32) | swap32(_data >> 32);} 76 __asm__("rev16 %0, %1\n" : "=l"(data) : "l"(data));
77 return (u16)data;
78}
79inline u32 swap32(u32 _data) {
80 __asm__("rev %0, %1\n" : "=l"(_data) : "l"(_data));
81 return _data;
82}
83inline u64 swap64(u64 _data) {
84 return ((u64)swap32(_data) << 32) | swap32(_data >> 32);
85}
71#elif __linux__ 86#elif __linux__
72inline u16 swap16(u16 _data) {return bswap_16(_data);} 87inline u16 swap16(u16 _data) {
73inline u32 swap32(u32 _data) {return bswap_32(_data);} 88 return bswap_16(_data);
74inline u64 swap64(u64 _data) {return bswap_64(_data);} 89}
90inline u32 swap32(u32 _data) {
91 return bswap_32(_data);
92}
93inline u64 swap64(u64 _data) {
94 return bswap_64(_data);
95}
75#elif __APPLE__ 96#elif __APPLE__
76inline __attribute__((always_inline)) u16 swap16(u16 _data) 97inline __attribute__((always_inline)) u16 swap16(u16 _data) {
77{return (_data >> 8) | (_data << 8);} 98 return (_data >> 8) | (_data << 8);
78inline __attribute__((always_inline)) u32 swap32(u32 _data) 99}
79{return __builtin_bswap32(_data);} 100inline __attribute__((always_inline)) u32 swap32(u32 _data) {
80inline __attribute__((always_inline)) u64 swap64(u64 _data) 101 return __builtin_bswap32(_data);
81{return __builtin_bswap64(_data);} 102}
103inline __attribute__((always_inline)) u64 swap64(u64 _data) {
104 return __builtin_bswap64(_data);
105}
82#elif __FreeBSD__ 106#elif __FreeBSD__
83inline u16 swap16(u16 _data) {return bswap16(_data);} 107inline u16 swap16(u16 _data) {
84inline u32 swap32(u32 _data) {return bswap32(_data);} 108 return bswap16(_data);
85inline u64 swap64(u64 _data) {return bswap64(_data);} 109}
110inline u32 swap32(u32 _data) {
111 return bswap32(_data);
112}
113inline u64 swap64(u64 _data) {
114 return bswap64(_data);
115}
86#else 116#else
87// Slow generic implementation. 117// Slow generic implementation.
88inline u16 swap16(u16 data) {return (data >> 8) | (data << 8);} 118inline u16 swap16(u16 data) {
89inline u32 swap32(u32 data) {return (swap16(data) << 16) | swap16(data >> 16);} 119 return (data >> 8) | (data << 8);
90inline u64 swap64(u64 data) {return ((u64)swap32(data) << 32) | swap32(data >> 32);} 120}
121inline u32 swap32(u32 data) {
122 return (swap16(data) << 16) | swap16(data >> 16);
123}
124inline u64 swap64(u64 data) {
125 return ((u64)swap32(data) << 32) | swap32(data >> 32);
126}
91#endif 127#endif
92 128
93inline float swapf(float f) { 129inline float swapf(float f) {
94 static_assert(sizeof(u32) == sizeof(float), 130 static_assert(sizeof(u32) == sizeof(float), "float must be the same size as uint32_t.");
95 "float must be the same size as uint32_t.");
96 131
97 u32 value; 132 u32 value;
98 std::memcpy(&value, &f, sizeof(u32)); 133 std::memcpy(&value, &f, sizeof(u32));
@@ -104,8 +139,7 @@ inline float swapf(float f) {
104} 139}
105 140
106inline double swapd(double f) { 141inline double swapd(double f) {
107 static_assert(sizeof(u64) == sizeof(double), 142 static_assert(sizeof(u64) == sizeof(double), "double must be the same size as uint64_t.");
108 "double must be the same size as uint64_t.");
109 143
110 u64 value; 144 u64 value;
111 std::memcpy(&value, &f, sizeof(u64)); 145 std::memcpy(&value, &f, sizeof(u64));
@@ -116,8 +150,7 @@ inline double swapd(double f) {
116 return f; 150 return f;
117} 151}
118 152
119} // Namespace Common 153} // Namespace Common
120
121 154
122template <typename T, typename F> 155template <typename T, typename F>
123struct swap_struct_t { 156struct swap_struct_t {
@@ -129,251 +162,272 @@ protected:
129 static T swap(T v) { 162 static T swap(T v) {
130 return F::swap(v); 163 return F::swap(v);
131 } 164 }
165
132public: 166public:
133 T const swap() const { 167 T const swap() const {
134 return swap(value); 168 return swap(value);
135
136 } 169 }
137 swap_struct_t() = default; 170 swap_struct_t() = default;
138 swap_struct_t(const T &v): value(swap(v)) {} 171 swap_struct_t(const T& v) : value(swap(v)) {
172 }
139 173
140 template <typename S> 174 template <typename S>
141 swapped_t& operator=(const S &source) { 175 swapped_t& operator=(const S& source) {
142 value = swap((T)source); 176 value = swap((T)source);
143 return *this; 177 return *this;
144 } 178 }
145 179
146 operator s8() const { return (s8)swap(); } 180 operator s8() const {
147 operator u8() const { return (u8)swap(); } 181 return (s8)swap();
148 operator s16() const { return (s16)swap(); } 182 }
149 operator u16() const { return (u16)swap(); } 183 operator u8() const {
150 operator s32() const { return (s32)swap(); } 184 return (u8)swap();
151 operator u32() const { return (u32)swap(); } 185 }
152 operator s64() const { return (s64)swap(); } 186 operator s16() const {
153 operator u64() const { return (u64)swap(); } 187 return (s16)swap();
154 operator float() const { return (float)swap(); } 188 }
155 operator double() const { return (double)swap(); } 189 operator u16() const {
190 return (u16)swap();
191 }
192 operator s32() const {
193 return (s32)swap();
194 }
195 operator u32() const {
196 return (u32)swap();
197 }
198 operator s64() const {
199 return (s64)swap();
200 }
201 operator u64() const {
202 return (u64)swap();
203 }
204 operator float() const {
205 return (float)swap();
206 }
207 operator double() const {
208 return (double)swap();
209 }
156 210
157 // +v 211 // +v
158 swapped_t operator +() const { 212 swapped_t operator+() const {
159 return +swap(); 213 return +swap();
160 } 214 }
161 // -v 215 // -v
162 swapped_t operator -() const { 216 swapped_t operator-() const {
163 return -swap(); 217 return -swap();
164 } 218 }
165 219
166 // v / 5 220 // v / 5
167 swapped_t operator/(const swapped_t &i) const { 221 swapped_t operator/(const swapped_t& i) const {
168 return swap() / i.swap(); 222 return swap() / i.swap();
169 } 223 }
170 template <typename S> 224 template <typename S>
171 swapped_t operator/(const S &i) const { 225 swapped_t operator/(const S& i) const {
172 return swap() / i; 226 return swap() / i;
173 } 227 }
174 228
175 // v * 5 229 // v * 5
176 swapped_t operator*(const swapped_t &i) const { 230 swapped_t operator*(const swapped_t& i) const {
177 return swap() * i.swap(); 231 return swap() * i.swap();
178 } 232 }
179 template <typename S> 233 template <typename S>
180 swapped_t operator*(const S &i) const { 234 swapped_t operator*(const S& i) const {
181 return swap() * i; 235 return swap() * i;
182 } 236 }
183 237
184 // v + 5 238 // v + 5
185 swapped_t operator+(const swapped_t &i) const { 239 swapped_t operator+(const swapped_t& i) const {
186 return swap() + i.swap(); 240 return swap() + i.swap();
187 } 241 }
188 template <typename S> 242 template <typename S>
189 swapped_t operator+(const S &i) const { 243 swapped_t operator+(const S& i) const {
190 return swap() + (T)i; 244 return swap() + (T)i;
191 } 245 }
192 // v - 5 246 // v - 5
193 swapped_t operator-(const swapped_t &i) const { 247 swapped_t operator-(const swapped_t& i) const {
194 return swap() - i.swap(); 248 return swap() - i.swap();
195 } 249 }
196 template <typename S> 250 template <typename S>
197 swapped_t operator-(const S &i) const { 251 swapped_t operator-(const S& i) const {
198 return swap() - (T)i; 252 return swap() - (T)i;
199 } 253 }
200 254
201 // v += 5 255 // v += 5
202 swapped_t& operator+=(const swapped_t &i) { 256 swapped_t& operator+=(const swapped_t& i) {
203 value = swap(swap() + i.swap()); 257 value = swap(swap() + i.swap());
204 return *this; 258 return *this;
205 } 259 }
206 template <typename S> 260 template <typename S>
207 swapped_t& operator+=(const S &i) { 261 swapped_t& operator+=(const S& i) {
208 value = swap(swap() + (T)i); 262 value = swap(swap() + (T)i);
209 return *this; 263 return *this;
210 } 264 }
211 // v -= 5 265 // v -= 5
212 swapped_t& operator-=(const swapped_t &i) { 266 swapped_t& operator-=(const swapped_t& i) {
213 value = swap(swap() - i.swap()); 267 value = swap(swap() - i.swap());
214 return *this; 268 return *this;
215 } 269 }
216 template <typename S> 270 template <typename S>
217 swapped_t& operator-=(const S &i) { 271 swapped_t& operator-=(const S& i) {
218 value = swap(swap() - (T)i); 272 value = swap(swap() - (T)i);
219 return *this; 273 return *this;
220 } 274 }
221 275
222 // ++v 276 // ++v
223 swapped_t& operator++() { 277 swapped_t& operator++() {
224 value = swap(swap()+1); 278 value = swap(swap() + 1);
225 return *this; 279 return *this;
226 } 280 }
227 // --v 281 // --v
228 swapped_t& operator--() { 282 swapped_t& operator--() {
229 value = swap(swap()-1); 283 value = swap(swap() - 1);
230 return *this; 284 return *this;
231 } 285 }
232 286
233 // v++ 287 // v++
234 swapped_t operator++(int) { 288 swapped_t operator++(int) {
235 swapped_t old = *this; 289 swapped_t old = *this;
236 value = swap(swap()+1); 290 value = swap(swap() + 1);
237 return old; 291 return old;
238 } 292 }
239 // v-- 293 // v--
240 swapped_t operator--(int) { 294 swapped_t operator--(int) {
241 swapped_t old = *this; 295 swapped_t old = *this;
242 value = swap(swap()-1); 296 value = swap(swap() - 1);
243 return old; 297 return old;
244 } 298 }
245 // Comparaison 299 // Comparaison
246 // v == i 300 // v == i
247 bool operator==(const swapped_t &i) const { 301 bool operator==(const swapped_t& i) const {
248 return swap() == i.swap(); 302 return swap() == i.swap();
249 } 303 }
250 template <typename S> 304 template <typename S>
251 bool operator==(const S &i) const { 305 bool operator==(const S& i) const {
252 return swap() == i; 306 return swap() == i;
253 } 307 }
254 308
255 // v != i 309 // v != i
256 bool operator!=(const swapped_t &i) const { 310 bool operator!=(const swapped_t& i) const {
257 return swap() != i.swap(); 311 return swap() != i.swap();
258 } 312 }
259 template <typename S> 313 template <typename S>
260 bool operator!=(const S &i) const { 314 bool operator!=(const S& i) const {
261 return swap() != i; 315 return swap() != i;
262 } 316 }
263 317
264 // v > i 318 // v > i
265 bool operator>(const swapped_t &i) const { 319 bool operator>(const swapped_t& i) const {
266 return swap() > i.swap(); 320 return swap() > i.swap();
267 } 321 }
268 template <typename S> 322 template <typename S>
269 bool operator>(const S &i) const { 323 bool operator>(const S& i) const {
270 return swap() > i; 324 return swap() > i;
271 } 325 }
272 326
273 // v < i 327 // v < i
274 bool operator<(const swapped_t &i) const { 328 bool operator<(const swapped_t& i) const {
275 return swap() < i.swap(); 329 return swap() < i.swap();
276 } 330 }
277 template <typename S> 331 template <typename S>
278 bool operator<(const S &i) const { 332 bool operator<(const S& i) const {
279 return swap() < i; 333 return swap() < i;
280 } 334 }
281 335
282 // v >= i 336 // v >= i
283 bool operator>=(const swapped_t &i) const { 337 bool operator>=(const swapped_t& i) const {
284 return swap() >= i.swap(); 338 return swap() >= i.swap();
285 } 339 }
286 template <typename S> 340 template <typename S>
287 bool operator>=(const S &i) const { 341 bool operator>=(const S& i) const {
288 return swap() >= i; 342 return swap() >= i;
289 } 343 }
290 344
291 // v <= i 345 // v <= i
292 bool operator<=(const swapped_t &i) const { 346 bool operator<=(const swapped_t& i) const {
293 return swap() <= i.swap(); 347 return swap() <= i.swap();
294 } 348 }
295 template <typename S> 349 template <typename S>
296 bool operator<=(const S &i) const { 350 bool operator<=(const S& i) const {
297 return swap() <= i; 351 return swap() <= i;
298 } 352 }
299 353
300 // logical 354 // logical
301 swapped_t operator !() const { 355 swapped_t operator!() const {
302 return !swap(); 356 return !swap();
303 } 357 }
304 358
305 // bitmath 359 // bitmath
306 swapped_t operator ~() const { 360 swapped_t operator~() const {
307 return ~swap(); 361 return ~swap();
308 } 362 }
309 363
310 swapped_t operator &(const swapped_t &b) const { 364 swapped_t operator&(const swapped_t& b) const {
311 return swap() & b.swap(); 365 return swap() & b.swap();
312 } 366 }
313 template <typename S> 367 template <typename S>
314 swapped_t operator &(const S &b) const { 368 swapped_t operator&(const S& b) const {
315 return swap() & b; 369 return swap() & b;
316 } 370 }
317 swapped_t& operator &=(const swapped_t &b) { 371 swapped_t& operator&=(const swapped_t& b) {
318 value = swap(swap() & b.swap()); 372 value = swap(swap() & b.swap());
319 return *this; 373 return *this;
320 } 374 }
321 template <typename S> 375 template <typename S>
322 swapped_t& operator &=(const S b) { 376 swapped_t& operator&=(const S b) {
323 value = swap(swap() & b); 377 value = swap(swap() & b);
324 return *this; 378 return *this;
325 } 379 }
326 380
327 swapped_t operator |(const swapped_t &b) const { 381 swapped_t operator|(const swapped_t& b) const {
328 return swap() | b.swap(); 382 return swap() | b.swap();
329 } 383 }
330 template <typename S> 384 template <typename S>
331 swapped_t operator |(const S &b) const { 385 swapped_t operator|(const S& b) const {
332 return swap() | b; 386 return swap() | b;
333 } 387 }
334 swapped_t& operator |=(const swapped_t &b) { 388 swapped_t& operator|=(const swapped_t& b) {
335 value = swap(swap() | b.swap()); 389 value = swap(swap() | b.swap());
336 return *this; 390 return *this;
337 } 391 }
338 template <typename S> 392 template <typename S>
339 swapped_t& operator |=(const S &b) { 393 swapped_t& operator|=(const S& b) {
340 value = swap(swap() | b); 394 value = swap(swap() | b);
341 return *this; 395 return *this;
342 } 396 }
343 397
344 swapped_t operator ^(const swapped_t &b) const { 398 swapped_t operator^(const swapped_t& b) const {
345 return swap() ^ b.swap(); 399 return swap() ^ b.swap();
346 } 400 }
347 template <typename S> 401 template <typename S>
348 swapped_t operator ^(const S &b) const { 402 swapped_t operator^(const S& b) const {
349 return swap() ^ b; 403 return swap() ^ b;
350 } 404 }
351 swapped_t& operator ^=(const swapped_t &b) { 405 swapped_t& operator^=(const swapped_t& b) {
352 value = swap(swap() ^ b.swap()); 406 value = swap(swap() ^ b.swap());
353 return *this; 407 return *this;
354 } 408 }
355 template <typename S> 409 template <typename S>
356 swapped_t& operator ^=(const S &b) { 410 swapped_t& operator^=(const S& b) {
357 value = swap(swap() ^ b); 411 value = swap(swap() ^ b);
358 return *this; 412 return *this;
359 } 413 }
360 414
361 template <typename S> 415 template <typename S>
362 swapped_t operator <<(const S &b) const { 416 swapped_t operator<<(const S& b) const {
363 return swap() << b; 417 return swap() << b;
364 } 418 }
365 template <typename S> 419 template <typename S>
366 swapped_t& operator <<=(const S &b) const { 420 swapped_t& operator<<=(const S& b) const {
367 value = swap(swap() << b); 421 value = swap(swap() << b);
368 return *this; 422 return *this;
369 } 423 }
370 424
371 template <typename S> 425 template <typename S>
372 swapped_t operator >>(const S &b) const { 426 swapped_t operator>>(const S& b) const {
373 return swap() >> b; 427 return swap() >> b;
374 } 428 }
375 template <typename S> 429 template <typename S>
376 swapped_t& operator >>=(const S &b) const { 430 swapped_t& operator>>=(const S& b) const {
377 value = swap(swap() >> b); 431 value = swap(swap() >> b);
378 return *this; 432 return *this;
379 } 433 }
@@ -381,129 +435,126 @@ public:
381 // Member 435 // Member
382 /** todo **/ 436 /** todo **/
383 437
384
385 // Arithmetics 438 // Arithmetics
386 template <typename S, typename T2, typename F2> 439 template <typename S, typename T2, typename F2>
387 friend S operator+(const S &p, const swapped_t v); 440 friend S operator+(const S& p, const swapped_t v);
388 441
389 template <typename S, typename T2, typename F2> 442 template <typename S, typename T2, typename F2>
390 friend S operator-(const S &p, const swapped_t v); 443 friend S operator-(const S& p, const swapped_t v);
391 444
392 template <typename S, typename T2, typename F2> 445 template <typename S, typename T2, typename F2>
393 friend S operator/(const S &p, const swapped_t v); 446 friend S operator/(const S& p, const swapped_t v);
394 447
395 template <typename S, typename T2, typename F2> 448 template <typename S, typename T2, typename F2>
396 friend S operator*(const S &p, const swapped_t v); 449 friend S operator*(const S& p, const swapped_t v);
397 450
398 template <typename S, typename T2, typename F2> 451 template <typename S, typename T2, typename F2>
399 friend S operator%(const S &p, const swapped_t v); 452 friend S operator%(const S& p, const swapped_t v);
400 453
401 // Arithmetics + assignements 454 // Arithmetics + assignements
402 template <typename S, typename T2, typename F2> 455 template <typename S, typename T2, typename F2>
403 friend S operator+=(const S &p, const swapped_t v); 456 friend S operator+=(const S& p, const swapped_t v);
404 457
405 template <typename S, typename T2, typename F2> 458 template <typename S, typename T2, typename F2>
406 friend S operator-=(const S &p, const swapped_t v); 459 friend S operator-=(const S& p, const swapped_t v);
407 460
408 // Bitmath 461 // Bitmath
409 template <typename S, typename T2, typename F2> 462 template <typename S, typename T2, typename F2>
410 friend S operator&(const S &p, const swapped_t v); 463 friend S operator&(const S& p, const swapped_t v);
411 464
412 // Comparison 465 // Comparison
413 template <typename S, typename T2, typename F2> 466 template <typename S, typename T2, typename F2>
414 friend bool operator<(const S &p, const swapped_t v); 467 friend bool operator<(const S& p, const swapped_t v);
415 468
416 template <typename S, typename T2, typename F2> 469 template <typename S, typename T2, typename F2>
417 friend bool operator>(const S &p, const swapped_t v); 470 friend bool operator>(const S& p, const swapped_t v);
418 471
419 template <typename S, typename T2, typename F2> 472 template <typename S, typename T2, typename F2>
420 friend bool operator<=(const S &p, const swapped_t v); 473 friend bool operator<=(const S& p, const swapped_t v);
421 474
422 template <typename S, typename T2, typename F2> 475 template <typename S, typename T2, typename F2>
423 friend bool operator>=(const S &p, const swapped_t v); 476 friend bool operator>=(const S& p, const swapped_t v);
424 477
425 template <typename S, typename T2, typename F2> 478 template <typename S, typename T2, typename F2>
426 friend bool operator!=(const S &p, const swapped_t v); 479 friend bool operator!=(const S& p, const swapped_t v);
427 480
428 template <typename S, typename T2, typename F2> 481 template <typename S, typename T2, typename F2>
429 friend bool operator==(const S &p, const swapped_t v); 482 friend bool operator==(const S& p, const swapped_t v);
430}; 483};
431 484
432
433// Arithmetics 485// Arithmetics
434template <typename S, typename T, typename F> 486template <typename S, typename T, typename F>
435S operator+(const S &i, const swap_struct_t<T, F> v) { 487S operator+(const S& i, const swap_struct_t<T, F> v) {
436 return i + v.swap(); 488 return i + v.swap();
437} 489}
438 490
439template <typename S, typename T, typename F> 491template <typename S, typename T, typename F>
440S operator-(const S &i, const swap_struct_t<T, F> v) { 492S operator-(const S& i, const swap_struct_t<T, F> v) {
441 return i - v.swap(); 493 return i - v.swap();
442} 494}
443 495
444template <typename S, typename T, typename F> 496template <typename S, typename T, typename F>
445S operator/(const S &i, const swap_struct_t<T, F> v) { 497S operator/(const S& i, const swap_struct_t<T, F> v) {
446 return i / v.swap(); 498 return i / v.swap();
447} 499}
448 500
449template <typename S, typename T, typename F> 501template <typename S, typename T, typename F>
450S operator*(const S &i, const swap_struct_t<T, F> v) { 502S operator*(const S& i, const swap_struct_t<T, F> v) {
451 return i * v.swap(); 503 return i * v.swap();
452} 504}
453 505
454template <typename S, typename T, typename F> 506template <typename S, typename T, typename F>
455S operator%(const S &i, const swap_struct_t<T, F> v) { 507S operator%(const S& i, const swap_struct_t<T, F> v) {
456 return i % v.swap(); 508 return i % v.swap();
457} 509}
458 510
459// Arithmetics + assignements 511// Arithmetics + assignements
460template <typename S, typename T, typename F> 512template <typename S, typename T, typename F>
461S &operator+=(S &i, const swap_struct_t<T, F> v) { 513S& operator+=(S& i, const swap_struct_t<T, F> v) {
462 i += v.swap(); 514 i += v.swap();
463 return i; 515 return i;
464} 516}
465 517
466template <typename S, typename T, typename F> 518template <typename S, typename T, typename F>
467S &operator-=(S &i, const swap_struct_t<T, F> v) { 519S& operator-=(S& i, const swap_struct_t<T, F> v) {
468 i -= v.swap(); 520 i -= v.swap();
469 return i; 521 return i;
470} 522}
471 523
472// Logical 524// Logical
473template <typename S, typename T, typename F> 525template <typename S, typename T, typename F>
474S operator&(const S &i, const swap_struct_t<T, F> v) { 526S operator&(const S& i, const swap_struct_t<T, F> v) {
475 return i & v.swap(); 527 return i & v.swap();
476} 528}
477 529
478template <typename S, typename T, typename F> 530template <typename S, typename T, typename F>
479S operator&(const swap_struct_t<T, F> v, const S &i) { 531S operator&(const swap_struct_t<T, F> v, const S& i) {
480 return (S)(v.swap() & i); 532 return (S)(v.swap() & i);
481} 533}
482 534
483
484// Comparaison 535// Comparaison
485template <typename S, typename T, typename F> 536template <typename S, typename T, typename F>
486bool operator<(const S &p, const swap_struct_t<T, F> v) { 537bool operator<(const S& p, const swap_struct_t<T, F> v) {
487 return p < v.swap(); 538 return p < v.swap();
488} 539}
489template <typename S, typename T, typename F> 540template <typename S, typename T, typename F>
490bool operator>(const S &p, const swap_struct_t<T, F> v) { 541bool operator>(const S& p, const swap_struct_t<T, F> v) {
491 return p > v.swap(); 542 return p > v.swap();
492} 543}
493template <typename S, typename T, typename F> 544template <typename S, typename T, typename F>
494bool operator<=(const S &p, const swap_struct_t<T, F> v) { 545bool operator<=(const S& p, const swap_struct_t<T, F> v) {
495 return p <= v.swap(); 546 return p <= v.swap();
496} 547}
497template <typename S, typename T, typename F> 548template <typename S, typename T, typename F>
498bool operator>=(const S &p, const swap_struct_t<T, F> v) { 549bool operator>=(const S& p, const swap_struct_t<T, F> v) {
499 return p >= v.swap(); 550 return p >= v.swap();
500} 551}
501template <typename S, typename T, typename F> 552template <typename S, typename T, typename F>
502bool operator!=(const S &p, const swap_struct_t<T, F> v) { 553bool operator!=(const S& p, const swap_struct_t<T, F> v) {
503 return p != v.swap(); 554 return p != v.swap();
504} 555}
505template <typename S, typename T, typename F> 556template <typename S, typename T, typename F>
506bool operator==(const S &p, const swap_struct_t<T, F> v) { 557bool operator==(const S& p, const swap_struct_t<T, F> v) {
507 return p == v.swap(); 558 return p == v.swap();
508} 559}
509 560
@@ -554,30 +605,30 @@ typedef s64 s64_le;
554typedef float float_le; 605typedef float float_le;
555typedef double double_le; 606typedef double double_le;
556 607
557typedef swap_struct_t<u64, swap_64_t<u64> > u64_be; 608typedef swap_struct_t<u64, swap_64_t<u64>> u64_be;
558typedef swap_struct_t<s64, swap_64_t<s64> > s64_be; 609typedef swap_struct_t<s64, swap_64_t<s64>> s64_be;
559 610
560typedef swap_struct_t<u32, swap_32_t<u32> > u32_be; 611typedef swap_struct_t<u32, swap_32_t<u32>> u32_be;
561typedef swap_struct_t<s32, swap_32_t<s32> > s32_be; 612typedef swap_struct_t<s32, swap_32_t<s32>> s32_be;
562 613
563typedef swap_struct_t<u16, swap_16_t<u16> > u16_be; 614typedef swap_struct_t<u16, swap_16_t<u16>> u16_be;
564typedef swap_struct_t<s16, swap_16_t<s16> > s16_be; 615typedef swap_struct_t<s16, swap_16_t<s16>> s16_be;
565 616
566typedef swap_struct_t<float, swap_float_t<float> > float_be; 617typedef swap_struct_t<float, swap_float_t<float>> float_be;
567typedef swap_struct_t<double, swap_double_t<double> > double_be; 618typedef swap_struct_t<double, swap_double_t<double>> double_be;
568#else 619#else
569 620
570typedef swap_struct_t<u64, swap_64_t<u64> > u64_le; 621typedef swap_struct_t<u64, swap_64_t<u64>> u64_le;
571typedef swap_struct_t<s64, swap_64_t<s64> > s64_le; 622typedef swap_struct_t<s64, swap_64_t<s64>> s64_le;
572 623
573typedef swap_struct_t<u32, swap_32_t<u32> > u32_le; 624typedef swap_struct_t<u32, swap_32_t<u32>> u32_le;
574typedef swap_struct_t<s32, swap_32_t<s32> > s32_le; 625typedef swap_struct_t<s32, swap_32_t<s32>> s32_le;
575 626
576typedef swap_struct_t<u16, swap_16_t<u16> > u16_le; 627typedef swap_struct_t<u16, swap_16_t<u16>> u16_le;
577typedef swap_struct_t< s16, swap_16_t<s16> > s16_le; 628typedef swap_struct_t<s16, swap_16_t<s16>> s16_le;
578 629
579typedef swap_struct_t<float, swap_float_t<float> > float_le; 630typedef swap_struct_t<float, swap_float_t<float>> float_le;
580typedef swap_struct_t<double, swap_double_t<double> > double_le; 631typedef swap_struct_t<double, swap_double_t<double>> double_le;
581 632
582typedef u32 u32_be; 633typedef u32 u32_be;
583typedef u16 u16_be; 634typedef u16 u16_be;