annotate intreadwrite.h @ 152:5b211d03227b libavutil

Move BE_*/LE_*/ST*/LD* macros to a common place. Some further optimization/cleanup would be desirable (e.g. LE_* and LD* should be the same on x86).
author reimar
date Sun, 03 Dec 2006 16:35:30 +0000
parents
children 33b71496b63b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
152
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
1 #ifndef INTREADWRITE_H
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
2 #define INTREADWRITE_H
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
3
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
4 #ifdef __GNUC__
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
5
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
6 struct unaligned_64 { uint64_t l; } __attribute__((packed));
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
7 struct unaligned_32 { uint32_t l; } __attribute__((packed));
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
8 struct unaligned_16 { uint16_t l; } __attribute__((packed));
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
9
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
10 #define LD16(a) (((const struct unaligned_16 *) (a))->l)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
11 #define LD32(a) (((const struct unaligned_32 *) (a))->l)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
12 #define LD64(a) (((const struct unaligned_64 *) (a))->l)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
13
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
14 #define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
15 #define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
16
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
17 #else /* __GNUC__ */
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
18
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
19 #define LD16(a) (*((uint16_t*)(a)))
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
20 #define LD32(a) (*((uint32_t*)(a)))
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
21 #define LD64(a) (*((uint64_t*)(a)))
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
22
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
23 #define ST16(a, b) *((uint16_t*)(a)) = (b)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
24 #define ST32(a, b) *((uint32_t*)(a)) = (b)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
25
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
26 #endif /* !__GNUC__ */
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
27
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
28 /* endian macros */
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
29 #if !defined(BE_16) || !defined(BE_32) || !defined(LE_16) || !defined(LE_32)
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
30 #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
31 #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
32 (((uint8_t*)(x))[1] << 16) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
33 (((uint8_t*)(x))[2] << 8) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
34 ((uint8_t*)(x))[3])
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
35 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
36 #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
37 (((uint8_t*)(x))[2] << 16) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
38 (((uint8_t*)(x))[1] << 8) | \
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
39 ((uint8_t*)(x))[0])
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
40 #endif
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
41
5b211d03227b Move BE_*/LE_*/ST*/LD* macros to a common place. Some further
reimar
parents:
diff changeset
42 #endif /* INTREADWRITE_H */