Commit | Line | Data |
---|---|---|
cf1e119b RD |
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 */ | |
a3550abd | 29 | #define AV_RB8(x) (((uint8_t*)(x))[0]) |
7d4495da | 30 | #define AV_WB8(p, d) { ((uint8_t*)(p))[0] = (d); } |
a3550abd AB |
31 | |
32 | #define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) | |
7d4495da MN |
33 | #define AV_WB16(p, d) { \ |
34 | ((uint8_t*)(p))[1] = (d); \ | |
35 | ((uint8_t*)(p))[0] = (d)>>8; } | |
a3550abd AB |
36 | |
37 | #define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \ | |
cf1e119b RD |
38 | (((uint8_t*)(x))[1] << 16) | \ |
39 | (((uint8_t*)(x))[2] << 8) | \ | |
40 | ((uint8_t*)(x))[3]) | |
7d4495da MN |
41 | #define AV_WB32(p, d) { \ |
42 | ((uint8_t*)(p))[3] = (d); \ | |
43 | ((uint8_t*)(p))[2] = (d)>>8; \ | |
44 | ((uint8_t*)(p))[1] = (d)>>16; \ | |
45 | ((uint8_t*)(p))[0] = (d)>>24; } | |
a3550abd AB |
46 | |
47 | #define AV_RL8(x) AV_RB8(x) | |
7d4495da | 48 | #define AV_WL8(p, d) AV_WB8(p, d) |
a3550abd AB |
49 | |
50 | #define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0]) | |
7d4495da MN |
51 | #define AV_WL16(p, d) { \ |
52 | ((uint8_t*)(p))[0] = (d); \ | |
53 | ((uint8_t*)(p))[1] = (d)>>8; } | |
a3550abd AB |
54 | |
55 | #define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \ | |
cf1e119b RD |
56 | (((uint8_t*)(x))[2] << 16) | \ |
57 | (((uint8_t*)(x))[1] << 8) | \ | |
58 | ((uint8_t*)(x))[0]) | |
7d4495da MN |
59 | #define AV_WL32(p, d) { \ |
60 | ((uint8_t*)(p))[0] = (d); \ | |
61 | ((uint8_t*)(p))[1] = (d)>>8; \ | |
62 | ((uint8_t*)(p))[2] = (d)>>16; \ | |
63 | ((uint8_t*)(p))[3] = (d)>>24; } | |
cf1e119b RD |
64 | |
65 | #endif /* INTREADWRITE_H */ |