1 | #ifndef SRL_ENDIANNESS_H_ |
---|
2 | #define SRL_ENDIANNESS_H_ |
---|
3 | |
---|
4 | #include "srl_public_types.h" |
---|
5 | |
---|
6 | /** @this reads a big endian 16 bits value */ |
---|
7 | # define endian_le16(x) (x) |
---|
8 | /** @this reads a big endian 32 bits value */ |
---|
9 | # define endian_le32(x) (x) |
---|
10 | /** @this reads a big endian 64 bits value */ |
---|
11 | //# define endian_le64(x) (x) |
---|
12 | /** @this reads a little endian 16 bits value */ |
---|
13 | # define endian_be16(x) endian_swap16(x) |
---|
14 | /** @this reads a little endian 32 bits value */ |
---|
15 | # define endian_be32(x) endian_swap32(x) |
---|
16 | /** @this reads a little endian 64 bits value */ |
---|
17 | //# define endian_be64(x) endian_swap64(x) |
---|
18 | |
---|
19 | /** @internal */ |
---|
20 | static inline uint16_t endian_swap16(uint16_t x) |
---|
21 | { |
---|
22 | return (x >> 8) | (x << 8); |
---|
23 | } |
---|
24 | |
---|
25 | /** @internal */ |
---|
26 | static inline uint32_t endian_swap32(uint32_t x) |
---|
27 | { |
---|
28 | return (((x >> 24) & 0x000000ff) | |
---|
29 | ((x >> 8 ) & 0x0000ff00) | |
---|
30 | ((x << 8 ) & 0x00ff0000) | |
---|
31 | ((x << 24) & 0xff000000)); |
---|
32 | } |
---|
33 | |
---|
34 | /** @internal *//* |
---|
35 | static inline uint64_t __endian_swap64(uint64_t x) |
---|
36 | { |
---|
37 | return (((uint64_t)endian_swap32(x ) << 32) | |
---|
38 | ((uint64_t)endian_swap32(x >> 32) )); |
---|
39 | }*/ |
---|
40 | |
---|
41 | static inline uint32_t srl_uint32_le_to_machine(uint32_t x) |
---|
42 | { |
---|
43 | return endian_le32(x); |
---|
44 | } |
---|
45 | |
---|
46 | static inline uint32_t srl_uint32_machine_to_le(uint32_t x) |
---|
47 | { |
---|
48 | return endian_le32(x); |
---|
49 | } |
---|
50 | |
---|
51 | static inline uint32_t srl_uint32_be_to_machine(uint32_t x) |
---|
52 | { |
---|
53 | return endian_be32(x); |
---|
54 | } |
---|
55 | |
---|
56 | static inline uint32_t srl_uint32_machine_to_be(uint32_t x) |
---|
57 | { |
---|
58 | return endian_be32(x); |
---|
59 | } |
---|
60 | |
---|
61 | static inline uint16_t srl_uint16_le_to_machine(uint16_t x) |
---|
62 | { |
---|
63 | return endian_le16(x); |
---|
64 | } |
---|
65 | |
---|
66 | static inline uint16_t srl_uint16_machine_to_le(uint16_t x) |
---|
67 | { |
---|
68 | return endian_le16(x); |
---|
69 | } |
---|
70 | |
---|
71 | static inline uint16_t srl_uint16_be_to_machine(uint16_t x) |
---|
72 | { |
---|
73 | return endian_be16(x); |
---|
74 | } |
---|
75 | |
---|
76 | static inline uint16_t srl_uint16_machine_to_be(uint16_t x) |
---|
77 | { |
---|
78 | return endian_be16(x); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | #endif |
---|