1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright © 2014 Tom Gundersen
13 static inline uint16_t unaligned_read_be16(const void *_u) {
14 const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
19 static inline uint32_t unaligned_read_be32(const void *_u) {
20 const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
25 static inline uint64_t unaligned_read_be64(const void *_u) {
26 const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
31 static inline void unaligned_write_be16(void *_u, uint16_t a) {
32 struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
37 static inline void unaligned_write_be32(void *_u, uint32_t a) {
38 struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
43 static inline void unaligned_write_be64(void *_u, uint64_t a) {
44 struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
51 static inline uint16_t unaligned_read_le16(const void *_u) {
52 const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
57 static inline uint32_t unaligned_read_le32(const void *_u) {
58 const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
63 static inline uint64_t unaligned_read_le64(const void *_u) {
64 const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
69 static inline void unaligned_write_le16(void *_u, uint16_t a) {
70 struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
75 static inline void unaligned_write_le32(void *_u, uint32_t a) {
76 struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
81 static inline void unaligned_write_le64(void *_u, uint64_t a) {
82 struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
87 #if __BYTE_ORDER == __BIG_ENDIAN
88 #define unaligned_read_ne16 unaligned_read_be16
89 #define unaligned_read_ne32 unaligned_read_be32
90 #define unaligned_read_ne64 unaligned_read_be64
92 #define unaligned_write_ne16 unaligned_write_be16
93 #define unaligned_write_ne32 unaligned_write_be32
94 #define unaligned_write_ne64 unaligned_write_be64
96 #define unaligned_read_ne16 unaligned_read_le16
97 #define unaligned_read_ne32 unaligned_read_le32
98 #define unaligned_read_ne64 unaligned_read_le64
100 #define unaligned_write_ne16 unaligned_write_le16
101 #define unaligned_write_ne32 unaligned_write_le32
102 #define unaligned_write_ne64 unaligned_write_le64