rename BE/LE_8/16/32 to AV_RL/B_8/16/32
[libav.git] / libavutil / intreadwrite.h
1 #ifndef INTREADWRITE_H
2 #define INTREADWRITE_H
3
4 #ifdef __GNUC__
5
6 struct unaligned_64 { uint64_t l; } __attribute__((packed));
7 struct unaligned_32 { uint32_t l; } __attribute__((packed));
8 struct unaligned_16 { uint16_t l; } __attribute__((packed));
9
10 #define LD16(a) (((const struct unaligned_16 *) (a))->l)
11 #define LD32(a) (((const struct unaligned_32 *) (a))->l)
12 #define LD64(a) (((const struct unaligned_64 *) (a))->l)
13
14 #define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
15 #define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
16
17 #else /* __GNUC__ */
18
19 #define LD16(a) (*((uint16_t*)(a)))
20 #define LD32(a) (*((uint32_t*)(a)))
21 #define LD64(a) (*((uint64_t*)(a)))
22
23 #define ST16(a, b) *((uint16_t*)(a)) = (b)
24 #define ST32(a, b) *((uint32_t*)(a)) = (b)
25
26 #endif /* !__GNUC__ */
27
28 /* endian macros */
29 #if !defined(AV_RB16) || !defined(AV_RB32) || !defined(AV_RL16) || !defined(AV_RL32)
30 #define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
31 #define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \
32 (((uint8_t*)(x))[1] << 16) | \
33 (((uint8_t*)(x))[2] << 8) | \
34 ((uint8_t*)(x))[3])
35 #define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
36 #define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \
37 (((uint8_t*)(x))[2] << 16) | \
38 (((uint8_t*)(x))[1] << 8) | \
39 ((uint8_t*)(x))[0])
40 #endif
41
42 #endif /* INTREADWRITE_H */