DPDK  20.05.0
rte_lru_arm64.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4 
5 #ifndef __RTE_LRU_ARM64_H__
6 #define __RTE_LRU_ARM64_H__
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <stdint.h>
13 #include <rte_vect.h>
14 
15 #ifndef RTE_TABLE_HASH_LRU_STRATEGY
16 #ifdef RTE_MACHINE_CPUFLAG_NEON
17 #define RTE_TABLE_HASH_LRU_STRATEGY 3
18 #else /* if no NEON, use simple scalar version */
19 #define RTE_TABLE_HASH_LRU_STRATEGY 1
20 #endif
21 #endif
22 
23 #if RTE_TABLE_HASH_LRU_STRATEGY == 3
24 
25 #define lru_init(bucket) \
26  { bucket->lru_list = ~0LLU; }
27 
28 static inline int
29 f_lru_pos(uint64_t lru_list)
30 {
31  /* Compare the vector to zero vector */
32  uint16x4_t lru_vec = vld1_u16((uint16_t *)&lru_list);
33  uint16x4_t min_vec = vmov_n_u16(vminv_u16(lru_vec));
34  uint64_t mask = vget_lane_u64(vreinterpret_u64_u16(
35  vceq_u16(min_vec, lru_vec)), 0);
36  return __builtin_clzl(mask) >> 4;
37 }
38 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
39 
40 #define lru_update(bucket, mru_val) \
41 do { \
42  const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
43  0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
44  const uint64_t decs[] = {0x1000100010001LLU, 0}; \
45  uint64x1_t lru = vdup_n_u64(bucket->lru_list); \
46  uint64x1_t vdec = vdup_n_u64(decs[mru_val>>2]); \
47  bucket->lru_list = vget_lane_u64(vreinterpret_u64_u16( \
48  vsub_u16(vreinterpret_u16_u64(lru), \
49  vreinterpret_u16_u64(vdec))), \
50  0); \
51  bucket->lru_list |= orvals[mru_val]; \
52 } while (0)
53 
54 #endif
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif