5#ifndef RUNTIME_PLATFORM_UTILS_H_
6#define RUNTIME_PLATFORM_UTILS_H_
22 :
std::unique_ptr<
T, decltype(
std::free)*>(nullptr,
std::free) {}
26 std::unique_ptr<
T,
decltype(std::free)*>::operator=(
value);
77 return ((
x & (
x - 1)) == 0) && (
x != 0);
97 return (
x & (alignment - 1)) ==
offset;
100 template <
typename T>
107 template <
typename T>
110 return (
x & -alignment);
113 template <
typename T>
115 return reinterpret_cast<T*
>(
119 template <
typename T>
127 template <
typename T>
129 return reinterpret_cast<T*
>(
142#if defined(ARCH_IS_64_BIT)
150#if __GNUC__ && !defined(HOST_ARCH_IA32) && !defined(HOST_ARCH_X64)
151 return __builtin_popcountll(
x);
153 x =
x - ((
x >> 1) & 0x5555555555555555);
154 x = (
x & 0x3333333333333333) + ((
x >> 2) & 0x3333333333333333);
155 x = (((
x + (
x >> 4)) & 0x0f0f0f0f0f0f0f0f) * 0x0101010101010101) >> 56;
162#if __GNUC__ && !defined(HOST_ARCH_IA32) && !defined(HOST_ARCH_X64)
163 return __builtin_popcount(
x);
167 x =
x - ((
x >> 1) & 0x55555555);
168 x = (
x & 0x33333333) + ((
x >> 2) & 0x33333333);
169 x = (
x + (
x >> 4)) & 0x0F0F0F0F;
172 return static_cast<int>(
x & 0x0000003F);
186 uint64_t
x =
static_cast<uint64_t
>((v > 0) ? v : -v);
189 if ((t =
x >> 32) != 0) {
193 if ((t =
x >> 16) != 0) {
197 if ((t =
x >> 8) != 0) {
201 if ((t =
x >> 4) != 0) {
205 if ((t =
x >> 2) != 0) {
220#if defined(DART_HOST_OS_WINDOWS)
221 unsigned long position;
222 return (_BitScanReverse(&position,
x) == 0)
224 : 31 -
static_cast<int>(position);
226 return x == 0 ? 32 : __builtin_clz(
x);
230#if defined(DART_HOST_OS_WINDOWS)
231#if defined(ARCH_IS_32_BIT)
232 const uint32_t x_hi =
static_cast<uint32_t
>(
x >> 32);
238 unsigned long position;
239 return (_BitScanReverse64(&position,
x) == 0)
241 : 63 -
static_cast<int>(position);
244 return x == 0 ? 64 : __builtin_clzll(
x);
256#if defined(DART_HOST_OS_WINDOWS)
257 unsigned long position;
258 return (_BitScanForward(&position,
x) == 0) ? 32
259 :
static_cast<int>(position);
261 return x == 0 ? 32 : __builtin_ctz(
x);
265#if defined(DART_HOST_OS_WINDOWS)
266#if defined(ARCH_IS_32_BIT)
267 const uint32_t x_lo =
static_cast<uint32_t
>(
x);
273 unsigned long position;
274 return (_BitScanForward64(&position,
x) == 0) ? 64
275 :
static_cast<int>(position);
278 return x == 0 ? 64 : __builtin_ctzll(
x);
312 template <
typename T>
315 constexpr intptr_t value_size_in_bits =
kBitsPerByte *
sizeof(
T);
317 if (
N >= value_size_in_bits)
return true;
318 const T limit =
static_cast<T>(1) << (
N - 1);
321 if (
N > value_size_in_bits)
return true;
322 const T limit =
static_cast<T>(1) << (
N - 1);
323 return value < limit;
327 template <
typename T>
330 constexpr intptr_t value_size_in_bits =
kBitsPerByte *
sizeof(
T);
332 if (
value < 0)
return false;
333 if (
N >= value_size_in_bits - 1) {
337 if (
N >= value_size_in_bits)
return true;
339 const T limit = (
static_cast<T>(1) <<
N) - 1;
340 return value <= limit;
351 template <
typename T>
362 return static_cast<int32_t
>(
value & 0xffff);
366 return static_cast<int32_t
>(
value >> 16);
370 return static_cast<int32_t
>(
value);
374 return static_cast<int32_t
>(
value >> 32);
378 return (
static_cast<uint64_t
>(high) << 32) | (low & 0x0ffffffffLL);
382 return (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') ||
387 return (
'0' <= c) && (c <=
'9');
392 ((
'a' <= c) && (c <=
'f'));
398 if ((
'A' <= c) && (c <=
'F'))
return 10 + (c -
'A');
399 return 10 + (c -
'a');
404 if (
i < 10)
return static_cast<char>(
'0' +
i);
405 return static_cast<char>(
'A' + (
i - 10));
430 template <
typename T =
int64_t>
434 return static_cast<T>(
static_cast<Unsigned
>(
a) +
static_cast<Unsigned
>(
b));
439 template <
typename T =
int64_t>
443 return static_cast<T>(
static_cast<Unsigned
>(
a) -
static_cast<Unsigned
>(
b));
448 template <
typename T =
int64_t>
452 return static_cast<T>(
static_cast<Unsigned
>(
a) *
static_cast<Unsigned
>(
b));
455 template <
typename T =
int64_t>
459 return static_cast<T>(-
static_cast<Unsigned
>(
a));
470 return static_cast<int64_t
>(
static_cast<uint64_t
>(
a) <<
b);
473 template <
typename T>
482 template <
typename T>
526 return bit_cast<int64_t, double>(
a) == bit_cast<int64_t, double>(
b);
532 template <
typename T>
536 return (
min <= v && v <=
max) ?
static_cast<T>(v)
543 return ((-0x20000000000000LL <=
value) && (
value <= 0x20000000000000LL));
547 template <
typename T = uword>
551 assert(n <=
sizeof(
T) * kBitsPerT);
553 : (
static_cast<Unsigned
>(1) << n) - 1);
556 template <
typename T = uword>
557 static constexpr T Bit(
size_t n) {
563 template <
typename T>
564 static constexpr bool TestBit(
T mask,
size_t position) {
566 return ((mask >> position) & 1) != 0;
569 template <
typename T>
575 return static_cast<T>(BitPosition(bit_));
579 return bits_ == other.bits_ && bit_ == other.bit_;
583 return !(*
this == other);
588 bit_ = bits_ & -bits_;
595 static DART_FORCE_INLINE intptr_t BitPosition(uint32_t bit) {
596#if defined(DART_HOST_OS_WINDOWS)
597 unsigned long position;
598 BitScanForward(&position, bit);
599 return static_cast<int>(position);
601 return __builtin_ctz(bit);
609 template <
typename T>
626 static intptr_t
StrNLen(
const char*
s, intptr_t n);
632 static size_t Read(
int filedes,
void* buf,
size_t nbyte);
666 char**
error =
nullptr);
677 char**
error =
nullptr);
684 char**
error =
nullptr);
686#if defined(DART_HOST_OS_LINUX)
687 static bool IsWindowsSubsystemForLinux();
693#if defined(DART_HOST_OS_ANDROID)
695#elif defined(DART_HOST_OS_FUCHSIA)
697#elif defined(DART_HOST_OS_LINUX)
699#elif defined(DART_HOST_OS_MACOS)
701#elif defined(DART_HOST_OS_WINDOWS)
704#error Unknown target os.
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
CAllocUniquePtr(T *value)
CAllocUniquePtr & operator=(std::nullptr_t value)
DART_FORCE_INLINE BitsIterator & operator++()
BitsIterator(uint32_t bits)
DART_FORCE_INLINE T operator*() const
DART_FORCE_INLINE bool operator==(const BitsIterator &other) const
DART_FORCE_INLINE bool operator!=(const BitsIterator &other) const
BitsIterator< T > begin()
static constexpr bool IsAligned(T *x, uintptr_t alignment, uintptr_t offset=0)
static T AbsWithSaturation(T x)
static uint64_t HostToBigEndian64(uint64_t host_value)
static constexpr T Bit(size_t n)
static bool IsInt(intptr_t N, T value)
static int CountLeadingZeros64(uint64_t x)
static T * RoundUp(T *x, uintptr_t alignment, uintptr_t offset=0)
static bool IsJavaScriptInt(int64_t value)
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
static uint64_t HostToLittleEndian64(uint64_t host_value)
static void CalculateMagicAndShiftForDivRem(int64_t divisor, int64_t *magic, int64_t *shift)
static int HexDigitToInt(char c)
static T MulWithWrapAround(T a, T b)
static void * LoadDynamicLibrary(const char *library_path, char **error=nullptr)
static int32_t Low32Bits(int64_t value)
static int32_t Low16Bits(int32_t value)
static T SafeDoubleToInt(double v)
static uword ReverseBitsWord(uword x)
static constexpr int CountOneBitsWord(uword x)
static constexpr T Maximum(T x, T y)
static int SNPrint(char *str, size_t size, const char *format,...) PRINTF_ATTRIBUTE(3
static bool MagnitudeIsUint(intptr_t N, T value)
static constexpr bool IsDecimalDigit(uint32_t c)
static constexpr int ShiftForPowerOfTwo(T x)
static int CountLeadingZeros32(uint32_t x)
static char * StrDup(const char *s)
static bool StrStartsWith(const char *s, const char *prefix)
static int CountTrailingZeros64(uint64_t x)
static constexpr T NBitMask(size_t n)
static double DivideAllowZero(double a, double b)
static uint64_t LittleEndianToHost64(uint64_t le_value)
static char static char * VSCreate(const char *format, va_list args)
static int CountTrailingZeros32(uint32_t x)
static constexpr bool IsAlphaNumeric(uint32_t c)
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
static int32_t High32Bits(int64_t value)
static uint32_t WordHash(intptr_t key)
static bool WillSubOverflow(int64_t a, int64_t b)
static T Minimum(T x, T y)
static T AddWithWrapAround(T a, T b)
static uint16_t HostToLittleEndian16(uint16_t host_value)
static T RotateLeft(T value, uint8_t rotate)
static T SubWithWrapAround(T a, T b)
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
static size_t Read(int filedes, void *buf, size_t nbyte)
static uint32_t StringHash(const void *data, int length)
static int CountLeadingZerosWord(uword x)
static constexpr size_t BitLength(int64_t value)
static int64_t LowHighTo64Bits(uint32_t low, int32_t high)
static bool WillAddOverflow(int64_t a, int64_t b)
static uint32_t BigEndianToHost32(uint32_t be_value)
static void UnloadDynamicLibrary(void *library_handle, char **error=nullptr)
static intptr_t StrNLen(const char *s, intptr_t n)
static constexpr int CountOneBits32(uint32_t x)
static constexpr bool TestBit(T mask, size_t position)
static char * StrError(int err, char *buffer, size_t bufsize)
static bool IsUint(intptr_t N, T value)
static int Close(int fildes)
static int CountTrailingZerosWord(uword x)
static uint32_t HostToLittleEndian32(uint32_t host_value)
static int Unlink(const char *path)
static T NegWithWrapAround(T a)
static float DivideAllowZero(float a, float b)
static constexpr int CountOneBits64(uint64_t x)
static char IntToHexDigit(int i)
static constexpr T RoundDown(T x, intptr_t alignment)
static bool RangeCheck(intptr_t offset, intptr_t count, intptr_t length)
static int32_t High16Bits(int32_t value)
static char * SCreate(const char *format,...) PRINTF_ATTRIBUTE(1
static void * ResolveSymbolInDynamicLibrary(void *library_handle, const char *symbol, char **error=nullptr)
static constexpr bool IsAligned(T x, uintptr_t alignment, uintptr_t offset=0)
static bool DoublesBitEqual(const double a, const double b)
static T RotateRight(T value, uint8_t rotate)
static int64_t ShiftLeftWithTruncation(int64_t a, int64_t b)
static bool IsHexDigit(char c)
static uint16_t HostToBigEndian16(uint16_t host_value)
static uint32_t HostToBigEndian32(uint32_t host_value)
static constexpr size_t HighestBit(int64_t v)
static uint32_t ReverseBits32(uint32_t x)
static uint64_t ReverseBits64(uint64_t x)
static T * RoundDown(T *x, intptr_t alignment)
static constexpr bool IsPowerOfTwo(T x)
static char * StrNDup(const char *s, intptr_t n)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
static float max(float r, float g, float b)
static float min(float r, float g, float b)
__attribute__((visibility("default"))) int RunBenchmarks(int argc
constexpr int64_t kMaxInt64
constexpr int64_t kMinInt64
constexpr intptr_t kBitsPerByte
static int8_t data[kExtLength]
constexpr intptr_t kBitsPerInt64
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size