Hello
Hello World
1auto insert_64(T* data, size_t count) -> void {
2 auto tmp_idx = m_idx_buffer;
3 auto idx_size = count;
4 auto per_ins = 512 / 8 / sizeof(T); // = 8
5 size_t i = 0, j = 0;
6
7 __m512i voffset = _mm512_set1_epi64(0);
8 __mmask8 reversed_mask = 0;
9 __mmask8 mask = ~reversed_mask;
10 __m512i vkey = _mm512_set1_epi64(0);
11 __m512i vval = _mm512_set1_epi64(0);
12 for (i = 0; i + _mm_popcnt_u32((uint32_t)(mask)) <= idx_size;) {
13 // vkey = _mm512_mask_expandloadu_epi64(vkey, mask, data + i);
14 vval = _mm512_mask_expandloadu_epi64(vval, mask, tmp_idx + i);
15 vkey = _mm512_i64gather_epi64(vval, data, 8);
16 i += _mm_popcnt_u32((uint32_t)mask);
17
18 __m512i vhash_val = hash_key_512(vkey, m_size);
19 vhash_val = _mm512_add_epi64(vhash_val, voffset);
20 vhash_val = _mm512_and_si512(vhash_val, _mm512_set1_epi64(m_size - 1));
21
22 __m512i vkey_table = _mm512_i64gather_epi64(vhash_val, m_hash_key, 8); // 8 is the size of T
23 mask = _mm512_cmpeq_epi64_mask(vkey_table, _mm512_set1_epi64(INT64_MAX)); // empty
24
25 // deal with comflict
26 __m512i con = _mm512_conflict_epi64(vhash_val);
27 __m512i con_2 = _mm512_conflict_epi64(vkey); // when keys are equal, we do not need to deal with it
28 mask = _mm512_mask_testn_epi64_mask(mask, con, con)
29 | _mm512_mask_test_epi64_mask(mask, con_2, con_2);
30
31 // check if the key is equal to the key in the hash table
32 mask = mask | _mm512_cmpeq_epi64_mask(vkey, vkey_table);
33
34 // write to hash table
35 _mm512_mask_i64scatter_epi64(m_hash_key, mask, vhash_val, vkey, 8);
36 for (j = 0; j < per_ins; j++) {
37 if (mask & (1 << j)) {
38 m_hash_bucket[vhash_val[j]] = m_hash_bucket[vhash_val[j]]->insert(vval[j]);
39 }
40 }
41
42 reversed_mask = ~mask;
43 // if the reversed mask is 0, means adding success, set the corresponding voffset to 0
44 // otherwise, add failed, add the corresponding voffset by 1
45 voffset = _mm512_maskz_add_epi64(reversed_mask, voffset, _mm512_set1_epi64(1));
46 }
47
48 // ...
49}
Italics | Bold | Code |
---|---|---|
italics | bold | code |
$$ \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } $$
$$ \begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} ax + by \\ cx + dy \end{pmatrix} $$
$$ f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases} $$
$$ \begin{align} f(x) &= x^2 + 2x + 1 \\ &= (x + 1)^2 \end{align} $$
- Greek Letters:$\alpha, \beta, \gamma, \delta, \epsilon, \phi, \psi, \omega$
- Summation:$\sum_{i=1}^{n} x_i$
- Integration:$\int_0^1 f(x) dx$
- Limit:$\lim_{x \to \infty} \frac{1}{x} = 0$