You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2KB

  1. #ifndef INTREADWRITE_H
  2. #define INTREADWRITE_H
  3. #ifdef __GNUC__
  4. struct unaligned_64 { uint64_t l; } __attribute__((packed));
  5. struct unaligned_32 { uint32_t l; } __attribute__((packed));
  6. struct unaligned_16 { uint16_t l; } __attribute__((packed));
  7. #define LD16(a) (((const struct unaligned_16 *) (a))->l)
  8. #define LD32(a) (((const struct unaligned_32 *) (a))->l)
  9. #define LD64(a) (((const struct unaligned_64 *) (a))->l)
  10. #define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
  11. #define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
  12. #else /* __GNUC__ */
  13. #define LD16(a) (*((uint16_t*)(a)))
  14. #define LD32(a) (*((uint32_t*)(a)))
  15. #define LD64(a) (*((uint64_t*)(a)))
  16. #define ST16(a, b) *((uint16_t*)(a)) = (b)
  17. #define ST32(a, b) *((uint32_t*)(a)) = (b)
  18. #endif /* !__GNUC__ */
  19. /* endian macros */
  20. #define AV_RB8(x) (((uint8_t*)(x))[0])
  21. #define AV_WB8(p, d) { ((uint8_t*)(p))[0] = (d); }
  22. #define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
  23. #define AV_WB16(p, d) { \
  24. ((uint8_t*)(p))[1] = (d); \
  25. ((uint8_t*)(p))[0] = (d)>>8; }
  26. #define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \
  27. (((uint8_t*)(x))[1] << 16) | \
  28. (((uint8_t*)(x))[2] << 8) | \
  29. ((uint8_t*)(x))[3])
  30. #define AV_WB32(p, d) { \
  31. ((uint8_t*)(p))[3] = (d); \
  32. ((uint8_t*)(p))[2] = (d)>>8; \
  33. ((uint8_t*)(p))[1] = (d)>>16; \
  34. ((uint8_t*)(p))[0] = (d)>>24; }
  35. #define AV_RL8(x) AV_RB8(x)
  36. #define AV_WL8(p, d) AV_WB8(p, d)
  37. #define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
  38. #define AV_WL16(p, d) { \
  39. ((uint8_t*)(p))[0] = (d); \
  40. ((uint8_t*)(p))[1] = (d)>>8; }
  41. #define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \
  42. (((uint8_t*)(x))[2] << 16) | \
  43. (((uint8_t*)(x))[1] << 8) | \
  44. ((uint8_t*)(x))[0])
  45. #define AV_WL32(p, d) { \
  46. ((uint8_t*)(p))[0] = (d); \
  47. ((uint8_t*)(p))[1] = (d)>>8; \
  48. ((uint8_t*)(p))[2] = (d)>>16; \
  49. ((uint8_t*)(p))[3] = (d)>>24; }
  50. #endif /* INTREADWRITE_H */