10#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
11 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
18 x = ((
x >> 32) & 0x00000000ffffffff) | (
x << 32);
19 x = ((
x >> 16) & 0x0000ffff0000ffff) | ((
x & 0x0000ffff0000ffff) << 16);
20 x = ((
x >> 8) & 0x00ff00ff00ff00ff) | ((
x & 0x00ff00ff00ff00ff) << 8);
21 x = ((
x >> 4) & 0x0f0f0f0f0f0f0f0f) | ((
x & 0x0f0f0f0f0f0f0f0f) << 4);
22 x = ((
x >> 2) & 0x3333333333333333) | ((
x & 0x3333333333333333) << 2);
23 x = ((
x >> 1) & 0x5555555555555555) | ((
x & 0x5555555555555555) << 1);
28 x = ((
x >> 16) & 0x0000ffff) | ((
x & 0x0000ffff) << 16);
29 x = ((
x >> 8) & 0x00ff00ff) | ((
x & 0x00ff00ff) << 8);
30 x = ((
x >> 4) & 0x0f0f0f0f) | ((
x & 0x0f0f0f0f) << 4);
31 x = ((
x >> 2) & 0x33333333) | ((
x & 0x33333333) << 2);
32 x = ((
x >> 1) & 0x55555555) | ((
x & 0x55555555) << 1);
42 ASSERT(divisor <= -2 || divisor >= 2);
61 const uint64_t exp = 1LL << 63;
64 uint64_t abs_d = (divisor >= 0) ? divisor : -
static_cast<uint64_t
>(divisor);
65 uint64_t sign_bit =
static_cast<uint64_t
>(divisor) >> 63;
66 uint64_t tmp = exp + sign_bit;
67 uint64_t abs_nc = tmp - 1 - (tmp % abs_d);
68 uint64_t quotient1 = exp / abs_nc;
69 uint64_t remainder1 = exp % abs_nc;
70 uint64_t quotient2 = exp / abs_d;
71 uint64_t remainder2 = exp % abs_d;
79 quotient1 = 2 * quotient1;
80 remainder1 = 2 * remainder1;
81 if (remainder1 >= abs_nc) {
83 remainder1 = remainder1 - abs_nc;
85 quotient2 = 2 * quotient2;
86 remainder2 = 2 * remainder2;
87 if (remainder2 >= abs_d) {
89 remainder2 = remainder2 - abs_d;
91 delta = abs_d - remainder2;
92 }
while (quotient1 < delta || (quotient1 == delta && remainder1 == 0));
94 *magic = (divisor > 0) ? (quotient2 + 1) : (-quotient2 - 1);
105#define MIX(hash, part) \
107 (part) *= kStringHashM; \
108 (part) ^= (part) >> kStringHashR; \
109 (part) *= kStringHashM; \
110 (hash) *= kStringHashM; \
116 uint32_t
hash = size;
118 auto cursor =
reinterpret_cast<const uint8_t*
>(
data);
121 const intptr_t misalignment =
122 reinterpret_cast<intptr_t
>(cursor) %
kInt32Size;
123 if (misalignment > 0) {
126 uint32_t data_window = 0;
133 const intptr_t pre_alignment_length =
kInt32Size - misalignment;
134 switch (pre_alignment_length) {
136 data_window |= cursor[2] << 16;
139 data_window |= cursor[1] << 8;
142 data_window |= cursor[0];
144 cursor += pre_alignment_length;
145 size -= pre_alignment_length;
149 uint32_t aligned_part = *
reinterpret_cast<const uint32_t*
>(cursor);
150 data_window |= (aligned_part << sl);
152 data_window = aligned_part >> sr;
155 if (size >= misalignment) {
158 switch (misalignment) {
160 data_window |= cursor[2] << (16 + sl);
163 data_window |= cursor[1] << (8 + sl);
166 data_window |= cursor[0] << sl;
169 cursor += misalignment;
170 size -= misalignment;
175 data_window |= cursor[1] << (8 + sl);
178 data_window |= cursor[0] << sl;
188 uint32_t part = *
reinterpret_cast<const uint32_t*
>(cursor);
197 hash ^= cursor[2] << 16;
200 hash ^= cursor[1] << 8;
222 a = (
a + 0x7ed55d16) + (
a << 12);
223 a = (
a ^ 0xc761c23c) ^ (
a >> 19);
224 a = (
a + 0x165667b1) + (
a << 5);
225 a = (
a + 0xd3a2646c) ^ (
a << 9);
226 a = (
a + 0xfd7046c5) + (
a << 3);
227 a = (
a ^ 0xb55a4f09) ^ (
a >> 16);
228 return static_cast<uint32_t
>(
a);
241 va_list measure_args;
242 va_copy(measure_args,
args);
244 va_end(measure_args);
246 char*
buffer =
reinterpret_cast<char*
>(
malloc(len + 1));
251 va_copy(print_args,
args);
258 return std::unique_ptr<char,
decltype(std::free)*>{str, std::free};
262 if (
error ==
nullptr)
return;
264#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
265 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
266 const char* status = dlerror();
267 *
error = status !=
nullptr ? strdup(status) :
nullptr;
268#elif defined(DART_HOST_OS_WINDOWS)
271 char* description =
nullptr;
272 int length = FormatMessageA(
273 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
274 FORMAT_MESSAGE_IGNORE_INSERTS,
275 nullptr, status, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
276 reinterpret_cast<char*
>(&description), 0,
nullptr);
284 LocalFree(description);
294 void* handle =
nullptr;
296#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
297 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
298 handle = dlopen(library_path, RTLD_LAZY);
299#elif defined(DART_HOST_OS_WINDOWS)
302 if (library_path ==
nullptr) {
303 handle = GetModuleHandle(
nullptr);
306 const int name_len = MultiByteToWideChar(
307 CP_UTF8, 0, library_path, -1,
nullptr, 0);
309 std::unique_ptr<wchar_t[]>
name(
new wchar_t[name_len]);
310 const int written_len =
311 MultiByteToWideChar(CP_UTF8, 0, library_path,
312 -1,
name.get(), name_len);
314 handle = LoadLibraryW(
name.get());
319 if (handle ==
nullptr) {
331#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
332 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
334 result = dlsym(library_handle, symbol);
339#elif defined(DART_HOST_OS_WINDOWS)
341 result =
reinterpret_cast<void*
>(
342 GetProcAddress(
reinterpret_cast<HMODULE>(library_handle), symbol));
355#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
356 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
357 ok = dlclose(library_handle) == 0;
358#elif defined(DART_HOST_OS_WINDOWS)
361 ok = FreeLibrary(
reinterpret_cast<HMODULE>(library_handle));
static bool ok(int result)
static uint32_t hash(const SkShaderBase::GradientInfo &v)
#define RELEASE_ASSERT(cond)
static void CalculateMagicAndShiftForDivRem(int64_t divisor, int64_t *magic, int64_t *shift)
static void * LoadDynamicLibrary(const char *library_path, char **error=nullptr)
static char * StrDup(const char *s)
static CStringUniquePtr CreateCStringUniquePtr(char *str)
static char static char * VSCreate(const char *format, va_list args)
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
static uint32_t WordHash(intptr_t key)
std::unique_ptr< char, decltype(std::free) * > CStringUniquePtr
static uint32_t StringHash(const void *data, int length)
static void UnloadDynamicLibrary(void *library_handle, char **error=nullptr)
static char * SCreate(const char *format,...) PRINTF_ATTRIBUTE(1
static void * ResolveSymbolInDynamicLibrary(void *library_handle, const char *symbol, char **error=nullptr)
static uint32_t ReverseBits32(uint32_t x)
static uint64_t ReverseBits64(uint64_t x)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
static void GetLastErrorAsString(char **error)
void * malloc(size_t size)
constexpr intptr_t kBitsPerByte
constexpr intptr_t kInt32Size
static constexpr uint32_t kStringHashM
constexpr intptr_t kBitsPerInt32
static int8_t data[kExtLength]
static constexpr int kStringHashR
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)