blob: 3fdf1847861c9161cfea6507f4c96222dc8f320f [file] [log] [blame]
Damjan Mariond51250f2021-12-22 12:22:59 +01001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
3 */
4#undef BIHASH_TYPE
5#undef BIHASH_KVP_PER_PAGE
6#undef BIHASH_32_64_SVM
7#undef BIHASH_ENABLE_STATS
8#undef BIHASH_KVP_AT_BUCKET_LEVEL
9#undef BIHASH_LAZY_INSTANTIATE
10#undef BIHASH_BUCKET_PREFETCH_CACHE_LINES
11#undef BIHASH_USE_HEAP
12
13#define BIHASH_TYPE _12_4
14#define BIHASH_KVP_PER_PAGE 4
15#define BIHASH_KVP_AT_BUCKET_LEVEL 0
16#define BIHASH_LAZY_INSTANTIATE 1
17#define BIHASH_BUCKET_PREFETCH_CACHE_LINES 1
18#define BIHASH_USE_HEAP 1
19
20#ifndef __included_bihash_12_4_h__
21#define __included_bihash_12_4_h__
22
23#include <vppinfra/crc32.h>
24#include <vppinfra/heap.h>
25#include <vppinfra/format.h>
26#include <vppinfra/pool.h>
27#include <vppinfra/xxhash.h>
28
29typedef union
30{
31 struct
32 {
33 u32 key[3];
34 u32 value;
35 };
36 u64 as_u64[2];
37} clib_bihash_kv_12_4_t;
38
Dave Barachb9c8c572023-03-16 13:03:47 -040039static inline void
40clib_bihash_mark_free_12_4 (clib_bihash_kv_12_4_t *v)
41{
42 v->value = 0xFEEDFACE;
43}
44
Damjan Mariond51250f2021-12-22 12:22:59 +010045static inline int
46clib_bihash_is_free_12_4 (const clib_bihash_kv_12_4_t *v)
47{
Dave Barachb9c8c572023-03-16 13:03:47 -040048 if (v->value == 0xFEEDFACE)
Damjan Mariond51250f2021-12-22 12:22:59 +010049 return 1;
50 return 0;
51}
52
53static inline u64
54clib_bihash_hash_12_4 (const clib_bihash_kv_12_4_t *v)
55{
56#ifdef clib_crc32c_uses_intrinsics
57 return clib_crc32c ((u8 *) v->key, 12);
58#else
59 u64 tmp = v->as_u64[0] ^ v->key[2];
60 return clib_xxhash (tmp);
61#endif
62}
63
64static inline u8 *
65format_bihash_kvp_12_4 (u8 *s, va_list *args)
66{
67 clib_bihash_kv_12_4_t *v = va_arg (*args, clib_bihash_kv_12_4_t *);
68
69 s = format (s, "key %u %u %u value %u", v->key[0], v->key[1], v->key[2],
70 v->value);
71 return s;
72}
73
74static inline int
75clib_bihash_key_compare_12_4 (u32 *a, u32 *b)
76{
77#if defined(CLIB_HAVE_VEC128)
78 u32x4 v = (*(u32x4u *) a) ^ (*(u32x4u *) b);
79 v[3] = 0;
80 return u32x4_is_all_zero (v);
81#else
82 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0;
83#endif
84}
85
86#undef __included_bihash_template_h__
87#include <vppinfra/bihash_template.h>
88
89#endif /* __included_bihash_12_4_h__ */