OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_FUCHSIA_H_ | 5 #ifndef PLATFORM_UTILS_FUCHSIA_H_ |
6 #define PLATFORM_UTILS_FUCHSIA_H_ | 6 #define PLATFORM_UTILS_FUCHSIA_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include <endian.h> |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 inline int Utils::CountLeadingZeros(uword x) { | 12 inline int Utils::CountLeadingZeros(uword x) { |
13 #if defined(ARCH_IS_32_BIT) | 13 #if defined(ARCH_IS_32_BIT) |
14 return __builtin_clzl(x); | 14 return __builtin_clzl(x); |
15 #elif defined(ARCH_IS_64_BIT) | 15 #elif defined(ARCH_IS_64_BIT) |
16 return __builtin_clzll(x); | 16 return __builtin_clzll(x); |
17 #else | 17 #else |
18 #error Architecture is not 32-bit or 64-bit. | 18 #error Architecture is not 32-bit or 64-bit. |
19 #endif | 19 #endif |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 inline int Utils::CountTrailingZeros(uword x) { | 23 inline int Utils::CountTrailingZeros(uword x) { |
24 #if defined(ARCH_IS_32_BIT) | 24 #if defined(ARCH_IS_32_BIT) |
25 return __builtin_ctzl(x); | 25 return __builtin_ctzl(x); |
26 #elif defined(ARCH_IS_64_BIT) | 26 #elif defined(ARCH_IS_64_BIT) |
27 return __builtin_ctzll(x); | 27 return __builtin_ctzll(x); |
28 #else | 28 #else |
29 #error Architecture is not 32-bit or 64-bit. | 29 #error Architecture is not 32-bit or 64-bit. |
30 #endif | 30 #endif |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { | 34 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { |
35 UNIMPLEMENTED(); | 35 return htobe16(value); |
36 return 0; | |
37 } | 36 } |
38 | 37 |
39 | 38 |
40 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { | 39 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { |
41 UNIMPLEMENTED(); | 40 return htobe32(value); |
42 return 0; | |
43 } | 41 } |
44 | 42 |
45 | 43 |
46 inline uint64_t Utils::HostToBigEndian64(uint64_t value) { | 44 inline uint64_t Utils::HostToBigEndian64(uint64_t value) { |
47 UNIMPLEMENTED(); | 45 return htobe64(value); |
48 return 0; | |
49 } | 46 } |
50 | 47 |
51 | 48 |
52 inline uint16_t Utils::HostToLittleEndian16(uint16_t value) { | 49 inline uint16_t Utils::HostToLittleEndian16(uint16_t value) { |
53 UNIMPLEMENTED(); | 50 return htole16(value); |
54 return 0; | |
55 } | 51 } |
56 | 52 |
57 | 53 |
58 inline uint32_t Utils::HostToLittleEndian32(uint32_t value) { | 54 inline uint32_t Utils::HostToLittleEndian32(uint32_t value) { |
59 UNIMPLEMENTED(); | 55 return htole32(value); |
60 return 0; | |
61 } | 56 } |
62 | 57 |
63 | 58 |
64 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { | 59 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { |
65 UNIMPLEMENTED(); | 60 return htole64(value); |
66 return 0; | |
67 } | 61 } |
68 | 62 |
69 | 63 |
70 inline char* Utils::StrError(int err, char* buffer, size_t bufsize) { | 64 inline char* Utils::StrError(int err, char* buffer, size_t bufsize) { |
71 snprintf(buffer, bufsize, "errno = %d", err); | 65 snprintf(buffer, bufsize, "errno = %d", err); |
72 return buffer; | 66 return buffer; |
73 } | 67 } |
74 | 68 |
75 } // namespace dart | 69 } // namespace dart |
76 | 70 |
77 #endif // PLATFORM_UTILS_FUCHSIA_H_ | 71 #endif // PLATFORM_UTILS_FUCHSIA_H_ |
OLD | NEW |