| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // This header defines cross-platform ByteSwap() implementations for 16, 32 and | 5 // This header defines cross-platform ByteSwap() implementations for 16, 32 and | 
| 6 // 64-bit values, and NetToHostXX() / HostToNextXX() functions equivalent to | 6 // 64-bit values, and NetToHostXX() / HostToNextXX() functions equivalent to | 
| 7 // the traditional ntohX() and htonX() functions. | 7 // the traditional ntohX() and htonX() functions. | 
| 8 // Use the functions defined here rather than using the platform-specific | 8 // Use the functions defined here rather than using the platform-specific | 
| 9 // functions directly. | 9 // functions directly. | 
| 10 | 10 | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 39 } | 39 } | 
| 40 | 40 | 
| 41 inline uint64_t ByteSwap(uint64_t x) { | 41 inline uint64_t ByteSwap(uint64_t x) { | 
| 42 #if defined(COMPILER_MSVC) | 42 #if defined(COMPILER_MSVC) | 
| 43   return _byteswap_uint64(x); | 43   return _byteswap_uint64(x); | 
| 44 #else | 44 #else | 
| 45   return __builtin_bswap64(x); | 45   return __builtin_bswap64(x); | 
| 46 #endif | 46 #endif | 
| 47 } | 47 } | 
| 48 | 48 | 
|  | 49 inline uintptr_t ByteSwapUintPtrT(uintptr_t x) { | 
|  | 50 #if defined(ARCH_CPU_64_BITS) | 
|  | 51   return ByteSwap(static_cast<uint64_t>(x)); | 
|  | 52 #elif defined(ARCH_CPU_32_BITS) | 
|  | 53   return ByteSwap(static_cast<uint32_t>(x)); | 
|  | 54 #else | 
|  | 55 #error architecture not supported | 
|  | 56 #endif | 
|  | 57 } | 
|  | 58 | 
| 49 // Converts the bytes in |x| from host order (endianness) to little endian, and | 59 // Converts the bytes in |x| from host order (endianness) to little endian, and | 
| 50 // returns the result. | 60 // returns the result. | 
| 51 inline uint16_t ByteSwapToLE16(uint16_t x) { | 61 inline uint16_t ByteSwapToLE16(uint16_t x) { | 
| 52 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 62 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 
| 53   return x; | 63   return x; | 
| 54 #else | 64 #else | 
| 55   return ByteSwap(x); | 65   return ByteSwap(x); | 
| 56 #endif | 66 #endif | 
| 57 } | 67 } | 
| 58 inline uint32_t ByteSwapToLE32(uint32_t x) { | 68 inline uint32_t ByteSwapToLE32(uint32_t x) { | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 114 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 124 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 
| 115   return ByteSwap(x); | 125   return ByteSwap(x); | 
| 116 #else | 126 #else | 
| 117   return x; | 127   return x; | 
| 118 #endif | 128 #endif | 
| 119 } | 129 } | 
| 120 | 130 | 
| 121 }  // namespace base | 131 }  // namespace base | 
| 122 | 132 | 
| 123 #endif  // BASE_SYS_BYTEORDER_H_ | 133 #endif  // BASE_SYS_BYTEORDER_H_ | 
| OLD | NEW | 
|---|