Deleted Added
sdiff udiff text old ( 2772:f0f52cbe744d ) new ( 2777:599e7940aba5 )
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;

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

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

--- 46 unchanged lines hidden ---