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