endian.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <nall/intrinsics.hpp>
  3. #if defined(ENDIAN_LSB)
  4. //little-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201
  5. #define order_lsb1(a) a
  6. #define order_lsb2(a,b) a,b
  7. #define order_lsb3(a,b,c) a,b,c
  8. #define order_lsb4(a,b,c,d) a,b,c,d
  9. #define order_lsb5(a,b,c,d,e) a,b,c,d,e
  10. #define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f
  11. #define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
  12. #define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
  13. #define order_msb1(a) a
  14. #define order_msb2(a,b) b,a
  15. #define order_msb3(a,b,c) c,b,a
  16. #define order_msb4(a,b,c,d) d,c,b,a
  17. #define order_msb5(a,b,c,d,e) e,d,c,b,a
  18. #define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a
  19. #define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
  20. #define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
  21. #elif defined(ENDIAN_MSB)
  22. //big-endian: uint8_t[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304
  23. #define order_lsb1(a) a
  24. #define order_lsb2(a,b) b,a
  25. #define order_lsb3(a,b,c) c,b,a
  26. #define order_lsb4(a,b,c,d) d,c,b,a
  27. #define order_lsb5(a,b,c,d,e) e,d,c,b,a
  28. #define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a
  29. #define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
  30. #define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
  31. #define order_msb1(a) a
  32. #define order_msb2(a,b) a,b
  33. #define order_msb3(a,b,c) a,b,c
  34. #define order_msb4(a,b,c,d) a,b,c,d
  35. #define order_msb5(a,b,c,d,e) a,b,c,d,e
  36. #define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f
  37. #define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
  38. #define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
  39. #else
  40. #error "Unknown endian. Please specify in nall/intrinsics.hpp"
  41. #endif