Damjan Marion | ef0bac7 | 2021-04-22 18:08:28 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2021 Cisco Systems, Inc. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4 | |
| 5 | #ifndef included_vector_funcs_h |
| 6 | #define included_vector_funcs_h |
Damjan Marion | ef0bac7 | 2021-04-22 18:08:28 +0200 | [diff] [blame^] | 7 | #include <vppinfra/clib.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 8 | |
Damjan Marion | ef0bac7 | 2021-04-22 18:08:28 +0200 | [diff] [blame^] | 9 | /** \brief Compare 64 16-bit elemments with provied value and return bitmap |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 10 | |
Damjan Marion | ef0bac7 | 2021-04-22 18:08:28 +0200 | [diff] [blame^] | 11 | @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 | |
| 16 | static_always_inline u64 |
| 17 | clib_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 Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | #endif |
Damjan Marion | ef0bac7 | 2021-04-22 18:08:28 +0200 | [diff] [blame^] | 47 | return mask; |
| 48 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | #endif |