1cb9cadadSEd Warnicke/*
2cb9cadadSEd Warnicke * Copyright (c) 2015 Cisco and/or its affiliates.
3cb9cadadSEd Warnicke * Licensed under the Apache License, Version 2.0 (the "License");
4cb9cadadSEd Warnicke * you may not use this file except in compliance with the License.
5cb9cadadSEd Warnicke * You may obtain a copy of the License at:
6cb9cadadSEd Warnicke *
7cb9cadadSEd Warnicke *     http://www.apache.org/licenses/LICENSE-2.0
8cb9cadadSEd Warnicke *
9cb9cadadSEd Warnicke * Unless required by applicable law or agreed to in writing, software
10cb9cadadSEd Warnicke * distributed under the License is distributed on an "AS IS" BASIS,
11cb9cadadSEd Warnicke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb9cadadSEd Warnicke * See the License for the specific language governing permissions and
13cb9cadadSEd Warnicke * limitations under the License.
14cb9cadadSEd Warnicke */
15cb9cadadSEd Warnicke#undef BIHASH_TYPE
16908a5ea6SDave Barach#undef BIHASH_KVP_PER_PAGE
172ce28d60SDave Barach#undef BIHASH_32_64_SVM
182ce28d60SDave Barach#undef BIHASH_ENABLE_STATS
1916e4a4a0SDave Barach#undef BIHASH_KVP_AT_BUCKET_LEVEL
2016e4a4a0SDave Barach#undef BIHASH_LAZY_INSTANTIATE
2116e4a4a0SDave Barach#undef BIHASH_BUCKET_PREFETCH_CACHE_LINES
22cb9cadadSEd Warnicke
23cb9cadadSEd Warnicke#define BIHASH_TYPE _24_8
24cb9cadadSEd Warnicke#define BIHASH_KVP_PER_PAGE 4
2516e4a4a0SDave Barach#define BIHASH_KVP_AT_BUCKET_LEVEL 0
2616e4a4a0SDave Barach#define BIHASH_LAZY_INSTANTIATE 1
2716e4a4a0SDave Barach#define BIHASH_BUCKET_PREFETCH_CACHE_LINES 1
28cb9cadadSEd Warnicke
29cb9cadadSEd Warnicke#ifndef __included_bihash_24_8_h__
30cb9cadadSEd Warnicke#define __included_bihash_24_8_h__
31cb9cadadSEd Warnicke
32b4bd28a4SChristophe Fontaine#include <vppinfra/crc32.h>
33cb9cadadSEd Warnicke#include <vppinfra/heap.h>
34cb9cadadSEd Warnicke#include <vppinfra/format.h>
35cb9cadadSEd Warnicke#include <vppinfra/pool.h>
36cb9cadadSEd Warnicke#include <vppinfra/xxhash.h>
37cb9cadadSEd Warnicke
38c3799996SDave Barachtypedef struct
39c3799996SDave Barach{
40cb9cadadSEd Warnicke  u64 key[3];
41cb9cadadSEd Warnicke  u64 value;
42cb9cadadSEd Warnicke} clib_bihash_kv_24_8_t;
43cb9cadadSEd Warnicke
44c3799996SDave Barachstatic inline int
450bfe5d8cSNeale Rannsclib_bihash_is_free_24_8 (const clib_bihash_kv_24_8_t * v)
46cb9cadadSEd Warnicke{
47b7b92993SDave Barach  /* Free values are clib_memset to 0xff, check a bit... */
48cb9cadadSEd Warnicke  if (v->key[0] == ~0ULL && v->value == ~0ULL)
49cb9cadadSEd Warnicke    return 1;
50cb9cadadSEd Warnicke  return 0;
51cb9cadadSEd Warnicke}
52cb9cadadSEd Warnicke
53c3799996SDave Barachstatic inline u64
540bfe5d8cSNeale Rannsclib_bihash_hash_24_8 (const clib_bihash_kv_24_8_t * v)
55cb9cadadSEd Warnicke{
56b4bd28a4SChristophe Fontaine#ifdef clib_crc32c_uses_intrinsics
570f68c79aSDamjan Marion  return clib_crc32c ((u8 *) v->key, 24);
58c3799996SDave Barach#else
59cb9cadadSEd Warnicke  u64 tmp = v->key[0] ^ v->key[1] ^ v->key[2];
60cb9cadadSEd Warnicke  return clib_xxhash (tmp);
61cb9cadadSEd Warnicke#endif
62c967a823SDamjan Marion}
63cb9cadadSEd Warnicke
64c3799996SDave Barachstatic inline u8 *
65c3799996SDave Barachformat_bihash_kvp_24_8 (u8 * s, va_list * args)
66cb9cadadSEd Warnicke{
67c3799996SDave Barach  clib_bihash_kv_24_8_t *v = va_arg (*args, clib_bihash_kv_24_8_t *);
68cb9cadadSEd Warnicke
69c3799996SDave Barach  s = format (s, "key %llu %llu %llu value %llu",
70c3799996SDave Barach	      v->key[0], v->key[1], v->key[2], v->value);
71cb9cadadSEd Warnicke  return s;
72cb9cadadSEd Warnicke}
73cb9cadadSEd Warnicke
74c3799996SDave Barachstatic inline int
751cf9a165SDamjan Marionclib_bihash_key_compare_24_8 (u64 * a, u64 * b)
76cb9cadadSEd Warnicke{
771cf9a165SDamjan Marion#if defined (CLIB_HAVE_VEC512)
781cf9a165SDamjan Marion  u64x8 v = u64x8_load_unaligned (a) ^ u64x8_load_unaligned (b);
791cf9a165SDamjan Marion  return (u64x8_is_zero_mask (v) & 0x7) == 0;
801cf9a165SDamjan Marion#elif defined(CLIB_HAVE_VEC128) && defined(CLIB_HAVE_VEC128_UNALIGNED_LOAD_STORE)
8109fdf9d0SDamjan Marion  u64x2 v = { a[2] ^ b[2], 0 };
8209fdf9d0SDamjan Marion  v |= u64x2_load_unaligned (a) ^ u64x2_load_unaligned (b);
831cf9a165SDamjan Marion  return u64x2_is_all_zero (v);
841cf9a165SDamjan Marion#else
85c3799996SDave Barach  return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0;
861cf9a165SDamjan Marion#endif
87cb9cadadSEd Warnicke}
88c3799996SDave Barach
89cb9cadadSEd Warnicke#undef __included_bihash_template_h__
90cb9cadadSEd Warnicke#include <vppinfra/bihash_template.h>
91cb9cadadSEd Warnicke
92cb9cadadSEd Warnicke#endif /* __included_bihash_24_8_h__ */
93c3799996SDave Barach
94c3799996SDave Barach/*
95c3799996SDave Barach * fd.io coding-style-patch-verification: ON
96c3799996SDave Barach *
97c3799996SDave Barach * Local Variables:
98c3799996SDave Barach * eval: (c-set-style "gnu")
99c3799996SDave Barach * End:
100c3799996SDave Barach */
101