DPDK  19.08.2
rte_member_x86.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #ifndef _RTE_MEMBER_X86_H_
6 #define _RTE_MEMBER_X86_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <x86intrin.h>
13 
14 #if defined(RTE_MACHINE_CPUFLAG_AVX2)
15 
16 static inline int
17 update_entry_search_avx(uint32_t bucket_id, member_sig_t tmp_sig,
18  struct member_ht_bucket *buckets,
19  member_set_t set_id)
20 {
21  uint32_t hitmask = _mm256_movemask_epi8((__m256i)_mm256_cmpeq_epi16(
22  _mm256_load_si256((__m256i const *)buckets[bucket_id].sigs),
23  _mm256_set1_epi16(tmp_sig)));
24  if (hitmask) {
25  uint32_t hit_idx = __builtin_ctzl(hitmask) >> 1;
26  buckets[bucket_id].sets[hit_idx] = set_id;
27  return 1;
28  }
29  return 0;
30 }
31 
32 static inline int
33 search_bucket_single_avx(uint32_t bucket_id, member_sig_t tmp_sig,
34  struct member_ht_bucket *buckets,
35  member_set_t *set_id)
36 {
37  uint32_t hitmask = _mm256_movemask_epi8((__m256i)_mm256_cmpeq_epi16(
38  _mm256_load_si256((__m256i const *)buckets[bucket_id].sigs),
39  _mm256_set1_epi16(tmp_sig)));
40  while (hitmask) {
41  uint32_t hit_idx = __builtin_ctzl(hitmask) >> 1;
42  if (buckets[bucket_id].sets[hit_idx] != RTE_MEMBER_NO_MATCH) {
43  *set_id = buckets[bucket_id].sets[hit_idx];
44  return 1;
45  }
46  hitmask &= ~(3U << ((hit_idx) << 1));
47  }
48  return 0;
49 }
50 
51 static inline void
52 search_bucket_multi_avx(uint32_t bucket_id, member_sig_t tmp_sig,
53  struct member_ht_bucket *buckets,
54  uint32_t *counter,
55  uint32_t match_per_key,
56  member_set_t *set_id)
57 {
58  uint32_t hitmask = _mm256_movemask_epi8((__m256i)_mm256_cmpeq_epi16(
59  _mm256_load_si256((__m256i const *)buckets[bucket_id].sigs),
60  _mm256_set1_epi16(tmp_sig)));
61  while (hitmask) {
62  uint32_t hit_idx = __builtin_ctzl(hitmask) >> 1;
63  if (buckets[bucket_id].sets[hit_idx] != RTE_MEMBER_NO_MATCH) {
64  set_id[*counter] = buckets[bucket_id].sets[hit_idx];
65  (*counter)++;
66  if (*counter >= match_per_key)
67  return;
68  }
69  hitmask &= ~(3U << ((hit_idx) << 1));
70  }
71 }
72 #endif
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif /* _RTE_MEMBER_X86_H_ */
uint16_t member_set_t
Definition: rte_member.h:58
#define RTE_MEMBER_NO_MATCH
Definition: rte_member.h:60