2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (C) IBM Corporation 2016.
6 #ifndef _RTE_LPM_ALTIVEC_H_
7 #define _RTE_LPM_ALTIVEC_H_
9 #include <rte_branch_prediction.h>
10 #include <rte_byteorder.h>
11 #include <rte_common.h>
19 rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],
22 vector signed int i24;
25 uint64_t idx, pt, pt2;
28 const uint32_t mask = UINT8_MAX;
29 const vector signed int mask8 = (xmm_t){mask, mask, mask, mask};
32 * RTE_LPM_VALID_EXT_ENTRY_BITMASK for 2 LPM entries
33 * as one 64-bit value (0x0300000003000000).
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);
40 * RTE_LPM_LOOKUP_SUCCESS for 2 LPM entries
41 * as one 64-bit value (0x0100000001000000).
43 const uint64_t mask_v =
44 ((uint64_t)RTE_LPM_LOOKUP_SUCCESS |
45 (uint64_t)RTE_LPM_LOOKUP_SUCCESS << 32);
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});
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];
57 idx = (uint32_t) i24[1];
58 idx = idx < (1<<24) ? idx : (1<<24)-1;
59 ptbl = (const uint32_t *)&lpm->tbl24[idx];
62 idx = (uint32_t) i24[2];
63 idx = idx < (1<<24) ? idx : (1<<24)-1;
64 ptbl = (const uint32_t *)&lpm->tbl24[idx];
67 idx = (uint32_t) i24[3];
68 idx = idx < (1<<24) ? idx : (1<<24)-1;
69 ptbl = (const uint32_t *)&lpm->tbl24[idx];
72 /* get 4 indexes for tbl8[]. */
73 i8.x = vec_and(ip, mask8);
75 pt = (uint64_t)tbl[0] |
76 (uint64_t)tbl[1] << 32;
77 pt2 = (uint64_t)tbl[2] |
78 (uint64_t)tbl[3] << 32;
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;
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]];
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]];
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]];
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]];
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;
127 #endif /* _RTE_LPM_ALTIVEC_H_ */