blob: c867066291004e114d7fa8b1bc22765b37da63fe [file] [log] [blame]
Damjan Marionef0bac72021-04-22 18:08:28 +02001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004
5#ifndef included_vector_funcs_h
6#define included_vector_funcs_h
Damjan Marionef0bac72021-04-22 18:08:28 +02007#include <vppinfra/clib.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -07008
Damjan Marionef0bac72021-04-22 18:08:28 +02009/** \brief Compare 64 16-bit elemments with provied value and return bitmap
Ed Warnickecb9cada2015-12-08 15:45:58 -070010
Damjan Marionef0bac72021-04-22 18:08:28 +020011 @param v value to compare elements with
12 @param a array of 64 u16 elements
13 @return u64 bitmap where each bit represents result of comparison
14*/
15
16static_always_inline u64
17clib_compare_u16_x64 (u16 v, u16 *a)
18{
19 u64 mask = 0;
20#if defined(CLIB_HAVE_VEC512) && !defined(__aarch64__)
21 u16x32 v32 = u16x32_splat (v);
22 u16x32u *av = (u16x32u *) a;
23 mask = ((u64) u16x32_is_equal_mask (av[0], v32) |
24 (u64) u16x32_is_equal_mask (av[1], v32) << 32);
25#elif defined(CLIB_HAVE_VEC256)
26 u16x16 v16 = u16x16_splat (v);
27 u16x16u *av = (u16x16u *) a;
28 i8x32 x;
29
30 x = i16x16_pack (v16 == av[0], v16 == av[1]);
31 mask = i8x32_msb_mask ((i8x32) u64x4_permute (x, 0, 2, 1, 3));
32 x = i16x16_pack (v16 == av[2], v16 == av[3]);
33 mask |= (u64) i8x32_msb_mask ((i8x32) u64x4_permute (x, 0, 2, 1, 3)) << 32;
34#elif defined(CLIB_HAVE_VEC128) && defined(CLIB_HAVE_VEC128_MSB_MASK)
35 u16x8 idx8 = u16x8_splat (v);
36 u16x8u *av = (u16x8u *) a;
37 mask =
38 ((u64) i8x16_msb_mask (i16x8_pack (idx8 == av[0], idx8 == av[1])) |
39 (u64) i8x16_msb_mask (i16x8_pack (idx8 == av[2], idx8 == av[3])) << 16 |
40 (u64) i8x16_msb_mask (i16x8_pack (idx8 == av[4], idx8 == av[5])) << 32 |
41 (u64) i8x16_msb_mask (i16x8_pack (idx8 == av[6], idx8 == av[7])) << 48);
42#else
43 for (int i = 0; i < 64; i++)
44 if (a[i] == v)
45 mask |= 1ULL << i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#endif
Damjan Marionef0bac72021-04-22 18:08:28 +020047 return mask;
48}
Ed Warnickecb9cada2015-12-08 15:45:58 -070049
Ed Warnickecb9cada2015-12-08 15:45:58 -070050#endif