Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: base/sys_byteorder.h

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Remove PRETTY_FUNCTION, and fix (?) ByteSwap for uintptr_t on macOS/iOS. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
gab 2016/12/06 15:43:21 Add a test to sys_byteorder_unittest.cc
palmer 2016/12/06 21:47:41 Done.
50 #if defined(ARCH_CPU_64_BITS)
51 return ByteSwap(static_cast<uint64_t>(x));
52 #else
gab 2016/12/06 15:43:21 Make this a #elif and have a #error Unsupported t
palmer 2016/12/06 21:47:41 Done.
53 return ByteSwap(static_cast<uint32_t>(x));
54 #endif
55 }
56
49 // Converts the bytes in |x| from host order (endianness) to little endian, and 57 // Converts the bytes in |x| from host order (endianness) to little endian, and
50 // returns the result. 58 // returns the result.
51 inline uint16_t ByteSwapToLE16(uint16_t x) { 59 inline uint16_t ByteSwapToLE16(uint16_t x) {
52 #if defined(ARCH_CPU_LITTLE_ENDIAN) 60 #if defined(ARCH_CPU_LITTLE_ENDIAN)
53 return x; 61 return x;
54 #else 62 #else
55 return ByteSwap(x); 63 return ByteSwap(x);
56 #endif 64 #endif
57 } 65 }
58 inline uint32_t ByteSwapToLE32(uint32_t x) { 66 inline uint32_t ByteSwapToLE32(uint32_t x) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #if defined(ARCH_CPU_LITTLE_ENDIAN) 122 #if defined(ARCH_CPU_LITTLE_ENDIAN)
115 return ByteSwap(x); 123 return ByteSwap(x);
116 #else 124 #else
117 return x; 125 return x;
118 #endif 126 #endif
119 } 127 }
120 128
121 } // namespace base 129 } // namespace base
122 130
123 #endif // BASE_SYS_BYTEORDER_H_ 131 #endif // BASE_SYS_BYTEORDER_H_
OLDNEW
« base/logging.h ('K') | « base/logging.h ('k') | docs/memory-infra/README.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698