Flutter Engine
The Flutter Engine
Namespaces | Macros | Functions | Variables
SkChecksum.cpp File Reference
#include "src/core/SkChecksum.h"
#include <cstring>

Go to the source code of this file.

Namespaces

namespace  SkChecksum
 

Macros

#define _likely_(x)   (x)
 
#define _unlikely_(x)   (x)
 

Functions

static void _wymum (uint64_t *A, uint64_t *B)
 
static uint64_t _wymix (uint64_t A, uint64_t B)
 
static uint64_t _wyr8 (const uint8_t *p)
 
static uint64_t _wyr4 (const uint8_t *p)
 
static uint64_t _wyr3 (const uint8_t *p, size_t k)
 
static uint64_t wyhash (const void *key, size_t len, uint64_t seed, const uint64_t *secret)
 
uint32_t SkChecksum::Hash32 (const void *data, size_t bytes, uint32_t seed)
 
uint64_t SkChecksum::Hash64 (const void *data, size_t bytes, uint64_t seed)
 

Variables

static const uint64_t _wyp [4]
 

Macro Definition Documentation

◆ _likely_

#define _likely_ (   x)    (x)

Definition at line 18 of file SkChecksum.cpp.

◆ _unlikely_

#define _unlikely_ (   x)    (x)

Definition at line 19 of file SkChecksum.cpp.

Function Documentation

◆ _wymix()

static uint64_t _wymix ( uint64_t  A,
uint64_t  B 
)
inlinestatic

Definition at line 44 of file SkChecksum.cpp.

44 {
45 _wymum(&A, &B);
46 return A ^ B;
47}
static void _wymum(uint64_t *A, uint64_t *B)
Definition: SkChecksum.cpp:23
#define B

◆ _wymum()

static void _wymum ( uint64_t *  A,
uint64_t *  B 
)
inlinestatic

Definition at line 23 of file SkChecksum.cpp.

23 {
24#if defined(__SIZEOF_INT128__)
25 __uint128_t r = *A;
26 r *= *B;
27 *A = (uint64_t)r;
28 *B = (uint64_t)(r >> 64);
29#elif defined(_MSC_VER) && defined(_M_X64)
30 *A = _umul128(*A, *B, B);
31#else
32 uint64_t ha = *A >> 32, hb = *B >> 32, la = (uint32_t)*A, lb = (uint32_t)*B, hi, lo;
33 uint64_t rh = ha * hb, rm0 = ha * lb, rm1 = hb * la, rl = la * lb, t = rl + (rm0 << 32),
34 c = t < rl;
35 lo = t + (rm1 << 32);
36 c += lo < t;
37 hi = rh + (rm0 >> 32) + (rm1 >> 32) + c;
38 *A = lo;
39 *B = hi;
40#endif
41}

◆ _wyr3()

static uint64_t _wyr3 ( const uint8_t *  p,
size_t  k 
)
inlinestatic

Definition at line 62 of file SkChecksum.cpp.

62 {
63 return (((uint64_t)p[0]) << 16) | (((uint64_t)p[k >> 1]) << 8) | p[k - 1];
64}

◆ _wyr4()

static uint64_t _wyr4 ( const uint8_t *  p)
inlinestatic

Definition at line 56 of file SkChecksum.cpp.

56 {
57 uint32_t v;
58 memcpy(&v, p, 4);
59 return v;
60}

◆ _wyr8()

static uint64_t _wyr8 ( const uint8_t *  p)
inlinestatic

Definition at line 50 of file SkChecksum.cpp.

50 {
51 uint64_t v;
52 memcpy(&v, p, 8);
53 return v;
54}

◆ wyhash()

static uint64_t wyhash ( const void *  key,
size_t  len,
uint64_t  seed,
const uint64_t *  secret 
)
inlinestatic

Definition at line 67 of file SkChecksum.cpp.

67 {
68 const uint8_t* p = (const uint8_t*)key;
69 seed ^= _wymix(seed ^ secret[0], secret[1]);
70 uint64_t a, b;
71 if (_likely_(len <= 16)) {
72 if (_likely_(len >= 4)) {
73 a = (_wyr4(p) << 32) | _wyr4(p + ((len >> 3) << 2));
74 b = (_wyr4(p + len - 4) << 32) | _wyr4(p + len - 4 - ((len >> 3) << 2));
75 } else if (_likely_(len > 0)) {
76 a = _wyr3(p, len);
77 b = 0;
78 } else
79 a = b = 0;
80 } else {
81 size_t i = len;
82 if (_unlikely_(i > 48)) {
83 uint64_t see1 = seed, see2 = seed;
84 do {
85 seed = _wymix(_wyr8(p) ^ secret[1], _wyr8(p + 8) ^ seed);
86 see1 = _wymix(_wyr8(p + 16) ^ secret[2], _wyr8(p + 24) ^ see1);
87 see2 = _wymix(_wyr8(p + 32) ^ secret[3], _wyr8(p + 40) ^ see2);
88 p += 48;
89 i -= 48;
90 } while (_likely_(i > 48));
91 seed ^= see1 ^ see2;
92 }
93 while (_unlikely_(i > 16)) {
94 seed = _wymix(_wyr8(p) ^ secret[1], _wyr8(p + 8) ^ seed);
95 i -= 16;
96 p += 16;
97 }
98 a = _wyr8(p + i - 16);
99 b = _wyr8(p + i - 8);
100 }
101 a ^= secret[1];
102 b ^= seed;
103 _wymum(&a, &b);
104 return _wymix(a ^ secret[0] ^ len, b ^ secret[1]);
105}
#define _unlikely_(x)
Definition: SkChecksum.cpp:19
#define _likely_(x)
Definition: SkChecksum.cpp:18
static uint64_t _wyr4(const uint8_t *p)
Definition: SkChecksum.cpp:56
static uint64_t _wyr3(const uint8_t *p, size_t k)
Definition: SkChecksum.cpp:62
static uint64_t _wymix(uint64_t A, uint64_t B)
Definition: SkChecksum.cpp:44
static uint64_t _wyr8(const uint8_t *p)
Definition: SkChecksum.cpp:50
static bool b
struct MyStruct a[10]

Variable Documentation

◆ _wyp

const uint64_t _wyp[4]
static
Initial value:
= {
0xa0761d6478bd642full, 0xe7037ed1a0b428dbull, 0x8ebc6af09c88c6e3ull, 0x589965cc75374cc3ull}

Definition at line 108 of file SkChecksum.cpp.