test/cycles: restore default delay callback
[dpdk.git] / lib / librte_lpm / rte_lpm_neon.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015 Cavium, Inc.
3  * Copyright(c) 2010-2014 Intel Corporation.
4  */
5
6 #ifndef _RTE_LPM_NEON_H_
7 #define _RTE_LPM_NEON_H_
8
9 #include <rte_branch_prediction.h>
10 #include <rte_byteorder.h>
11 #include <rte_common.h>
12 #include <rte_vect.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 static inline void
19 rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],
20         uint32_t defv)
21 {
22         uint32x4_t i24;
23         rte_xmm_t i8;
24         uint32_t tbl[4];
25         uint64_t idx, pt, pt2;
26         const uint32_t *ptbl;
27
28         const uint32_t mask = UINT8_MAX;
29         const int32x4_t mask8 = vdupq_n_s32(mask);
30
31         /*
32          * RTE_LPM_VALID_EXT_ENTRY_BITMASK for 2 LPM entries
33          * as one 64-bit value (0x0300000003000000).
34          */
35         const uint64_t mask_xv =
36                 ((uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK |
37                 (uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK << 32);
38
39         /*
40          * RTE_LPM_LOOKUP_SUCCESS for 2 LPM entries
41          * as one 64-bit value (0x0100000001000000).
42          */
43         const uint64_t mask_v =
44                 ((uint64_t)RTE_LPM_LOOKUP_SUCCESS |
45                 (uint64_t)RTE_LPM_LOOKUP_SUCCESS << 32);
46
47         /* get 4 indexes for tbl24[]. */
48         i24 = vshrq_n_u32((uint32x4_t)ip, CHAR_BIT);
49
50         /* extract values from tbl24[] */
51         idx = vgetq_lane_u64((uint64x2_t)i24, 0);
52
53         ptbl = (const uint32_t *)&lpm->tbl24[(uint32_t)idx];
54         tbl[0] = *ptbl;
55         ptbl = (const uint32_t *)&lpm->tbl24[idx >> 32];
56         tbl[1] = *ptbl;
57
58         idx = vgetq_lane_u64((uint64x2_t)i24, 1);
59
60         ptbl = (const uint32_t *)&lpm->tbl24[(uint32_t)idx];
61         tbl[2] = *ptbl;
62         ptbl = (const uint32_t *)&lpm->tbl24[idx >> 32];
63         tbl[3] = *ptbl;
64
65         /* get 4 indexes for tbl8[]. */
66         i8.x = vandq_s32(ip, mask8);
67
68         pt = (uint64_t)tbl[0] |
69                 (uint64_t)tbl[1] << 32;
70         pt2 = (uint64_t)tbl[2] |
71                 (uint64_t)tbl[3] << 32;
72
73         /* search successfully finished for all 4 IP addresses. */
74         if (likely((pt & mask_xv) == mask_v) &&
75                         likely((pt2 & mask_xv) == mask_v)) {
76                 *(uint64_t *)hop = pt & RTE_LPM_MASKX4_RES;
77                 *(uint64_t *)(hop + 2) = pt2 & RTE_LPM_MASKX4_RES;
78                 return;
79         }
80
81         if (unlikely((pt & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
82                         RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
83                 i8.u32[0] = i8.u32[0] +
84                         (uint8_t)tbl[0] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
85                 ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[0]];
86                 tbl[0] = *ptbl;
87         }
88         if (unlikely((pt >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
89                         RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
90                 i8.u32[1] = i8.u32[1] +
91                         (uint8_t)tbl[1] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
92                 ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[1]];
93                 tbl[1] = *ptbl;
94         }
95         if (unlikely((pt2 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
96                         RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
97                 i8.u32[2] = i8.u32[2] +
98                         (uint8_t)tbl[2] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
99                 ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[2]];
100                 tbl[2] = *ptbl;
101         }
102         if (unlikely((pt2 >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
103                         RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
104                 i8.u32[3] = i8.u32[3] +
105                         (uint8_t)tbl[3] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
106                 ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[3]];
107                 tbl[3] = *ptbl;
108         }
109
110         hop[0] = (tbl[0] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[0] & 0x00FFFFFF : defv;
111         hop[1] = (tbl[1] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[1] & 0x00FFFFFF : defv;
112         hop[2] = (tbl[2] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[2] & 0x00FFFFFF : defv;
113         hop[3] = (tbl[3] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[3] & 0x00FFFFFF : defv;
114 }
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #endif /* _RTE_LPM_NEON_H_ */