DPDK  18.11.8
rte_lpm_mips.h
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_LPM_LOONGSON_H_
35 #define _RTE_LPM_LOONGSON_H_
36 
37 #include <rte_branch_prediction.h>
38 #include <rte_byteorder.h>
39 #include <rte_common.h>
40 #include <rte_vect.h>
41 #include <rte_lpm.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 static inline void
48 rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],
49  uint32_t defv)
50 
51 {
52  xmm_t i24;
53  rte_xmm_t i8;
54  uint32_t tbl[4];
55  uint64_t idx, pt, pt2;
56  const uint32_t *ptbl;
57 
58  const uint32_t mask = UINT8_MAX;
59  xmm_t mask8_tmp;
60  mask8_tmp.v4i32 = __msa_fill_w(mask);
61 
62  const xmm_t mask8 = mask8_tmp;
63 
64  /*
65  * RTE_LPM_VALID_EXT_ENTRY_BITMASK for 2 LPM entries
66  * as one 64-bit value (0x0300000003000000).
67  */
68  const uint64_t mask_xv =
69  ((uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK |
70  (uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK << 32);
71 
72  /*
73  * RTE_LPM_LOOKUP_SUCCESS for 2 LPM entries
74  * as one 64-bit value (0x0100000001000000).
75  */
76  const uint64_t mask_v =
77  ((uint64_t)RTE_LPM_LOOKUP_SUCCESS |
78  (uint64_t)RTE_LPM_LOOKUP_SUCCESS << 32);
79 
80  /* get 4 indexes for tbl24[]. */
81  i24.v4i32 = __msa_srli_w(ip.v4i32, CHAR_BIT);
82 
83  /* extract values from tbl24[] */
84  idx = __msa_copy_u_d(i24.v2i64, 0);
85 
86  ptbl = (const uint32_t *)&lpm->tbl24[(uint32_t)idx];
87  tbl[0] = *ptbl;
88  ptbl = (const uint32_t *)&lpm->tbl24[idx >> 32];
89  tbl[1] = *ptbl;
90 
91  idx = __msa_copy_u_d(i24.v2i64, 1);
92 
93  ptbl = (const uint32_t *)&lpm->tbl24[(uint32_t)idx];
94  tbl[2] = *ptbl;
95  ptbl = (const uint32_t *)&lpm->tbl24[idx >> 32];
96  tbl[3] = *ptbl;
97 
98  /* get 4 indexes for tbl8[]. */
99  i8.x.v16u8 = __msa_and_v(ip.v16u8, mask8.v16u8);
100 
101  pt = (uint64_t)tbl[0] |
102  (uint64_t)tbl[1] << 32;
103  pt2 = (uint64_t)tbl[2] |
104  (uint64_t)tbl[3] << 32;
105 
106  /* search successfully finished for all 4 IP addresses. */
107  if (likely((pt & mask_xv) == mask_v) &&
108  likely((pt2 & mask_xv) == mask_v)) {
109  *(uint64_t *)hop = pt & RTE_LPM_MASKX4_RES;
110  *(uint64_t *)(hop + 2) = pt2 & RTE_LPM_MASKX4_RES;
111  return;
112  }
113 
114  if (unlikely((pt & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
115  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
116  i8.u32[0] = i8.u32[0] +
117  (uint8_t)tbl[0] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
118  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[0]];
119  tbl[0] = *ptbl;
120  }
121  if (unlikely((pt >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
122  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
123  i8.u32[1] = i8.u32[1] +
124  (uint8_t)tbl[1] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
125  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[1]];
126  tbl[1] = *ptbl;
127  }
128  if (unlikely((pt2 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
129  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
130  i8.u32[2] = i8.u32[2] +
131  (uint8_t)tbl[2] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
132  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[2]];
133  tbl[2] = *ptbl;
134  }
135  if (unlikely((pt2 >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
136  RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
137  i8.u32[3] = i8.u32[3] +
138  (uint8_t)tbl[3] * RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
139  ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[3]];
140  tbl[3] = *ptbl;
141  }
142 
143  hop[0] = (tbl[0] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[0] & 0x00FFFFFF : defv;
144  hop[1] = (tbl[1] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[1] & 0x00FFFFFF : defv;
145  hop[2] = (tbl[2] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[2] & 0x00FFFFFF : defv;
146  hop[3] = (tbl[3] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[3] & 0x00FFFFFF : defv;
147 }
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* _RTE_LPM_LOONGSON_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:64