FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
array_mask.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: Apache-2.0
2
* Copyright(c) 2021 Cisco Systems, Inc.
3
*/
4
5
#ifndef included_vector_array_mask_h
6
#define included_vector_array_mask_h
7
#include <
vppinfra/clib.h
>
8
9
/** \brief Mask array of 32-bit elemments
10
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
15
*/
16
17
static_always_inline
void
18
clib_array_mask_u32
(
u32
*
src
,
u32
mask
,
u32
n_elts)
19
{
20
u32
i
;
21
#if defined(CLIB_HAVE_VEC512)
22
u32x16 mask16 = u32x16_splat (
mask
);
23
24
for
(
i
= 0;
i
+ 16 <= n_elts;
i
+= 16)
25
*((u32x16u *) (
src
+
i
)) &= mask16;
26
n_elts -=
i
;
27
if
(n_elts)
28
{
29
u16
m =
pow2_mask
(n_elts);
30
u32x16_mask_store (u32x16_mask_load_zero (
src
+
i
, m) & mask16,
src
+
i
,
31
m);
32
}
33
return
;
34
#elif defined(CLIB_HAVE_VEC256)
35
u32x8 mask8 = u32x8_splat (
mask
);
36
37
for
(
i
= 0;
i
+ 8 <= n_elts;
i
+= 8)
38
*((u32x8u *) (
src
+
i
)) &= mask8;
39
n_elts -=
i
;
40
src
+=
i
;
41
#if defined(CLIB_HAVE_VEC256_MASK_LOAD_STORE)
42
if
(n_elts)
43
{
44
u8
m =
pow2_mask
(n_elts);
45
u32x8_mask_store (u32x8_mask_load_zero (
src
, m) & mask8,
src
, m);
46
}
47
return
;
48
#endif
49
#elif defined(CLIB_HAVE_VEC128)
50
u32x4
mask4 = u32x4_splat (
mask
);
51
52
for
(
i
= 0;
i
+ 4 <= n_elts;
i
+= 4)
53
*((u32x4u *) (
src
+
i
)) &= mask4;
54
n_elts -=
i
;
55
src
+=
i
;
56
switch
(n_elts)
57
{
58
case
3:
59
src
[2] &=
mask
;
60
case
2:
61
src
[1] &=
mask
;
62
case
1:
63
src
[0] &=
mask
;
64
case
0:
65
default
:;
66
}
67
return
;
68
#endif
69
while
(n_elts > 0)
70
{
71
src
[0] &=
mask
;
72
src
++;
73
n_elts--;
74
}
75
}
76
77
#endif
pow2_mask
static uword pow2_mask(uword x)
Definition:
clib.h:252
clib.h
clib_array_mask_u32
static_always_inline void clib_array_mask_u32(u32 *src, u32 mask, u32 n_elts)
Mask array of 32-bit elemments.
Definition:
array_mask.h:18
u16
unsigned short u16
Definition:
types.h:57
static_always_inline
#define static_always_inline
Definition:
clib.h:112
mask
vl_api_pnat_mask_t mask
Definition:
pnat.api:45
src
vl_api_address_t src
Definition:
gre.api:54
u32
unsigned int u32
Definition:
types.h:88
u32x4
unsigned long long u32x4
Definition:
ixge.c:28
u8
unsigned char u8
Definition:
types.h:56
i
int i
Definition:
flowhash_template.h:376
src
vppinfra
vector
array_mask.h
Generated on Sat Jan 8 2022 10:37:21 for FD.io VPP by
1.8.17