DPDK  20.05.0
rte_lpm_altivec.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright (C) IBM Corporation 2016.
4  */
5 
6 #ifndef _RTE_LPM_ALTIVEC_H_
7 #define _RTE_LPM_ALTIVEC_H_
8 
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  vector signed int 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 vector signed int mask8 = (xmm_t){mask, mask, mask, 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 = vec_sr((xmm_t) ip,
49  (vector unsigned int){CHAR_BIT, CHAR_BIT, CHAR_BIT, CHAR_BIT});
50 
51  /* extract values from tbl24[] */
52  idx = (uint32_t)i24[0];
53  idx = idx < (1<<24) ? idx : (1<<24)-1;
54  ptbl = (const uint32_t *)&lpm->tbl24[idx];
55  tbl[0] = *ptbl;
56 
57  idx = (uint32_t) i24[1];
58  idx = idx < (1<<24) ? idx : (1<<24)-1;
59  ptbl = (const uint32_t *)&lpm->tbl24[idx];
60  tbl[1] = *ptbl;
61 
62  idx = (uint32_t) i24[2];
63  idx = idx < (1<<24) ? idx : (1<<24)-1;
64  ptbl = (const uint32_t *)&lpm->tbl24[idx];
65  tbl[2] = *ptbl;
66 
67  idx = (uint32_t) i24[3];
68  idx = idx < (1<<24) ? idx : (1<<24)-1;
69  ptbl = (const uint32_t *)&lpm->tbl24[idx];
70  tbl[3] = *ptbl;
71 
72  /* get 4 indexes for tbl8[]. */
73  i8.x = vec_and(ip, mask8);
74 
75  pt = (uint64_t)tbl[0] |
76  (uint64_t)tbl[1] << 32;
77  pt2 = (uint64_t)tbl[2] |
78  (uint64_t)tbl[3] << 32;
79 
80  /* search successfully finished for all 4 IP addresses. */
81  if (likely((pt & mask_xv) == mask_v) &&
82  likely((pt2 & mask_xv) == mask_v)) {
83  *(uint64_t *)hop = pt & RTE_LPM_MASKX4_RES;
84  *(uint64_t *)(hop + 2) = pt2 & RTE_LPM_MASKX4_RES;
85  return;
86  }
87 
88  if (unlikely((pt & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
89  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
90  i8.u32[0] = i8.u32[0] +
91  (uint8_t)tbl[0] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
92  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[0]];
93  tbl[0] = *ptbl;
94  }
95  if (unlikely((pt >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
96  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
97  i8.u32[1] = i8.u32[1] +
98  (uint8_t)tbl[1] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
99  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[1]];
100  tbl[1] = *ptbl;
101  }
102  if (unlikely((pt2 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
103  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
104  i8.u32[2] = i8.u32[2] +
105  (uint8_t)tbl[2] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
106  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[2]];
107  tbl[2] = *ptbl;
108  }
109  if (unlikely((pt2 >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
110  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
111  i8.u32[3] = i8.u32[3] +
112  (uint8_t)tbl[3] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
113  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[3]];
114  tbl[3] = *ptbl;
115  }
116 
117  hop[0] = (tbl[0] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[0] & 0x00FFFFFF : defv;
118  hop[1] = (tbl[1] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[1] & 0x00FFFFFF : defv;
119  hop[2] = (tbl[2] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[2] & 0x00FFFFFF : defv;
120  hop[3] = (tbl[3] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[3] & 0x00FFFFFF : defv;
121 }
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* _RTE_LPM_ALTIVEC_H_ */
#define likely(x)
#define unlikely(x)
static void rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv)
#define RTE_LPM_LOOKUP_SUCCESS
Definition: rte_lpm.h:63