Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / unaligned / be_byteshift.h
blob8bdb8fa01bd4cfe8b97359079579596adb38f4d3
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_UNALIGNED_BE_BYTESHIFT_H
3 #define _LINUX_UNALIGNED_BE_BYTESHIFT_H
5 #include <linux/types.h>
7 static inline u16 __get_unaligned_be16(const u8 *p)
9 return p[0] << 8 | p[1];
12 static inline u32 __get_unaligned_be32(const u8 *p)
14 return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
17 static inline u64 __get_unaligned_be64(const u8 *p)
19 return (u64)__get_unaligned_be32(p) << 32 |
20 __get_unaligned_be32(p + 4);
23 static inline void __put_unaligned_be16(u16 val, u8 *p)
25 *p++ = val >> 8;
26 *p++ = val;
29 static inline void __put_unaligned_be32(u32 val, u8 *p)
31 __put_unaligned_be16(val >> 16, p);
32 __put_unaligned_be16(val, p + 2);
35 static inline void __put_unaligned_be64(u64 val, u8 *p)
37 __put_unaligned_be32(val >> 32, p);
38 __put_unaligned_be32(val, p + 4);
41 static inline u16 get_unaligned_be16(const void *p)
43 return __get_unaligned_be16((const u8 *)p);
46 static inline u32 get_unaligned_be32(const void *p)
48 return __get_unaligned_be32((const u8 *)p);
51 static inline u64 get_unaligned_be64(const void *p)
53 return __get_unaligned_be64((const u8 *)p);
56 static inline void put_unaligned_be16(u16 val, void *p)
58 __put_unaligned_be16(val, p);
61 static inline void put_unaligned_be32(u32 val, void *p)
63 __put_unaligned_be32(val, p);
66 static inline void put_unaligned_be64(u64 val, void *p)
68 __put_unaligned_be64(val, p);
71 #endif /* _LINUX_UNALIGNED_BE_BYTESHIFT_H */