akaros/kern/arch/x86/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        /* the + denotes both output and input */
  20        asm volatile("bswap %0" : "+r"(x));
  21        return x;
  22}
  23
  24static inline uint64_t byte_swap64(uint64_t x)
  25{
  26        return (uint64_t)(((uint64_t)byte_swap32(x & 0xffffffff) << 32) |
  27                          (byte_swap32(x >> 32)));
  28}
  29