Monitor command showmappings updates
[akaros.git] / kern / arch / x86 / endian.h
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 #ifndef ROS_KERN_ARCH_ENDIAN_H
8 #define ROS_KERN_ARCH_ENDIAN_H
9
10 #include <ros/common.h>
11 #include <arch/types.h>
12
13 static inline uint16_t byte_swap16(uint16_t x)
14 {
15         return (uint16_t)(x << 8 | x >> 8);
16 }
17
18 static inline uint32_t byte_swap32(uint32_t x)
19 {
20         /* the + denotes both output and input */
21         asm volatile("bswap %0" : "+r"(x));
22         return x;
23 }
24
25 static inline uint64_t byte_swap64(uint64_t x)
26 {
27         return (uint64_t)(((uint64_t)byte_swap32(x & 0xffffffff) << 32) |
28                           (byte_swap32(x >> 32)));
29 }
30
31 #endif /* ROS_KERN_ARCH_ENDIAN_H */