27#define DIR24_8_TBL24_NUM_ENT (1 << 24)
28#define DIR24_8_TBL8_GRP_NUM_ENT 256U
29#define DIR24_8_EXT_ENT 1
30#define DIR24_8_TBL24_MASK 0xffffff00
32#define BITMAP_SLAB_BIT_SIZE_LOG2 6
33#define BITMAP_SLAB_BIT_SIZE (1 << BITMAP_SLAB_BIT_SIZE_LOG2)
34#define BITMAP_SLAB_BITMASK (BITMAP_SLAB_BIT_SIZE - 1)
37 uint32_t number_tbl8s;
45 __extension__ uint64_t tbl24[0] __cne_cache_aligned;
49get_tbl24_p(
struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz)
51 return (
void *)&((uint8_t *)dp->tbl24)[(ip & DIR24_8_TBL24_MASK) >> (8 - nh_sz)];
55bits_in_nh(uint8_t nh_sz)
57 return 8 * (1 << nh_sz);
61get_max_nh(uint8_t nh_sz)
63 return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1);
67get_tbl24_idx(uint32_t ip)
73get_tbl8_idx(uint32_t res, uint32_t ip)
75 return (res >> 1) * DIR24_8_TBL8_GRP_NUM_ENT + (uint8_t)ip;
79lookup_msk(uint8_t nh_sz)
81 return ((1ULL << ((1 << (nh_sz + 3)) - 1)) << 1) - 1;
85get_psd_idx(uint32_t val, uint8_t nh_sz)
87 return val & ((1 << (3 - nh_sz)) - 1);
91get_tbl_idx(uint32_t val, uint8_t nh_sz)
93 return val >> (3 - nh_sz);
97get_tbl24(
struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz)
99 return ((dp->tbl24[get_tbl_idx(get_tbl24_idx(ip), nh_sz)] >>
100 (get_psd_idx(get_tbl24_idx(ip), nh_sz) * bits_in_nh(nh_sz))) &
104static inline uint64_t
105get_tbl8(
struct dir24_8_tbl *dp, uint32_t res, uint32_t ip, uint8_t nh_sz)
107 return ((dp->tbl8[get_tbl_idx(get_tbl8_idx(res, ip), nh_sz)] >>
108 (get_psd_idx(get_tbl8_idx(res, ip), nh_sz) * bits_in_nh(nh_sz))) &
113is_entry_extended(uint64_t ent)
115 return (ent & DIR24_8_EXT_ENT) == DIR24_8_EXT_ENT;
118#define LOOKUP_FUNC(suffix, type, bulk_prefetch, nh_sz) \
119 static inline void dir24_8_lookup_bulk_##suffix(void *p, const uint32_t *ips, \
120 uint64_t *next_hops, const unsigned int n) \
122 struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; \
125 uint32_t prefetch_offset = CNE_MIN((unsigned int)bulk_prefetch, n); \
127 for (i = 0; i < prefetch_offset; i++) \
128 cne_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); \
129 for (i = 0; i < (n - prefetch_offset); i++) { \
130 cne_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], nh_sz)); \
131 tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \
132 if (unlikely(is_entry_extended(tmp))) \
134 ((type *)dp->tbl8)[(uint8_t)ips[i] + ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \
135 next_hops[i] = tmp >> 1; \
137 for (; i < n; i++) { \
138 tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \
139 if (unlikely(is_entry_extended(tmp))) \
141 ((type *)dp->tbl8)[(uint8_t)ips[i] + ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \
142 next_hops[i] = tmp >> 1; \
146LOOKUP_FUNC(1b, uint8_t, 5, 0)
147LOOKUP_FUNC(2b, uint16_t, 6, 1)
148LOOKUP_FUNC(4b, uint32_t, 15, 2)
149LOOKUP_FUNC(8b, uint64_t, 12, 3)
152dir24_8_lookup_bulk(struct dir24_8_tbl *dp, const uint32_t *ips, uint64_t *next_hops,
153 const
unsigned int n, uint8_t nh_sz)
157 uint32_t prefetch_offset =
CNE_MIN(15U, n);
159 for (i = 0; i < prefetch_offset; i++)
160 cne_prefetch0(get_tbl24_p(dp, ips[i], nh_sz));
161 for (i = 0; i < (n - prefetch_offset); i++) {
162 cne_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], nh_sz));
163 tmp = get_tbl24(dp, ips[i], nh_sz);
164 if (
unlikely(is_entry_extended(tmp)))
165 tmp = get_tbl8(dp, tmp, ips[i], nh_sz);
167 next_hops[i] = tmp >> 1;
170 tmp = get_tbl24(dp, ips[i], nh_sz);
171 if (
unlikely(is_entry_extended(tmp)))
172 tmp = get_tbl8(dp, tmp, ips[i], nh_sz);
174 next_hops[i] = tmp >> 1;
179dir24_8_lookup_bulk_0(
void *p,
const uint32_t *ips, uint64_t *next_hops,
const unsigned int n)
181 struct dir24_8_tbl *dp = (
struct dir24_8_tbl *)p;
183 dir24_8_lookup_bulk(dp, ips, next_hops, n, 0);
187dir24_8_lookup_bulk_1(
void *p,
const uint32_t *ips, uint64_t *next_hops,
const unsigned int n)
189 struct dir24_8_tbl *dp = (
struct dir24_8_tbl *)p;
191 dir24_8_lookup_bulk(dp, ips, next_hops, n, 1);
195dir24_8_lookup_bulk_2(
void *p,
const uint32_t *ips, uint64_t *next_hops,
const unsigned int n)
197 struct dir24_8_tbl *dp = (
struct dir24_8_tbl *)p;
199 dir24_8_lookup_bulk(dp, ips, next_hops, n, 2);
203dir24_8_lookup_bulk_3(
void *p,
const uint32_t *ips, uint64_t *next_hops,
const unsigned int n)
205 struct dir24_8_tbl *dp = (
struct dir24_8_tbl *)p;
207 dir24_8_lookup_bulk(dp, ips, next_hops, n, 3);
211dir24_8_lookup_bulk_uni(
void *p,
const uint32_t *ips, uint64_t *next_hops,
const unsigned int n)
213 struct dir24_8_tbl *dp = (
struct dir24_8_tbl *)p;
216 uint32_t prefetch_offset =
CNE_MIN(15U, n);
217 uint8_t nh_sz = dp->nh_sz;
219 for (i = 0; i < prefetch_offset; i++)
220 cne_prefetch0(get_tbl24_p(dp, ips[i], nh_sz));
221 for (i = 0; i < (n - prefetch_offset); i++) {
222 cne_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], nh_sz));
223 tmp = get_tbl24(dp, ips[i], nh_sz);
224 if (
unlikely(is_entry_extended(tmp)))
225 tmp = get_tbl8(dp, tmp, ips[i], nh_sz);
227 next_hops[i] = tmp >> 1;
230 tmp = get_tbl24(dp, ips[i], nh_sz);
231 if (
unlikely(is_entry_extended(tmp)))
232 tmp = get_tbl8(dp, tmp, ips[i], nh_sz);
234 next_hops[i] = tmp >> 1;
240void dir24_8_free(
void *p);
244int dir24_8_modify(
struct cne_fib *fib, uint32_t ip, uint8_t depth, uint64_t next_hop,
int op);
void(*) cne_fib_lookup_fn_t(void *fib, const uint32_t *ips, uint64_t *next_hops, const unsigned int n)