akaros/kern/arch/riscv/endian.h
<<
>>
Prefs
   1/* Copyright (c) 2010 The Regents of the University of California
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   5 * Endian #def and byte_swapping functions */
   6
   7#pragma once
   8
   9#include <ros/common.h>
  10#include <arch/types.h>
  11
  12static inline uint16_t byte_swap16(uint16_t x)
  13{
  14        return (uint16_t)(x << 8 | x >> 8);
  15}
  16
  17static inline uint32_t byte_swap32(uint32_t x)
  18{
  19        return (uint32_t)(((uint32_t)byte_swap16(x & 0xffff) << 16) |
  20                          (byte_swap16(x >> 16)));
  21}
  22
  23static inline uint64_t byte_swap64(uint64_t x)
  24{
  25        return (uint64_t)(((uint64_t)byte_swap32(x & 0xffffffff) << 32) |
  26                          (byte_swap32(x >> 32)));
  27}
  28