1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 static inline uint16_t unaligned_read_be16(const void *_u) {
11 const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
16 static inline uint32_t unaligned_read_be32(const void *_u) {
17 const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
22 static inline uint64_t unaligned_read_be64(const void *_u) {
23 const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
28 static inline void unaligned_write_be16(void *_u, uint16_t a) {
29 struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
34 static inline void unaligned_write_be32(void *_u, uint32_t a) {
35 struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
40 static inline void unaligned_write_be64(void *_u, uint64_t a) {
41 struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
48 static inline uint16_t unaligned_read_le16(const void *_u) {
49 const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
54 static inline uint32_t unaligned_read_le32(const void *_u) {
55 const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
60 static inline uint64_t unaligned_read_le64(const void *_u) {
61 const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
66 static inline void unaligned_write_le16(void *_u, uint16_t a) {
67 struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
72 static inline void unaligned_write_le32(void *_u, uint32_t a) {
73 struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
78 static inline void unaligned_write_le64(void *_u, uint64_t a) {
79 struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
84 #if __BYTE_ORDER == __BIG_ENDIAN
85 #define unaligned_read_ne16 unaligned_read_be16
86 #define unaligned_read_ne32 unaligned_read_be32
87 #define unaligned_read_ne64 unaligned_read_be64
89 #define unaligned_write_ne16 unaligned_write_be16
90 #define unaligned_write_ne32 unaligned_write_be32
91 #define unaligned_write_ne64 unaligned_write_be64
93 #define unaligned_read_ne16 unaligned_read_le16
94 #define unaligned_read_ne32 unaligned_read_le32
95 #define unaligned_read_ne64 unaligned_read_le64
97 #define unaligned_write_ne16 unaligned_write_le16
98 #define unaligned_write_ne32 unaligned_write_le32
99 #define unaligned_write_ne64 unaligned_write_le64