linux/include/linux/unaligned/be_byteshift.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef _LINUX_UNALIGNED_BE_BYTESHIFT_H
   3#define _LINUX_UNALIGNED_BE_BYTESHIFT_H
   4
   5#include <linux/types.h>
   6
   7static inline u16 __get_unaligned_be16(const u8 *p)
   8{
   9        return p[0] << 8 | p[1];
  10}
  11
  12static inline u32 __get_unaligned_be32(const u8 *p)
  13{
  14        return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
  15}
  16
  17static inline u64 __get_unaligned_be64(const u8 *p)
  18{
  19        return (u64)__get_unaligned_be32(p) << 32 |
  20               __get_unaligned_be32(p + 4);
  21}
  22
  23static inline void __put_unaligned_be16(u16 val, u8 *p)
  24{
  25        *p++ = val >> 8;
  26        *p++ = val;
  27}
  28
  29static inline void __put_unaligned_be32(u32 val, u8 *p)
  30{
  31        __put_unaligned_be16(val >> 16, p);
  32        __put_unaligned_be16(val, p + 2);
  33}
  34
  35static inline void __put_unaligned_be64(u64 val, u8 *p)
  36{
  37        __put_unaligned_be32(val >> 32, p);
  38        __put_unaligned_be32(val, p + 4);
  39}
  40
  41static inline u16 get_unaligned_be16(const void *p)
  42{
  43        return __get_unaligned_be16((const u8 *)p);
  44}
  45
  46static inline u32 get_unaligned_be32(const void *p)
  47{
  48        return __get_unaligned_be32((const u8 *)p);
  49}
  50
  51static inline u64 get_unaligned_be64(const void *p)
  52{
  53        return __get_unaligned_be64((const u8 *)p);
  54}
  55
  56static inline void put_unaligned_be16(u16 val, void *p)
  57{
  58        __put_unaligned_be16(val, p);
  59}
  60
  61static inline void put_unaligned_be32(u32 val, void *p)
  62{
  63        __put_unaligned_be32(val, p);
  64}
  65
  66static inline void put_unaligned_be64(u64 val, void *p)
  67{
  68        __put_unaligned_be64(val, p);
  69}
  70
  71#endif /* _LINUX_UNALIGNED_BE_BYTESHIFT_H */
  72