FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
cuckoo_16_8.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #undef CLIB_CUCKOO_TYPE
16 
17 #define CLIB_CUCKOO_TYPE _16_8
18 #define CLIB_CUCKOO_KVP_PER_BUCKET (4)
19 #define CLIB_CUCKOO_LOG2_KVP_PER_BUCKET (2)
20 #define CLIB_CUCKOO_BFS_MAX_STEPS (2000)
21 #define CLIB_CUCKOO_BFS_MAX_PATH_LENGTH (8)
22 
23 #ifndef __included_cuckoo_16_8_h__
24 #define __included_cuckoo_16_8_h__
25 
26 #include <vppinfra/heap.h>
27 #include <vppinfra/format.h>
28 #include <vppinfra/pool.h>
29 #include <vppinfra/xxhash.h>
30 #include <vppinfra/cuckoo_debug.h>
31 #include <vppinfra/cuckoo_common.h>
32 
33 #undef CLIB_CUCKOO_OPTIMIZE_PREFETCH
34 #undef CLIB_CUCKOO_OPTIMIZE_UNROLL
35 #undef CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH
36 #define CLIB_CUCKOO_OPTIMIZE_PREFETCH 1
37 #define CLIB_CUCKOO_OPTIMIZE_UNROLL 1
38 #define CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH 1
39 
40 #if __SSE4_2__ && !defined (__i386__)
41 #include <x86intrin.h>
42 #endif
43 
44 /** 8 octet key, 8 octet key value pair */
45 typedef struct
46 {
47  u64 key[2]; /**< the key */
48  u64 value; /**< the value */
50 
51 /** Decide if a clib_cuckoo_kv_16_8_t instance is free
52  @param v- pointer to the (key,value) pair
53 */
54 always_inline int
56 {
57  if (v->key[0] == ~0ULL && v->value == ~0ULL)
58  return 1;
59  return 0;
60 }
61 
62 always_inline void
64 {
65  clib_memset (v, 0xff, sizeof (*v));
66 }
67 
68 /** Format a clib_cuckoo_kv_16_8_t instance
69  @param s - u8 * vector under construction
70  @param args (vararg) - the (key,value) pair to format
71  @return s - the u8 * vector under construction
72 */
74 format_cuckoo_kvp_16_8 (u8 * s, va_list * args)
75 {
76  clib_cuckoo_kv_16_8_t *v = va_arg (*args, clib_cuckoo_kv_16_8_t *);
77 
79  {
80  s = format (s, " -- empty -- ");
81  }
82  else
83  {
84  s =
85  format (s, "key %llu%llu value %llu", v->key[0], v->key[1], v->value);
86  }
87  return s;
88 }
89 
92 {
93 #ifdef clib_crc32c_uses_intrinsics
94  return clib_crc32c ((u8 *) v->key, 16);
95 #else
96  u64 tmp = v->key[0] ^ v->key[1];
97  return clib_xxhash (tmp);
98 #endif
99 }
100 
101 /** Compare two clib_cuckoo_kv_16_8_t instances
102  @param a - first key
103  @param b - second key
104 */
105 always_inline int
107 {
108 #if defined(CLIB_HAVE_VEC128) && defined(CLIB_HAVE_VEC128_UNALIGNED_LOAD_STORE)
109  u64x2 v;
110  v = u64x2_load_unaligned (a) ^ u64x2_load_unaligned (b);
111  return u64x2_is_all_zero (v);
112 #else
113  return ((a[0] ^ b[0]) | (a[1] ^ b[1])) == 0;
114 #endif
115 }
116 
117 #undef __included_cuckoo_template_h__
119 
120 #endif /* __included_cuckoo_16_8_h__ */
121 
122 /*
123  * fd.io coding-style-patch-verification: ON
124  *
125  * Local Variables:
126  * eval: (c-set-style "gnu")
127  * End:
128  */
tmp
u32 * tmp
Definition: interface_output.c:1078
clib_cuckoo_kv_16_8_t::value
u64 value
the value
Definition: cuckoo_16_8.h:48
clib_cuckoo_kv_is_free_16_8
static int clib_cuckoo_kv_is_free_16_8(const clib_cuckoo_kv_16_8_t *v)
Decide if a clib_cuckoo_kv_16_8_t instance is free.
Definition: cuckoo_16_8.h:55
clib_cuckoo_kv_16_8_t
8 octet key, 8 octet key value pair
Definition: cuckoo_16_8.h:45
u64x2
epu8_epi32 epu16_epi32 u64x2
Definition: vector_sse42.h:641
cuckoo_template.h
format_cuckoo_kvp_16_8
static u8 * format_cuckoo_kvp_16_8(u8 *s, va_list *args)
Format a clib_cuckoo_kv_16_8_t instance.
Definition: cuckoo_16_8.h:74
key
typedef key
Definition: ipsec_types.api:88
clib_cuckoo_kv_16_8_t::key
u64 key[2]
the key
Definition: cuckoo_16_8.h:47
cuckoo_debug.h
cuckoo debugs
clib_cuckoo_kv_set_free_16_8
static void clib_cuckoo_kv_set_free_16_8(clib_cuckoo_kv_16_8_t *v)
Definition: cuckoo_16_8.h:63
pool.h
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
clib_cuckoo_key_compare_16_8
static int clib_cuckoo_key_compare_16_8(u64 *a, u64 *b)
Compare two clib_cuckoo_kv_16_8_t instances.
Definition: cuckoo_16_8.h:106
format.h
clib_xxhash
static u64 clib_xxhash(u64 key)
Definition: xxhash.h:58
xxhash.h
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
clib_cuckoo_hash_16_8
static u64 clib_cuckoo_hash_16_8(clib_cuckoo_kv_16_8_t *v)
Definition: cuckoo_16_8.h:91
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:544
cuckoo_common.h
heap.h