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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #undef CLIB_CUCKOO_TYPE
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)
23 #ifndef __included_cuckoo_16_8_h__
24 #define __included_cuckoo_16_8_h__
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>
33 #undef CLIB_CUCKOO_OPTIMIZE_PREFETCH
34 #undef CLIB_CUCKOO_OPTIMIZE_CMP_REDUCED_HASH
35 #undef CLIB_CUCKOO_OPTIMIZE_UNROLL
36 #undef CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH
37 #define CLIB_CUCKOO_OPTIMIZE_PREFETCH 1
38 #define CLIB_CUCKOO_OPTIMIZE_CMP_REDUCED_HASH 1
39 #define CLIB_CUCKOO_OPTIMIZE_UNROLL 1
40 #define CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH 1
42 #if __SSE4_2__ && !defined (__i386__)
43 #include <x86intrin.h>
46 /** 8 octet key, 8 octet key value pair */
49 u64 key[2]; /**< the key */
50 u64 value; /**< the value */
51 } clib_cuckoo_kv_16_8_t;
53 /** Decide if a clib_cuckoo_kv_16_8_t instance is free
54 @param v- pointer to the (key,value) pair
57 clib_cuckoo_kv_is_free_16_8 (const clib_cuckoo_kv_16_8_t * v)
59 if (v->key[0] == ~0ULL && v->value == ~0ULL)
65 clib_cuckoo_kv_set_free_16_8 (clib_cuckoo_kv_16_8_t * v)
67 clib_memset (v, 0xff, sizeof (*v));
70 /** Format a clib_cuckoo_kv_16_8_t instance
71 @param s - u8 * vector under construction
72 @param args (vararg) - the (key,value) pair to format
73 @return s - the u8 * vector under construction
76 format_cuckoo_kvp_16_8 (u8 * s, va_list * args)
78 clib_cuckoo_kv_16_8_t *v = va_arg (*args, clib_cuckoo_kv_16_8_t *);
80 if (clib_cuckoo_kv_is_free_16_8 (v))
82 s = format (s, " -- empty -- ");
87 format (s, "key %llu%llu value %llu", v->key[0], v->key[1], v->value);
93 clib_cuckoo_hash_16_8 (clib_cuckoo_kv_16_8_t * v)
95 #ifdef clib_crc32c_uses_intrinsics
96 return clib_crc32c ((u8 *) v->key, 16);
98 u64 tmp = v->key[0] ^ v->key[1];
99 return clib_xxhash (tmp);
103 /** Compare two clib_cuckoo_kv_16_8_t instances
105 @param b - second key
108 clib_cuckoo_key_compare_16_8 (u64 * a, u64 * b)
110 #if defined(CLIB_HAVE_VEC128) && defined(CLIB_HAVE_VEC128_UNALIGNED_LOAD_STORE)
112 v = u64x2_load_unaligned (a) ^ u64x2_load_unaligned (b);
113 return u64x2_is_all_zero (v);
115 return ((a[0] ^ b[0]) | (a[1] ^ b[1])) == 0;
119 #undef __included_cuckoo_template_h__
120 #include <vppinfra/cuckoo_template.h>
122 #endif /* __included_cuckoo_16_8_h__ */
125 * fd.io coding-style-patch-verification: ON
128 * eval: (c-set-style "gnu")