1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
5 #ifndef included_vector_array_mask_h
6 #define included_vector_array_mask_h
7 #include <vppinfra/clib.h>
9 /** \brief Mask array of 32-bit elemments
11 @param src source array of u32 elements
12 @param mask use to mask the values of source array
13 @param n_elts number of elements in the source array
14 @return masked values are return in source array
17 static_always_inline void
18 clib_array_mask_u32 (u32 *src, u32 mask, u32 n_elts)
21 #if defined(CLIB_HAVE_VEC512)
22 u32x16 mask16 = u32x16_splat (mask);
24 for (i = 0; i + 16 <= n_elts; i += 16)
25 *((u32x16u *) (src + i)) &= mask16;
29 u16 m = pow2_mask (n_elts);
30 u32x16_mask_store (u32x16_mask_load_zero (src + i, m) & mask16, src + i,
34 #elif defined(CLIB_HAVE_VEC256)
35 u32x8 mask8 = u32x8_splat (mask);
37 for (i = 0; i + 8 <= n_elts; i += 8)
38 *((u32x8u *) (src + i)) &= mask8;
41 #if defined(CLIB_HAVE_VEC256_MASK_LOAD_STORE)
44 u8 m = pow2_mask (n_elts);
45 u32x8_mask_store (u32x8_mask_load_zero (src, m) & mask8, src, m);
49 #elif defined(CLIB_HAVE_VEC128)
50 u32x4 mask4 = u32x4_splat (mask);
52 for (i = 0; i + 4 <= n_elts; i += 4)
53 *((u32x4u *) (src + i)) &= mask4;