From d51250f5e2bc99784399b196733e813fef000d71 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 22 Dec 2021 12:22:59 +0100 Subject: [PATCH] vppinfra: add bihash 12_4 template Type: feature Change-Id: I8a6b2c7d7682a01c472d7375d444e8b43eb5db04 Signed-off-by: Damjan Marion --- src/vppinfra/CMakeLists.txt | 1 + src/vppinfra/bihash_12_4.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/vppinfra/bihash_12_4.h diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt index 1a43f25b2c6..b08ebb61e6f 100644 --- a/src/vppinfra/CMakeLists.txt +++ b/src/vppinfra/CMakeLists.txt @@ -105,6 +105,7 @@ set(VPPINFRA_SRCS set(VPPINFRA_HEADERS sanitizer.h + bihash_12_4.h bihash_16_8.h bihash_24_8.h bihash_32_8.h diff --git a/src/vppinfra/bihash_12_4.h b/src/vppinfra/bihash_12_4.h new file mode 100644 index 00000000000..fe050e15924 --- /dev/null +++ b/src/vppinfra/bihash_12_4.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright(c) 2021 Cisco Systems, Inc. + */ +#undef BIHASH_TYPE +#undef BIHASH_KVP_PER_PAGE +#undef BIHASH_32_64_SVM +#undef BIHASH_ENABLE_STATS +#undef BIHASH_KVP_AT_BUCKET_LEVEL +#undef BIHASH_LAZY_INSTANTIATE +#undef BIHASH_BUCKET_PREFETCH_CACHE_LINES +#undef BIHASH_USE_HEAP + +#define BIHASH_TYPE _12_4 +#define BIHASH_KVP_PER_PAGE 4 +#define BIHASH_KVP_AT_BUCKET_LEVEL 0 +#define BIHASH_LAZY_INSTANTIATE 1 +#define BIHASH_BUCKET_PREFETCH_CACHE_LINES 1 +#define BIHASH_USE_HEAP 1 + +#ifndef __included_bihash_12_4_h__ +#define __included_bihash_12_4_h__ + +#include +#include +#include +#include +#include + +typedef union +{ + struct + { + u32 key[3]; + u32 value; + }; + u64 as_u64[2]; +} clib_bihash_kv_12_4_t; + +static inline int +clib_bihash_is_free_12_4 (const clib_bihash_kv_12_4_t *v) +{ + /* Free values are clib_memset to 0xff, check a bit... */ + if (v->as_u64[0] == ~0ULL && v->value == ~0) + return 1; + return 0; +} + +static inline u64 +clib_bihash_hash_12_4 (const clib_bihash_kv_12_4_t *v) +{ +#ifdef clib_crc32c_uses_intrinsics + return clib_crc32c ((u8 *) v->key, 12); +#else + u64 tmp = v->as_u64[0] ^ v->key[2]; + return clib_xxhash (tmp); +#endif +} + +static inline u8 * +format_bihash_kvp_12_4 (u8 *s, va_list *args) +{ + clib_bihash_kv_12_4_t *v = va_arg (*args, clib_bihash_kv_12_4_t *); + + s = format (s, "key %u %u %u value %u", v->key[0], v->key[1], v->key[2], + v->value); + return s; +} + +static inline int +clib_bihash_key_compare_12_4 (u32 *a, u32 *b) +{ +#if defined(CLIB_HAVE_VEC128) + u32x4 v = (*(u32x4u *) a) ^ (*(u32x4u *) b); + v[3] = 0; + return u32x4_is_all_zero (v); +#else + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0; +#endif +} + +#undef __included_bihash_template_h__ +#include + +#endif /* __included_bihash_12_4_h__ */ -- 2.16.6