1
2#ifndef _TOOLS_LE_BYTESHIFT_H
3#define _TOOLS_LE_BYTESHIFT_H
4
5#include <stdint.h>
6
7static inline uint16_t __get_unaligned_le16(const uint8_t *p)
8{
9 return p[0] | p[1] << 8;
10}
11
12static inline uint32_t __get_unaligned_le32(const uint8_t *p)
13{
14 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
15}
16
17static inline uint64_t __get_unaligned_le64(const uint8_t *p)
18{
19 return (uint64_t)__get_unaligned_le32(p + 4) << 32 |
20 __get_unaligned_le32(p);
21}
22
23static inline void __put_unaligned_le16(uint16_t val, uint8_t *p)
24{
25 *p++ = val;
26 *p++ = val >> 8;
27}
28
29static inline void __put_unaligned_le32(uint32_t val, uint8_t *p)
30{
31 __put_unaligned_le16(val >> 16, p + 2);
32 __put_unaligned_le16(val, p);
33}
34
35static inline void __put_unaligned_le64(uint64_t val, uint8_t *p)
36{
37 __put_unaligned_le32(val >> 32, p + 4);
38 __put_unaligned_le32(val, p);
39}
40
41static inline uint16_t get_unaligned_le16(const void *p)
42{
43 return __get_unaligned_le16((const uint8_t *)p);
44}
45
46static inline uint32_t get_unaligned_le32(const void *p)
47{
48 return __get_unaligned_le32((const uint8_t *)p);
49}
50
51static inline uint64_t get_unaligned_le64(const void *p)
52{
53 return __get_unaligned_le64((const uint8_t *)p);
54}
55
56static inline void put_unaligned_le16(uint16_t val, void *p)
57{
58 __put_unaligned_le16(val, p);
59}
60
61static inline void put_unaligned_le32(uint32_t val, void *p)
62{
63 __put_unaligned_le32(val, p);
64}
65
66static inline void put_unaligned_le64(uint64_t val, void *p)
67{
68 __put_unaligned_le64(val, p);
69}
70
71#endif
72