2016-07-01 19:42:05 +00:00
|
|
|
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|
|
|
|
#define RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|
2016-07-01 19:42:05 +00:00
|
|
|
|
2016-07-29 15:07:25 +00:00
|
|
|
#include <endian.h>
|
2016-07-01 19:42:05 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
inline int Utils::CountLeadingZeros(uword x) {
|
2016-07-18 17:35:03 +00:00
|
|
|
#if defined(ARCH_IS_32_BIT)
|
|
|
|
return __builtin_clzl(x);
|
|
|
|
#elif defined(ARCH_IS_64_BIT)
|
|
|
|
return __builtin_clzll(x);
|
|
|
|
#else
|
|
|
|
#error Architecture is not 32-bit or 64-bit.
|
|
|
|
#endif
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int Utils::CountTrailingZeros(uword x) {
|
2016-07-18 17:35:03 +00:00
|
|
|
#if defined(ARCH_IS_32_BIT)
|
|
|
|
return __builtin_ctzl(x);
|
|
|
|
#elif defined(ARCH_IS_64_BIT)
|
|
|
|
return __builtin_ctzll(x);
|
|
|
|
#else
|
|
|
|
#error Architecture is not 32-bit or 64-bit.
|
|
|
|
#endif
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t Utils::HostToBigEndian16(uint16_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htobe16(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t Utils::HostToBigEndian32(uint32_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htobe32(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t Utils::HostToBigEndian64(uint64_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htobe64(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t Utils::HostToLittleEndian16(uint16_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htole16(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t Utils::HostToLittleEndian32(uint32_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htole32(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t Utils::HostToLittleEndian64(uint64_t value) {
|
2016-07-29 15:07:25 +00:00
|
|
|
return htole64(value);
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline char* Utils::StrError(int err, char* buffer, size_t bufsize) {
|
2016-10-20 20:39:35 +00:00
|
|
|
if (strerror_r(err, buffer, bufsize) != 0) {
|
|
|
|
snprintf(buffer, bufsize, "%s", "strerror_r failed");
|
|
|
|
}
|
2016-07-22 21:00:31 +00:00
|
|
|
return buffer;
|
2016-07-01 19:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|