Deleted Added
sdiff udiff text old ( 2665:a124942bacb8 ) new ( 2764:e6fea7527b3c )
full compact
1/*
2 * Copyright (c) 2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 76 unchanged lines hidden (view full) ---

85#if defined(linux)
86 return bswap_16(x);
87#else
88 return (uint16_t)(((uint16_t)(x) & 0xff) << 8 |
89 ((uint16_t)(x) & 0xff00) >> 8);
90#endif
91}
92
93// This function lets the compiler figure out how to call the
94// swap_byte functions above for different data types. Since the
95// sizeof() values are known at compiel time, it should inline to a
96// direct call to the right swap_byteNN() function.
97template <typename T>
98static inline T swap_byte(T x) {
99 if (sizeof(T) == 8)
100 return swap_byte64((uint64_t)x);
101 else if (sizeof(T) == 4)
102 return swap_byte32((uint32_t)x);
103 else if (sizeof(T) == 2)
104 return swap_byte16((uint16_t)x);
105 else if (sizeof(T) == 1)
106 return x;
107 else
108 panic("Can't byte-swap values larger than 64 bits");
109}
110
111//The conversion functions with fixed endianness on both ends don't need to
112//be in a namespace
113template <typename T> static inline T betole(T value) {return swap_byte(value);}
114template <typename T> static inline T letobe(T value) {return swap_byte(value);}
115
116//For conversions not involving the guest system, we can define the functions
117//conditionally based on the BYTE_ORDER macro and outside of the namespaces

--- 46 unchanged lines hidden ---