OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef PLATFORM_UTILS_LINUX_H_ | 5 #ifndef PLATFORM_UTILS_LINUX_H_ |
6 #define PLATFORM_UTILS_LINUX_H_ | 6 #define PLATFORM_UTILS_LINUX_H_ |
7 | 7 |
| 8 #include <endian.h> // NOLINT |
| 9 |
8 namespace dart { | 10 namespace dart { |
9 | 11 |
10 inline int Utils::CountTrailingZeros(uword x) { | 12 inline int Utils::CountTrailingZeros(uword x) { |
11 #if defined(ARCH_IS_32_BIT) | 13 #if defined(ARCH_IS_32_BIT) |
12 return __builtin_ctzl(x); | 14 return __builtin_ctzl(x); |
13 #elif defined(ARCH_IS_64_BIT) | 15 #elif defined(ARCH_IS_64_BIT) |
14 return __builtin_ctzll(x); | 16 return __builtin_ctzll(x); |
15 #else | 17 #else |
16 #error Architecture is not 32-bit or 64-bit. | 18 #error Architecture is not 32-bit or 64-bit. |
17 #endif | 19 #endif |
18 }; | 20 }; |
19 | 21 |
| 22 |
| 23 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { |
| 24 return htobe16(value); |
| 25 } |
| 26 |
| 27 |
| 28 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { |
| 29 return htobe32(value); |
| 30 } |
| 31 |
| 32 |
| 33 inline uint64_t Utils::HostToBigEndian64(uint64_t value) { |
| 34 return htobe64(value); |
| 35 } |
| 36 |
| 37 |
| 38 inline uint16_t Utils::HostToLittleEndian16(uint16_t value) { |
| 39 return htole16(value); |
| 40 } |
| 41 |
| 42 |
| 43 inline uint32_t Utils::HostToLittleEndian32(uint32_t value) { |
| 44 return htole32(value); |
| 45 } |
| 46 |
| 47 |
| 48 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { |
| 49 return htole64(value); |
| 50 } |
| 51 |
20 } // namespace dart | 52 } // namespace dart |
21 | 53 |
22 #endif // PLATFORM_UTILS_LINUX_H_ | 54 #endif // PLATFORM_UTILS_LINUX_H_ |
OLD | NEW |