/* 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 <vppinfra/crc32.h>
#include <vppinfra/heap.h>
#include <vppinfra/format.h>
#include <vppinfra/pool.h>
#include <vppinfra/xxhash.h>

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 <vppinfra/bihash_template.h>

#endif /* __included_bihash_12_4_h__ */
