aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/vector_avx512.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-11-05 20:44:09 +0100
committerFlorin Coras <florin.coras@gmail.com>2021-11-08 20:44:03 +0000
commit7459be1b3626b608e60df574343a1432a068ebce (patch)
tree9e7419383fb0ead8071f9fe8ac23076c16d26f79 /src/vppinfra/vector_avx512.h
parent1e26724dce437566fb645374d41f7b18a7199937 (diff)
vppinfra: AVX512 in clib_count_equal_*
Type: improvement Change-Id: I8105d396cfc984e00cf5137bc57122510f5e6437 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/vector_avx512.h')
-rw-r--r--src/vppinfra/vector_avx512.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vppinfra/vector_avx512.h b/src/vppinfra/vector_avx512.h
index a82231ac025..1a5c2528bf7 100644
--- a/src/vppinfra/vector_avx512.h
+++ b/src/vppinfra/vector_avx512.h
@@ -301,6 +301,27 @@ _ (u32x16, u16, epu32, _mm512, __m512i)
_ (u64x8, u8, epu64, _mm512, __m512i)
#undef _
+#define _(t, m, e, p, it) \
+ static_always_inline m t##_is_not_equal_mask (t a, t b) \
+ { \
+ return p##_cmpneq_##e##_mask ((it) a, (it) b); \
+ }
+_ (u8x16, u16, epu8, _mm, __m128i)
+_ (u16x8, u8, epu16, _mm, __m128i)
+_ (u32x4, u8, epu32, _mm, __m128i)
+_ (u64x2, u8, epu64, _mm, __m128i)
+
+_ (u8x32, u32, epu8, _mm256, __m256i)
+_ (u16x16, u16, epu16, _mm256, __m256i)
+_ (u32x8, u8, epu32, _mm256, __m256i)
+_ (u64x4, u8, epu64, _mm256, __m256i)
+
+_ (u8x64, u64, epu8, _mm512, __m512i)
+_ (u16x32, u32, epu16, _mm512, __m512i)
+_ (u32x16, u16, epu32, _mm512, __m512i)
+_ (u64x8, u8, epu64, _mm512, __m512i)
+#undef _
+
#define _(f, t, fn, it) \
static_always_inline t t##_from_##f (f x) { return (t) fn ((it) x); }
_ (u16x16, u32x16, _mm512_cvtepi16_epi32, __m256i)
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
/*
 * nhrp.h: next-hop resolution
 *
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <vnet/nhrp/nhrp.h>
#include <vnet/fib/fib_table.h>
#include <vnet/adj/adj_midchain.h>

typedef struct nhrp_key_t_
{
  ip46_address_t nk_peer;
  u32 nk_sw_if_index;
} nhrp_key_t;

struct nhrp_entry_t_
{
  nhrp_key_t *ne_key;
  fib_prefix_t ne_nh;
  u32 ne_fib_index;
};

static uword *nhrp_db;
static nhrp_entry_t *nhrp_pool;
static nhrp_vft_t *nhrp_vfts;

#define NHRP_NOTIFY(_ne, _fn) {                 \
  nhrp_vft_t *_vft;                             \
  vec_foreach(_vft, nhrp_vfts) {                \
    if (_vft->_fn) {                             \
      _vft->_fn(_ne);                            \
    }                                           \
  }                                             \
}

u32
nhrp_entry_get_sw_if_index (const nhrp_entry_t * ne)
{
  return (ne->ne_key->nk_sw_if_index);
}

u32
nhrp_entry_get_fib_index (const nhrp_entry_t * ne)
{
  return (ne->ne_fib_index);
}

const ip46_address_t *
nhrp_entry_get_peer (const nhrp_entry_t * ne)
{
  return (&ne->ne_key->nk_peer);
}

const fib_prefix_t *
nhrp_entry_get_nh (const nhrp_entry_t * ne)
{
  return (&ne->ne_nh);
}

void
nhrp_entry_adj_stack (const nhrp_entry_t * ne, adj_index_t ai)
{
  adj_midchain_delegate_stack (ai, ne->ne_fib_index, &ne->ne_nh);
}

nhrp_entry_t *
nhrp_entry_get (index_t nei)
{
  return pool_elt_at_index (nhrp_pool, nei);
}

nhrp_entry_t *
nhrp_entry_find (u32 sw_if_index, const ip46_address_t * peer)
{
  nhrp_key_t nk = {
    .nk_peer = *peer,
    .nk_sw_if_index = sw_if_index,
  };
  uword *p;

  p = hash_get_mem (nhrp_db, &nk);

  if (NULL != p)
    return nhrp_entry_get (p[0]);

  return (NULL);
}

int
nhrp_entry_add (u32 sw_if_index,
		const ip46_address_t * peer,
		u32 nh_table_id, const ip46_address_t * nh)
{
  fib_protocol_t fproto;
  nhrp_entry_t *ne;
  u32 fib_index;
  index_t nei;

  fproto = (ip46_address_is_ip4 (nh) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);

  fib_index = fib_table_find (fproto, nh_table_id);

  if (~0 == fib_index)
    {
      return (VNET_API_ERROR_NO_SUCH_FIB);
    }

  ne = nhrp_entry_find (sw_if_index, peer);

  if (NULL == ne)
    {
      nhrp_key_t nk = {
	.nk_peer = *peer,
	.nk_sw_if_index = sw_if_index,
      };
      nhrp_entry_t *ne;

      pool_get_zero (nhrp_pool, ne);

      nei = ne - nhrp_pool;
      ne->ne_key = clib_mem_alloc (sizeof (*ne->ne_key));
      clib_memcpy (ne->ne_key, &nk, sizeof (*ne->ne_key));

      ip46_address_copy (&ne->ne_nh.fp_addr, nh);
      ne->ne_nh.fp_proto = fproto;
      ne->ne_nh.fp_len = (ne->ne_nh.fp_proto == FIB_PROTOCOL_IP4 ? 32 : 128);
      ne->ne_fib_index = fib_index;

      hash_set_mem (nhrp_db, ne->ne_key, nei);

      NHRP_NOTIFY (ne, nv_added);
    }
  else
    return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);

  return 0;
}

int
nhrp_entry_del (u32 sw_if_index, const ip46_address_t * peer)
{
  nhrp_entry_t *ne;

  ne = nhrp_entry_find (sw_if_index, peer);

  if (ne != NULL)
    {
      hash_unset_mem (nhrp_db, ne->ne_key);

      NHRP_NOTIFY (ne, nv_deleted);

      clib_mem_free (ne->ne_key);
      pool_put (nhrp_pool, ne);
    }
  else
    return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);

  return 0;
}

u8 *
format_nhrp_entry (u8 * s, va_list * args)
{
  index_t nei = va_arg (*args, index_t);
  vnet_main_t *vnm = vnet_get_main ();
  nhrp_entry_t *ne;

  ne = nhrp_entry_get (nei);

  s = format (s, "[%d] ", nei);
  s = format (s, "%U:", format_vnet_sw_if_index_name,
	      vnm, ne->ne_key->nk_sw_if_index);
  s = format (s, " %U", format_ip46_address,
	      &ne->ne_key->nk_peer, IP46_TYPE_ANY);
  s = format (s, " via [%d]:%U",
	      fib_table_get_table_id (ne->ne_fib_index, ne->ne_nh.fp_proto),
	      format_fib_prefix, &ne->ne_nh);

  return (s);
}

void
nhrp_walk (nhrp_walk_cb_t fn, void *ctx)
{
  index_t nei;

  /* *INDENT-OFF* */
  pool_foreach_index(nei, nhrp_pool,
  ({
    fn(nei, ctx);
  }));
  /* *INDENT-ON* */
}

void
nhrp_walk_itf (u32 sw_if_index, nhrp_walk_cb_t fn, void *ctx)
{
  index_t nei;

  /* *INDENT-OFF* */
  pool_foreach_index(nei, nhrp_pool,
  ({
    if (sw_if_index == nhrp_entry_get_sw_if_index(nhrp_entry_get(nei)))
      fn(nei, ctx);
  }));
  /* *INDENT-ON* */
}

void
nhrp_register (const nhrp_vft_t * vft)
{
  vec_add1 (nhrp_vfts, *vft);
}

static clib_error_t *
nhrp_init (vlib_main_t * vm)
{
  nhrp_db = hash_create_mem (0, sizeof (nhrp_key_t), sizeof (u32));

  return (NULL);
}

VLIB_INIT_FUNCTION (nhrp_init);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */